include ../settings.mk
NATIVE_libreadline_LIB = $(shell ../findLib "libreadline.so")
NATIVE_libhistory_LIB = $(shell ../findLib "libhistory.so")
GENERATED_WRAPPERS = libreadline.5D libhistory.5D

all: $(GENERATED_WRAPPERS)

# FIXME make override work

%.5D: %.sign
	$(FIND_5D_EXPORTS) $< >$@.new && mv $@.new $@
libreadline.5D: libreadline.sign
libreadline.sign: libreadline.symbols prototypes libreadline.override
	../generateSignatures $< $(NATIVE_libreadline_LIB) "" >$@.new && mv $@.new $@
libreadline.symbols: $(NATIVE_libreadline_LIB) libreadline.obsoletes
	$(EXTRACT_GNU_SYMBOLS) $< |sort |uniq > libreadline.symbols.new && cat libreadline.obsoletes >>libreadline.symbols.new && sort libreadline.symbols.new |uniq -u >libreadline.symbols.new2 && mv libreadline.symbols.new2 libreadline.symbols
libhistory.5D: libhistory.sign
libhistory.sign: libhistory.symbols prototypes libhistory.override
	../generateSignatures $< $(NATIVE_libhistory_LIB) "" >$@.new && mv $@.new $@
libhistory.symbols: $(NATIVE_libhistory_LIB) libhistory.obsoletes
	$(EXTRACT_GNU_SYMBOLS) $< |sort |uniq > libhistory.symbols.new && cat libhistory.obsoletes >>libhistory.symbols.new && sort libhistory.symbols.new |uniq -u >libhistory.symbols.new2 && mv libhistory.symbols.new2 libhistory.symbols
prototypes a.out: a.c a.inc
	$(CC) -aux-info prototypes.new -o a.out a.c -lcrypto && mv prototypes.new prototypes
a.inc: findConstants findConstantsB
	./findConstants >a.inc.new && mv a.inc.new a.inc
clean:
	rm -f libreadline.5D libreadline.sign libreadline.symbols
	rm -f libhistory.5D libhistory.sign libhistory.symbols
	rm -f a.out prototypes prototypes.new a.inc a.inc.new
	rm -f $(GENERATED_WRAPPERS)

distclean: clean

install:
	install -m 755 -d $(DESTDIR)/usr/share/5D/Readline6
	install -m 644 $(GENERATED_WRAPPERS) $(DESTDIR)/usr/share/5D/Readline6/
	install -m 644 init.5D $(DESTDIR)/usr/share/5D/Readline6/init.5D