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

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

INST_PREFIX = /usr/local

CCOPT = -I.  -I$(INST_PREFIX)/include
LDOPT =  -L$(INST_PREFIX)/lib -lazcurses
CFLAGS = -Wall -O2 $(CCOPT)

AZ_LIB_EXT = $(INST_PREFIX)/lib/azprolog/ext
AZ_LIB_OBJ = $(INST_PREFIX)/lib/azprolog/obj

AZPCFLAGS = /message /s_verbos /cc $(CC) /ccopt "$(CCOPT)" /link_opt "$(LDOPT)"

ifeq ($(AZ_DEBUG_MODE),true)
AZPC = azpc_d
else
AZPC = azpc
endif

CC=gcc

EXEC_TARGETS = azedit.so lib_azedit.a azedit

export LD_LIBRARY_PATH=$(INST_PREFIX)/lib


default: azedit.so lib_azedit.a

azedit: azedit.c
	$(AZPC) -p $< /i /e $@ /curses  /ccopt "$(CFLAGS)" /link_opt "$(LDOPT)"
	rm -f *.o

azedit.so: azedit.c
	$(CC) $(CFLAGS) -fPIC -o azedit.o -c $<
	$(CC) -shared -dynamiclib -o $@ azedit.o $(LDOPT)
	chmod 644 $@

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

azedit.c: azedit.pl
	AZProlog=$(INST_PREFIX) $(INST_PREFIX)/bin/$(AZPC) -p $< /ncc $(AZPCFLAGS)


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

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

dist:
	git archive --format=tar --prefix=$(NAME)/ HEAD | gzip > ../$(NAME)-$(DATE_TAG).tar.gz
