]> git.decadent.org.uk Git - ion3.git/blob - build/rules.mk
[svn-upgrade] Integrating new upstream version, ion3 (20070506)
[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
20 # Main targets
21 ######################################
22
23 .PHONY: subdirs
24 .PHONY: subdirs-clean
25 .PHONY: subdirs-realclean
26 .PHONY: subdirs-depend
27 .PHONY: subdirs-install
28 .PHONY: _install
29 .PHONY: _depend
30 .PHONY: _exports
31
32 all: subdirs _exports $(TARGETS)
33
34 clean: subdirs-clean _clean
35
36 realclean: subdirs-realclean _clean _realclean
37
38 depend: subdirs-depend _depend
39
40 install: subdirs-install _install
41
42
43 ifdef MAKE_EXPORTS
44
45 # Exports
46 ######################################
47
48 EXPORTS_C = exports.c
49 EXPORTS_H = exports.h
50
51 DEPEND_DEPENDS += $(EXPORTS_H)
52
53 TO_CLEAN := $(TO_CLEAN) $(EXPORTS_C) $(EXPORTS_H)
54
55 _exports: $(EXPORTS_C)
56
57 $(EXPORTS_H): $(EXPORTS_C)
58
59 $(EXPORTS_C): $(SOURCES) $(MKEXPORTS_EXTRA_DEPS)
60         $(MKEXPORTS) -module $(MAKE_EXPORTS) -o $(EXPORTS_C) -h $(EXPORTS_H) \
61         $(SOURCES) $(MKEXPORTS_EXTRAS)
62
63 # Exports documentation
64 ######################################
65
66 EXPORTS_DOC = exports.tex
67
68 TO_CLEAN := $(TO_CLEAN) $(EXPORTS_DOC)
69
70 _exports_doc: $(EXPORTS_DOC)
71
72 $(EXPORTS_DOC): $(SOURCES) $(LUA_SOURCES) $(MKEXPORTS_EXTRA_DEPS)
73         $(MKEXPORTS) -mkdoc -module $(MAKE_EXPORTS) -o $(EXPORTS_DOC) \
74         $(SOURCES) $(LUA_SOURCES) $(MKEXPORTS_EXTRAS)
75
76 else # !MAKE_EXPORTS
77
78 EXPORTS_C = 
79 EXPORTS_H = 
80 EXPORTS_DOC =
81
82 endif # !MAKE_EXPORTS
83
84
85 # Compilation and linking
86 ######################################
87
88 OBJS=$(subst .c,.o,$(SOURCES) $(EXPORTS_C))
89
90 ifdef MODULE
91
92 ifneq ($(PRELOAD_MODULES),1)
93
94 CC_PICFLAGS=-fPIC -DPIC
95 LD_SHAREDFLAGS=-shared
96
97 %.o: %.c
98         $(CC) $(CC_PICFLAGS) $(CFLAGS) -c $< -o $@
99
100 $(MODULE).so: $(OBJS) $(EXT_OBJS)
101         $(CC) $(LD_SHAREDFLAGS) $(LDFLAGS) $(OBJS) $(EXT_OBJS) -o $@
102
103
104 module_install: module_stub_install
105         $(INSTALLDIR) $(MODULEDIR)
106         $(INSTALL) -m $(BIN_MODE) $(MODULE).so $(MODULEDIR)
107
108 else # PRELOAD_MODULES
109
110 PICOPT=-fPIC -DPIC
111 LINKOPT=-shared
112
113 %.o: %.c
114         $(CC) $(CFLAGS) -c $< -o $@
115
116 $(MODULE).a: $(OBJS) $(EXT_OBJS)
117         $(AR) $(ARFLAGS) $@ $+
118         $(RANLIB) $@
119
120 module_install: module_stub_install
121
122 endif # PRELOAD_MODULES
123
124 module_stub_install:
125         $(INSTALLDIR) $(LCDIR)
126         $(INSTALL) -m $(DATA_MODE) $(MODULE).lc $(LCDIR)
127
128 ifndef MODULE_STUB
129
130 $(MODULE).lc:
131         echo "ioncore.load_module('$(MODULE)')" | $(LUAC) -o $@ -
132 else
133
134 LUA_SOURCES += $(MODULE_STUB)
135
136 endif #MODULE_STUB
137
138 else # !MODULE
139
140
141 %.o: %.c
142         $(CC) $(CFLAGS) -c $< -o $@
143
144
145 endif# !MODULE
146
147
148 # Clean rules
149 ######################################
150
151 _clean:
152         $(RM) -f $(TO_CLEAN) core $(DEPEND_FILE) $(OBJS)
153
154 _realclean:
155         $(RM) -f $(TO_REALCLEAN) $(TARGETS)
156
157 # Lua rules
158 ######################################
159
160 %.lc: %.lua
161         $(LUAC) -o $@ $<
162
163 lc_install:
164         $(INSTALLDIR) $(LCDIR)
165         for i in $(LUA_COMPILED); do \
166                 $(INSTALL) -m $(DATA_MODE) $$i $(LCDIR); \
167         done
168
169 etc_install:
170         $(INSTALLDIR) $(ETCDIR)
171         for i in $(ETC); do \
172                 $(INSTALL) -m $(DATA_MODE) $$i $(ETCDIR); \
173         done
174
175 # Dependencies
176 ######################################
177
178 ifdef SOURCES
179
180 _depend: $(DEPEND_DEPENDS)
181         $(MAKE_DEPEND)
182
183 ifeq ($(DEPEND_FILE),$(wildcard $(DEPEND_FILE)))
184 include $(DEPEND_FILE)
185 endif
186
187 endif
188
189 # Subdirectories
190 ######################################
191
192 ifdef SUBDIRS
193
194 subdirs:
195         set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done
196
197 subdirs-depend:
198         set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i depend; done
199
200 subdirs-clean:
201         set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
202
203 subdirs-realclean:
204         set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i realclean; done
205
206 subdirs-install:
207         set -e; for i in $(INSTALL_SUBDIRS); do $(MAKE) -C $$i install; done
208
209 endif
210
211 # Localisation
212 ######################################
213
214 TO_CLEAN += potfiles_c potfiles_lua
215
216 _potfiles:
217         echo "$(SOURCES)"|tr ' ' '\n' > potfiles_c
218         echo "$(LUA_SOURCES) $(ETC)"|tr ' ' '\n' > potfiles_lua