diff -r ebefcbcb126f -r 895f6304179d rules.mk --- a/rules.mk Wed Oct 06 18:24:41 2004 +0200 +++ b/rules.mk Sat Oct 09 13:01:37 2004 +0200 @@ -2,18 +2,31 @@ ## Some make rules ## -###################################### +ifdef MODULE +ifeq ($(PRELOAD_MODULES),1) +MODULE_TARGETS := $(MODULE).a $(MODULE).lc +else +MODULE_TARGETS := $(MODULE).so $(MODULE).lc +endif +TARGETS := $(TARGETS) $(MODULE_TARGETS) +endif -ifdef MODULE -ifneq ($(STATIC_MODULES),1) -TARGETS := $(TARGETS) $(MODULE).so -else -TARGETS := $(TARGETS) $(MODULE).a -endif +ifdef LUA_SOURCES +LUA_COMPILED := $(subst .lua,.lc, $(LUA_SOURCES)) +TARGETS := $(TARGETS) $(LUA_COMPILED) endif -ifdef SUBDIRS +# Main targets +###################################### + +.PHONY: subdirs +.PHONY: subdirs-clean +.PHONY: subdirs-realclean +.PHONY: subdirs-depend +.PHONY: subdirs-install +.PHONY: _install +.PHONY: _depend all: subdirs $(TARGETS) @@ -23,91 +36,136 @@ depend: subdirs-depend _depend -else - -all: $(TARGETS) - -clean: _clean - -realclean: _clean _realclean - -depend: _depend - -endif - -ifdef INSTALL_SUBDIRS - install: subdirs-install _install -else -install: _install - -endif - +# Exports ###################################### -OBJS=$(subst .c,.o,$(SOURCES)) - ifdef MAKE_EXPORTS TO_CLEAN := $(TO_CLEAN) exports.c -OBJS := $(OBJS) exports.o +EXPORTS_C = exports.c exports.c: $(SOURCES) - $(PERL) $(TOPDIR)/mkexports.pl $(MAKE_EXPORTS) exports.c $(SOURCES) + $(MKEXPORTS) -module $(MAKE_EXPORTS) -o exports.c $(SOURCES) + +else # !MAKE_EXPORTS + +EXPORTS_C = -endif +endif # !MAKE_EXPORTS + + +# Compilation and linking +###################################### + +OBJS=$(subst .c,.o,$(SOURCES) $(EXPORTS_C)) ifdef MODULE -ifneq ($(STATIC_MODULES),1) +ifneq ($(PRELOAD_MODULES),1) + +CC_PICFLAGS=-fPIC -DPIC +LD_SHAREDFLAGS=-shared + +%.o: %.c + $(CC) $(CC_PICFLAGS) $(CFLAGS) -c $< -o $@ $(MODULE).so: $(OBJS) $(EXT_OBJS) - $(CC) $(CFLAGS) $(LDFLAGS) $(MODULE_LDFLAGS) $(OBJS) $(EXT_OBJS) -o $@ + $(CC) $(LD_SHAREDFLAGS) $(LDFLAGS) $(OBJS) $(EXT_OBJS) -o $@ -module_install: + +module_install: module_stub_install $(INSTALLDIR) $(MODULEDIR) $(INSTALL) -m $(BIN_MODE) $(MODULE).so $(MODULEDIR) - # $(STRIP) $(MODULEDIR)/$(MODULE).so + +else # PRELOAD_MODULES -else +PICOPT=-fPIC -DPIC +LINKOPT=-shared -$(MODULE).a: $(OBJS) +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +$(MODULE).a: $(OBJS) $(EXT_OBJS) $(AR) $(ARFLAGS) $@ $+ $(RANLIB) $@ -module_install: +module_install: module_stub_install -endif +endif # PRELOAD_MODULES -.c.o: - $(CC) $(CFLAGS) $(MODULE_CFLAGS) -c $< -o $@ +module_stub_install: + $(INSTALLDIR) $(LCDIR) + $(INSTALL) -m $(DATA_MODE) $(MODULE).lc $(LCDIR) +ifndef MODULE_STUB + +$(MODULE).lc: + echo "ioncore.load_module('$(MODULE)')" | $(LUAC) -o $@ - else -.c.o: +LUA_SOURCES += $(MODULE_STUB) + +endif #MODULE_STUB + +else # !MODULE + + +%.o: %.c $(CC) $(CFLAGS) -c $< -o $@ + +endif# !MODULE + + +# Clean rules +###################################### + +_clean: + $(RM) -f $(TO_CLEAN) core $(DEPEND_FILE) $(OBJS) + +_realclean: + $(RM) -f $(TO_REALCLEAN) $(TARGETS) + +# Lua rules +###################################### + +%.lc: %.lua + $(LUAC) -o $@ $< + +lc_install: + $(INSTALLDIR) $(LCDIR) + for i in $(LUA_COMPILED); do \ + $(INSTALL) -m $(DATA_MODE) $$i $(LCDIR); \ + done + +etc_install: + $(INSTALLDIR) $(ETCDIR) + for i in $(ETC); do \ + $(INSTALL) -m $(DATA_MODE) $$i $(ETCDIR); \ + done + +# Dependencies +###################################### + +ifdef SOURCES + +_depend: $(DEPEND_DEPENDS) + $(MAKE_DEPEND) + +ifeq ($(DEPEND_FILE),$(wildcard $(DEPEND_FILE))) +include $(DEPEND_FILE) +endif + endif -_clean: - rm -f core $(DEPEND_FILE) $(OBJS) $(TO_CLEAN) - -_realclean: - rm -f $(TARGETS) $(TO_REALCLEAN) - +# Subdirectories +###################################### -ifdef SOURCES -_depend: - $(MAKE_DEPEND) $(SOURCES) -else -_depend: - -endif - -###################################### +ifdef SUBDIRS subdirs: set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done @@ -124,8 +182,13 @@ subdirs-install: set -e; for i in $(INSTALL_SUBDIRS); do $(MAKE) -C $$i install; done +endif + +# Localisation ###################################### -ifeq ($(DEPEND_FILE),$(wildcard $(DEPEND_FILE))) -include $(DEPEND_FILE) -endif +TO_CLEAN += potfiles_c potfiles_lua + +_potfiles: + echo "$(SOURCES)"|tr ' ' '\n' > potfiles_c + echo "$(LUA_SOURCES) $(ETC)"|tr ' ' '\n' > potfiles_lua