@SET_MAKE@

CC=@CC@
CPP=@CPP@

AR=@AR@

MODULES=@subdirs@
MODULE_SEGMENTS=@MODULE_SEGMENTS@
MODULE_LINKOPTS=@MODULE_LINKOPTS@

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

all: modules

modules:
	for a in $(MODULES) ; do echo making $$a ; ( cd $$a ; $(MAKE) $(MAKE_FLAGS) MODNAME=$$a ) || exit $$? ; done
	$(MAKE) linker_options modlist.h modlist_headers.h

modlist.h: $(MODULE_SEGMENTS)
	( for a in $(MODULES) ; do cat $$a/modlist_segment ; done ; ) >modlist.h

modlist_headers.h: $(MODULE_SEGMENTS)
	( for a in $(MODULES) ; do cat $$a/modlist_segment; done ) | sed -e 's/^.*{.*,\(.*\),\(.*\).*}.*$$/void \1(void),\2(void);/' >modlist_headers.h

linker_options: $(MODULE_LINKOPTS)
	( for a in $(MODULES) ; do cat $$a/linker_options; done ; ) >linker_options

depend:
	for a in $(MODULES) ; do ( cd $$a ; ${MAKE} $(MAKE_FLAGS) MODNAME=$$a depend ) ; done

install:
	for a in $(MODULES) ; do ( cd $$a ; ${MAKE} $(MAKE_FLAGS) MODNAME=$$a install ) ; done

clean:
	for a in $(MODULES) ; do ( cd $$a ; ${MAKE} $(MAKE_FLAGS) MODNAME=$$a clean ) ; done

verify:
	for a in $(MODULES) ; do ( cd $$a ; echo verifying $$a ; ${MAKE} $(MAKE_FLAGS) MODNAME=$$a verify ) || exit $$? ; done

verbose_verify:
	for a in $(MODULES) ; do ( cd $$a ; ${MAKE} $(MAKE_FLAGS) MODNAME=$$a verbose_verify ) || exit $$? ; done

@dependencies@
