#
# $Id: dynamic_module_makefile.in,v 1.27 1997/12/01 20:21:33 grubba Exp $
#


CC=@CC@
CPP=@CPP@
AR=@AR@

PREFLAGS=-I. -I$(SRCDIR) -I$(SRCDIR)/../.. -I../.. -I. $(MODULE_CPPFLAGS) $(DEFINES) 
CFLAGS=$(PREFLAGS) $(OTHERFLAGS) @CCSHARED@ $(MODULE_CFLAGS)

MAKE_FLAGS = "prefix=$(prefix)" "exec_prefix=$(exec_prefix)" "CC=$(CC)" "OTHERFLAGS=$(OTHERFLAGS) @CCSHARED@" "TMP_BINDIR=$(TMP_BINDIR)" "DEFINES=$(DEFINES)" "TMP_LIBDIR=$(TMP_LIBDIR)" "RUNPIKE=$(RUNPIKE)" "INSTALL=$(INSTALL)" "AR=$(AR)" $(MODULE_MAKE_FLAGS)

all: subdirs dummy

subdirs:
	for a in '' $(MODULE_SUBDIRS) ; do if test ! -z "$$a"; then echo making $$a ; ( cd $$a && $(MAKE) $(MAKE_FLAGS) ) || exit $$? ; else :; fi ; done

dummy:	$(DUMMY) linker_options modlist_headers modlist_segment module.so
	tmp="$(INSTALL_NAME)" ; \
	if test x$$tmp = x ; then tmp="$(MODNAME)"; else :; fi ;\
	$(INSTALL) module.so $(TMP_LIBDIR)/modules/$$tmp.so ;\
	if [ -f $(SRCDIR)/module.pmod.in ]; then sed -e "s/@module@/\"$$tmp\"/" <$(SRCDIR)/module.pmod.in >$(TMP_LIBDIR)/modules/$$tmp.pmod ; else :; fi

linker_options: Makefile
	echo "$(LINKER_OPTIONS)" >linker_options

modlist_headers: Makefile
	echo "" >modlist_headers

modlist_segment: Makefile
	echo "" >modlist_segment

Makefile: ../dynamic_module_makefile $(SRCDIR)/Makefile.in $(SRCDIR)/dependencies
	CONFIG_FILES=Makefile CONFIG_HEADERS="" ./config.status
	@echo "Run make again"
	@exit 1

module.so: $(OBJS)  $(MODULE_ARCHIVES)
	$(TMP_BINDIR)/smartlink "@LDSHARED@" -o module.@SO@ $(OBJS) $(MODULE_ARCHIVES) $(MODULE_LDFLAGS) -lc
	if test @SO@ != so ; then mv module.@SO@ module.so ; else :; fi

clean:
	-rm -f *.o *.a *.so module.so
	for a in '' $(MODULE_SUBDIRS) ; do if test ! -z "$$a"; then echo cleaning $$a ; ( cd $$a ; $(MAKE) $(MAKE_FLAGS) clean ) ; else :; fi ; done


depend:
	gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(TMP_BINDIR)/fixdepends.sh $(SRCDIR)
	for a in '' $(MODULE_SUBDIRS) ; do if test ! -z "$$a"; then echo making depend in $$a ; ( cd $$a ; $(MAKE) $(MAKE_FLAGS) depend ) ; else :; fi ; done

#verify / debug
module_testsuite: $(SRCDIR)/testsuite.in
	$(TMP_BINDIR)/mktestsuite $(SRCDIR)/testsuite.in >module_testsuite -DSRCDIR=$(SRCDIR) 

verify: module_testsuite  $(MODULE_TESTS)
	$(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite

verbose_verify: module_testsuite  $(MODULE_TESTS)
	$(RUNPIKE) $(TMP_BINDIR)/test_pike.pike module_testsuite --verbose

gdb_verify: module_testsuite
	@echo >.gdbinit handle SIGUSR1 nostop noprint pass
	@echo >>.gdbinit run -DNOT_INSTALLED -m ../../lib/master.pike $(PIKEOPTS) $(SRCDIR)/../../../bin/test_pike.pike module_testsuite -v -v -f
	gdb ../../pike
	@rm .gdbinit


install: $(MODULE_INSTALL)
	$(INSTALL) module.so @prefix@/lib/pike/modules/$(MODNAME).so

