# Makefile
# ex.  > make PLATFORM_BITS=64 INST_PREFIX=/usr
#

NAME = azoniguruma
DATE_TAG:=`date +%Y%m%d`

INST_PREFIX = /usr/local

CCOPT = -I.   -I/usr/local/include
LDOPT =  -L$(INST_PREFIX)/lib

CFLAGS = -Wall -O2 $(CCOPT)

AZ_CCOPT = -Wall -O2 $(CCOPT) -I$(INST_PREFIX)/include
AZPC_LIBS = onig
AZ_LIB_EXT = $(INST_PREFIX)/lib/azprolog/ext
AZ_LIB_OBJ = $(INST_PREFIX)/lib/azprolog/obj

LDLIBS=$(LDOPT) -lonig
CC=gcc

EXEC_TARGETS = oniguruma.so lib_oniguruma.a oniguruma azoniguruma check

default: oniguruma.so lib_oniguruma.a

oniguruma: oniguruma_userfile.c
	$(CC) $(CFLAGS) -c $<
	gcc -o $@ oniguruma_userfile.o $(AZ_LIB_OBJ)/azpi.o $(AZ_LIB_OBJ)/curses.o -L$(AZ_LIB_EXT) -lazp -l_oniguruma -lonig -lcurses -lm -ldl

azoniguruma: oniguruma.c
	azpc -p $< /i /e $@ /curses  /ccopt "$(AZ_CCOPT)" /lib $(AZPC_LIBS)
	rm -f *.o

oniguruma.so: oniguruma.c
	$(CC) $(CFLAGS) -fPIC -o oniguruma.o -c $<
	$(CC) -shared -dynamiclib -o $@ oniguruma.o $(LDLIBS)
	rm -f oniguruma.o

lib_oniguruma.a: oniguruma.c
	$(CC) $(CFLAGS) -o oniguruma.o -c $<
	ar rv $@ oniguruma.o
	ranlib $@

oniguruma.o: oniguruma.c

clean:
	rm -f *~ .*~ *.o mkaz userfile.c $(EXEC_TARGETS)

tar:
	cd ..; tar -cvf $(NAME)-$(DATE_TAG).tar $(NAME)
	gzip ../$(NAME)-$(DATE_TAG).tar
