# Copyright INRIA
LLD = ld -bh:4 -T512 -H512 -o /tmp/scilex-1 -bnodelcsect /lib/crt0.o
LLD1 = ld -bh:4 -T512 -H512 -o $@ -bnodelcsect -bE:bin/scilex.exp /lib/crt0.o
LLDLF = -lxlf90 -lxlopt -lxlf -lxlomp_ser -lm -lc


bin/scilex: scilex-lib
	@x=1;if [ -f $@ ] ; then \
		x=`find $(MAINSCI) $(DEFAULTS) $(LIBR) \( -name '*.a' -o -name '*.o' \) \
		-newer $@ -print | wc -l `; \
	fi;\
	if [ $$x -ne 0 ] ; then \
		echo "linking";\
		$(RM) $@ ;\
		$(RM) /tmp/scilex-1;\
		$(LLD) $(MAINSCI) $(DEFAULTS) $(LIBR) $(LD_LDFLAGS) $(TCLTK_LIBS) \
			$(XLIBS) $(TERMCAPLIB) $(LLDLF);\
		(echo "#!$(SCIDIR)/bin/scilex"; /usr/bin/nm -B -Bgp /tmp/scilex-1\
			| sed -n -e '/.* T \./s///p' -e '/.* [DB] /s///p' \
			| sort -u) > bin/scilex.exp ;\
		$(RM) /tmp/scilex-1 ;\
		$(LLD1) $(MAINSCI) $(DEFAULTS) $(LIBR) $(LD_LDFLAGS) $(TCLTK_LIBS) \
			$(XLIBS) $(TERMCAPLIB) $(LLDLF);\
	else \
		echo bin/scilex is up to date ;\
	fi


