6 ifeq ($(PRELOAD_MODULES),1)
7 MODULE_TARGETS := $(MODULE).a $(MODULE).lc
9 MODULE_TARGETS := $(MODULE).so $(MODULE).lc
11 TARGETS := $(TARGETS) $(MODULE_TARGETS)
15 LUA_COMPILED := $(subst .lua,.lc, $(LUA_SOURCES))
16 TARGETS := $(TARGETS) $(LUA_COMPILED)
19 ifdef EXTRA_EXECUTABLE
20 EXECUTABLE := $(EXTRA_EXECUTABLE)
21 BINDIR_ := $(EXTRABINDIR)
26 EXECUTABLE_ := $(EXECUTABLE)$(BIN_SUFFIX)
27 TARGETS := $(TARGETS) $(EXECUTABLE_)
32 ######################################
36 .PHONY: subdirs-realclean
37 .PHONY: subdirs-depend
38 .PHONY: subdirs-install
43 all: subdirs _exports $(TARGETS)
45 clean: subdirs-clean _clean
47 realclean: subdirs-realclean _clean _realclean
49 depend: subdirs-depend _depend
51 install: subdirs-install _install
57 ######################################
62 DEPEND_DEPENDS += $(EXPORTS_H)
64 TO_CLEAN := $(TO_CLEAN) $(EXPORTS_C) $(EXPORTS_H)
66 _exports: $(EXPORTS_C)
68 $(EXPORTS_H): $(EXPORTS_C)
70 $(EXPORTS_C): $(SOURCES) $(MKEXPORTS_EXTRA_DEPS)
71 $(MKEXPORTS) -module $(MAKE_EXPORTS) -o $(EXPORTS_C) -h $(EXPORTS_H) \
72 $(SOURCES) $(MKEXPORTS_EXTRAS)
74 # Exports documentation
75 ######################################
77 EXPORTS_DOC = exports.tex
79 TO_CLEAN := $(TO_CLEAN) $(EXPORTS_DOC)
81 _exports_doc: $(EXPORTS_DOC)
83 $(EXPORTS_DOC): $(SOURCES) $(LUA_SOURCES) $(MKEXPORTS_EXTRA_DEPS)
84 $(MKEXPORTS) -mkdoc -module $(MAKE_EXPORTS) -o $(EXPORTS_DOC) \
85 $(SOURCES) $(LUA_SOURCES) $(MKEXPORTS_EXTRAS)
96 # Compilation and linking
97 ######################################
99 OBJS=$(subst .c,.o,$(SOURCES) $(EXPORTS_C))
106 ifeq ($(PRELOAD_MODULES),1)
107 EXT_OBJS += $(foreach mod, $(MODULE_LIST), $(MODULE_PATH)/$(mod)/$(mod).a)
108 DEPEND_DEPENDS += preload.c
110 TO_CLEAN += preload.c
111 else # !PRELOAD_MODULES
112 LDFLAGS += $(EXPORT_DYNAMIC)
113 WHOLEA = -Wl,-whole-archive
114 NO_WHOLEA = -Wl,-no-whole-archive
115 endif # !PRELOAD_MODULES
118 $(LUA) $(TOPDIR)/build/mkpreload.lua $(MODULE_LIST) > preload.c
123 ifeq ($(RELOCATABLE),1)
124 DEFINES += -DCF_RELOCATABLE_BIN_LOCATION=\"$(BINDIR_)/$(EXECUTABLE)\"
127 $(EXECUTABLE_): $(OBJS) $(EXT_OBJS)
128 $(CC) $(OBJS) $(WHOLEA) $(EXT_OBJS) $(NO_WHOLEA) $(LDFLAGS) -o $@
131 $(INSTALLDIR) $(BINDIR_)
132 $(INSTALLBIN) $(EXECUTABLE_) $(BINDIR_)
139 ifneq ($(PRELOAD_MODULES),1)
141 CC_PICFLAGS=-fPIC -DPIC
142 LD_SHAREDFLAGS=-shared
145 $(CC) $(CC_PICFLAGS) $(CFLAGS) -c $< -o $@
147 $(MODULE).so: $(OBJS) $(EXT_OBJS)
148 $(CC) $(LD_SHAREDFLAGS) $(LDFLAGS) $(OBJS) $(EXT_OBJS) -o $@
151 module_install: module_stub_install
152 $(INSTALLDIR) $(MODULEDIR)
153 $(INSTALLBIN) $(MODULE).so $(MODULEDIR)
155 else # PRELOAD_MODULES
161 $(CC) $(CFLAGS) -c $< -o $@
163 $(MODULE).a: $(OBJS) $(EXT_OBJS)
164 $(AR) $(ARFLAGS) $@ $+
167 module_install: module_stub_install
169 endif # PRELOAD_MODULES
172 $(INSTALLDIR) $(LCDIR)
173 $(INSTALL) -m $(DATA_MODE) $(MODULE).lc $(LCDIR)
178 echo "ioncore.load_module('$(MODULE)')" | $(LUAC) -o $@ -
181 LUA_SOURCES += $(MODULE_STUB)
189 $(CC) $(CFLAGS) -c $< -o $@
196 ######################################
199 $(RM) -f $(TO_CLEAN) core $(DEPEND_FILE) $(OBJS)
202 $(RM) -f $(TO_REALCLEAN) $(TARGETS)
205 ######################################
211 $(INSTALLDIR) $(LCDIR)
212 for i in $(LUA_COMPILED); do \
213 $(INSTALL) -m $(DATA_MODE) $$i $(LCDIR); \
217 $(INSTALLDIR) $(ETCDIR)
218 for i in $(ETC); do \
219 $(INSTALL) -m $(DATA_MODE) $$i $(ETCDIR); \
223 ######################################
227 _depend: $(DEPEND_DEPENDS)
230 ifeq ($(DEPEND_FILE),$(wildcard $(DEPEND_FILE)))
231 include $(DEPEND_FILE)
237 ######################################
242 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done
245 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i depend; done
248 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
251 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i realclean; done
254 set -e; for i in $(INSTALL_SUBDIRS); do $(MAKE) -C $$i install; done
259 ######################################
261 TO_CLEAN += potfiles_c potfiles_lua
264 echo "$(SOURCES)"|tr ' ' '\n' > potfiles_c
265 echo "$(LUA_SOURCES) $(ETC)"|tr ' ' '\n' > potfiles_lua
268 ######################################
271 INSTALLBIN ?= $(INSTALL) $(INSTALL_STRIP) -m $(BIN_MODE)