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