]> git.decadent.org.uk Git - ion3.git/blob - build/rules.mk
[svn-upgrade] Integrating new upstream version, ion3 (20080207)
[ion3.git] / build / rules.mk
1 ##
2 ## Some make rules
3 ##
4
5 ifdef MODULE
6 ifeq ($(PRELOAD_MODULES),1)
7 MODULE_TARGETS := $(MODULE).a $(MODULE).lc
8 else
9 MODULE_TARGETS := $(MODULE).so $(MODULE).lc
10 endif
11 TARGETS := $(TARGETS) $(MODULE_TARGETS)
12 endif
13
14 ifdef LUA_SOURCES
15 LUA_COMPILED := $(subst .lua,.lc, $(LUA_SOURCES))
16 TARGETS := $(TARGETS) $(LUA_COMPILED)
17 endif
18
19 ifdef EXTRA_EXECUTABLE
20 EXECUTABLE := $(EXTRA_EXECUTABLE)
21 BINDIR_ := $(EXTRABINDIR)
22 endif
23
24 ifdef EXECUTABLE
25 BINDIR_ ?= $(BINDIR)
26 EXECUTABLE_ := $(EXECUTABLE)$(BIN_SUFFIX)
27 TARGETS := $(TARGETS) $(EXECUTABLE_)
28 endif
29
30
31 # Main targets
32 ######################################
33
34 .PHONY: subdirs
35 .PHONY: subdirs-clean
36 .PHONY: subdirs-realclean
37 .PHONY: subdirs-depend
38 .PHONY: subdirs-install
39 .PHONY: _install
40 .PHONY: _depend
41 .PHONY: _exports
42
43 all: subdirs _exports $(TARGETS)
44
45 clean: subdirs-clean _clean
46
47 realclean: subdirs-realclean _clean _realclean
48
49 depend: subdirs-depend _depend
50
51 install: subdirs-install _install
52
53
54 ifdef MAKE_EXPORTS
55
56 # Exports
57 ######################################
58
59 EXPORTS_C = exports.c
60 EXPORTS_H = exports.h
61
62 DEPEND_DEPENDS += $(EXPORTS_H)
63
64 TO_CLEAN := $(TO_CLEAN) $(EXPORTS_C) $(EXPORTS_H)
65
66 _exports: $(EXPORTS_C)
67
68 $(EXPORTS_H): $(EXPORTS_C)
69
70 $(EXPORTS_C): $(SOURCES) $(MKEXPORTS_EXTRA_DEPS)
71         $(MKEXPORTS) -module $(MAKE_EXPORTS) -o $(EXPORTS_C) -h $(EXPORTS_H) \
72         $(SOURCES) $(MKEXPORTS_EXTRAS)
73
74 # Exports documentation
75 ######################################
76
77 EXPORTS_DOC = exports.tex
78
79 TO_CLEAN := $(TO_CLEAN) $(EXPORTS_DOC)
80
81 _exports_doc: $(EXPORTS_DOC)
82
83 $(EXPORTS_DOC): $(SOURCES) $(LUA_SOURCES) $(MKEXPORTS_EXTRA_DEPS)
84         $(MKEXPORTS) -mkdoc -module $(MAKE_EXPORTS) -o $(EXPORTS_DOC) \
85         $(SOURCES) $(LUA_SOURCES) $(MKEXPORTS_EXTRAS)
86
87 else # !MAKE_EXPORTS
88
89 EXPORTS_C = 
90 EXPORTS_H = 
91 EXPORTS_DOC =
92
93 endif # !MAKE_EXPORTS
94
95
96 # Compilation and linking
97 ######################################
98
99 OBJS=$(subst .c,.o,$(SOURCES) $(EXPORTS_C))
100
101
102 ifdef EXECUTABLE
103
104 ifdef MODULE_LIST
105 ifdef MODULE_PATH
106 ifeq ($(PRELOAD_MODULES),1)
107 EXT_OBJS += $(foreach mod, $(MODULE_LIST), $(MODULE_PATH)/$(mod)/$(mod).a)
108 DEPEND_DEPENDS += preload.c
109 SOURCES += 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
116
117 preload.c:
118         $(LUA) $(TOPDIR)/build/mkpreload.lua $(MODULE_LIST) > preload.c
119
120 endif # MODULE_PATH
121 endif # MODULE_LIST
122
123 ifeq ($(RELOCATABLE),1)
124 DEFINES += -DCF_RELOCATABLE_BIN_LOCATION=\"$(BINDIR_)/$(EXECUTABLE)\"
125 endif
126
127 $(EXECUTABLE_): $(OBJS) $(EXT_OBJS)
128         $(CC) $(OBJS) $(WHOLEA) $(EXT_OBJS) $(NO_WHOLEA) $(LDFLAGS) -o $@
129
130 executable_install:
131         $(INSTALLDIR) $(BINDIR_)
132         $(INSTALLBIN) $(EXECUTABLE_) $(BINDIR_)
133
134 endif # EXECUTABLE
135
136
137 ifdef MODULE
138
139 ifneq ($(PRELOAD_MODULES),1)
140
141 CC_PICFLAGS=-fPIC -DPIC
142 LD_SHAREDFLAGS=-shared
143
144 %.o: %.c
145         $(CC) $(CC_PICFLAGS) $(CFLAGS) -c $< -o $@
146
147 $(MODULE).so: $(OBJS) $(EXT_OBJS)
148         $(CC) $(LD_SHAREDFLAGS) $(LDFLAGS) $(OBJS) $(EXT_OBJS) -o $@
149
150
151 module_install: module_stub_install
152         $(INSTALLDIR) $(MODULEDIR)
153         $(INSTALLBIN) $(MODULE).so $(MODULEDIR)
154
155 else # PRELOAD_MODULES
156
157 PICOPT=-fPIC -DPIC
158 LINKOPT=-shared
159
160 %.o: %.c
161         $(CC) $(CFLAGS) -c $< -o $@
162
163 $(MODULE).a: $(OBJS) $(EXT_OBJS)
164         $(AR) $(ARFLAGS) $@ $+
165         $(RANLIB) $@
166
167 module_install: module_stub_install
168
169 endif # PRELOAD_MODULES
170
171 module_stub_install:
172         $(INSTALLDIR) $(LCDIR)
173         $(INSTALL) -m $(DATA_MODE) $(MODULE).lc $(LCDIR)
174
175 ifndef MODULE_STUB
176
177 $(MODULE).lc:
178         echo "ioncore.load_module('$(MODULE)')" | $(LUAC) -o $@ -
179 else
180
181 LUA_SOURCES += $(MODULE_STUB)
182
183 endif #MODULE_STUB
184
185 else # !MODULE
186
187
188 %.o: %.c
189         $(CC) $(CFLAGS) -c $< -o $@
190
191
192 endif# !MODULE
193
194
195 # Clean rules
196 ######################################
197
198 _clean:
199         $(RM) -f $(TO_CLEAN) core $(DEPEND_FILE) $(OBJS)
200
201 _realclean:
202         $(RM) -f $(TO_REALCLEAN) $(TARGETS)
203
204 # Lua rules
205 ######################################
206
207 %.lc: %.lua
208         $(LUAC) -o $@ $<
209
210 lc_install:
211         $(INSTALLDIR) $(LCDIR)
212         for i in $(LUA_COMPILED); do \
213                 $(INSTALL) -m $(DATA_MODE) $$i $(LCDIR); \
214         done
215
216 etc_install:
217         $(INSTALLDIR) $(ETCDIR)
218         for i in $(ETC); do \
219                 $(INSTALL) -m $(DATA_MODE) $$i $(ETCDIR); \
220         done
221
222 # Dependencies
223 ######################################
224
225 ifdef SOURCES
226
227 _depend: $(DEPEND_DEPENDS)
228         $(MAKE_DEPEND)
229
230 ifeq ($(DEPEND_FILE),$(wildcard $(DEPEND_FILE)))
231 include $(DEPEND_FILE)
232 endif
233
234 endif
235
236 # Subdirectories
237 ######################################
238
239 ifdef SUBDIRS
240
241 subdirs:
242         set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done
243
244 subdirs-depend:
245         set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i depend; done
246
247 subdirs-clean:
248         set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
249
250 subdirs-realclean:
251         set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i realclean; done
252
253 subdirs-install:
254         set -e; for i in $(INSTALL_SUBDIRS); do $(MAKE) -C $$i install; done
255
256 endif
257
258 # Localisation
259 ######################################
260
261 TO_CLEAN += potfiles_c potfiles_lua
262
263 _potfiles:
264         echo "$(SOURCES)"|tr ' ' '\n' > potfiles_c
265         echo "$(LUA_SOURCES) $(ETC)"|tr ' ' '\n' > potfiles_lua
266
267 # Defaults
268 ######################################
269
270 INSTALL_STRIP ?= -s
271 INSTALLBIN ?= $(INSTALL) $(INSTALL_STRIP) -m $(BIN_MODE)