#
# $Id: static_module_makefile.in,v 1.22 1997/12/01 20:21:07 grubba Exp $
#


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

PREFLAGS=-I. -I$(SRCDIR) -I$(SRCDIR)/../.. -I../.. -I. -Dpike_module_init=pike_module_$(MODNAME)_init -Dpike_module_exit=pike_module_$(MODNAME)_exit $(MODULE_CPPFLAGS) $(DEFINES) 
CFLAGS=$(PREFLAGS) $(OTHERFLAGS) $(MODULE_CFLAGS)

MAKE_FLAGS = "prefix=$(prefix)" "exec_prefix=$(exec_prefix)" "CC=$(CC)" "OTHERFLAGS=$(OTHERFLAGS)" "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:	linker_options modlist_headers modlist_segment module.pmod module.a
	tmp="$(INSTALL_NAME)" ;\
	if test x$$tmp = x ; then tmp="$(MODNAME)"; else :; fi ;\
	$(INSTALL) module.pmod $(TMP_LIBDIR)/modules/$$tmp.pmod

linker_options: Makefile $(MODULE_ARCHIVES)
	echo >linker_options modules/$(MODNAME)/module.a $(MODULE_LDFLAGS)
	for a in '' $(MODULE_ARCHIVES) ; do if test ! -z "$$a"; then echo modules/$(MODNAME)/$$a >>linker_options ; else :; fi ; done

modlist_headers: Makefile
	echo >modlist_headers "void pike_module_$(MODNAME)_init(void), pike_module_$(MODNAME)_exit(void);"

modlist_segment: Makefile
	echo >modlist_segment " ,{ \"$(MODNAME)\", pike_module_$(MODNAME)_init, pike_module_$(MODNAME)_exit } "

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

module.pmod: Makefile
	if [ -f $(SRCDIR)/module.pmod.in ]; then \
	   sed -e "s/@module@/_static_modules.$(MODNAME)/" <$(SRCDIR)/module.pmod.in >module.pmod ;\
	else \
	  echo >module.pmod "inherit _static_modules.$(MODNAME);" ;\
	fi

module.a: $(OBJS)
	-rm -f module.a
	$(AR) cq module.a $(OBJS)
	-@RANLIB@ module.a
	if test -f linker_options ; then touch linker_options ; else :; fi

clean:
	-rm -f *.o *.a *.so module.so module.pmod
	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)

