]> git.decadent.org.uk Git - ion3.git/blob - build/rules.mk
3f8a42d0cfff40963a6d6e5dad16a20655069753
[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 # Exports
44 ######################################
45
46 ifdef MAKE_EXPORTS
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)
60         $(MKEXPORTS) -module $(MAKE_EXPORTS) -o $(EXPORTS_C) -h $(EXPORTS_H) \
61         $(SOURCES) $(MKEXPORTS_EXTRAS)
62
63 else # !MAKE_EXPORTS
64
65 EXPORTS_C = 
66 EXPORTS_H = 
67
68 endif # !MAKE_EXPORTS
69
70
71 # Compilation and linking
72 ######################################
73
74 OBJS=$(subst .c,.o,$(SOURCES) $(EXPORTS_C))
75
76 ifdef MODULE
77
78 ifneq ($(PRELOAD_MODULES),1)
79
80 CC_PICFLAGS=-fPIC -DPIC
81 LD_SHAREDFLAGS=-shared
82
83 %.o: %.c
84         $(CC) $(CC_PICFLAGS) $(CFLAGS) -c $< -o $@
85
86 $(MODULE).so: $(OBJS) $(EXT_OBJS)
87         $(CC) $(LD_SHAREDFLAGS) $(LDFLAGS) $(OBJS) $(EXT_OBJS) -o $@
88
89
90 module_install: module_stub_install
91         $(INSTALLDIR) $(MODULEDIR)
92         $(INSTALL) -m $(BIN_MODE) $(MODULE).so $(MODULEDIR)
93
94 else # PRELOAD_MODULES
95
96 PICOPT=-fPIC -DPIC
97 LINKOPT=-shared
98
99 %.o: %.c
100         $(CC) $(CFLAGS) -c $< -o $@
101
102 $(MODULE).a: $(OBJS) $(EXT_OBJS)
103         $(AR) $(ARFLAGS) $@ $+
104         $(RANLIB) $@
105
106 module_install: module_stub_install
107
108 endif # PRELOAD_MODULES
109
110 module_stub_install:
111         $(INSTALLDIR) $(LCDIR)
112         $(INSTALL) -m $(DATA_MODE) $(MODULE).lc $(LCDIR)
113
114 ifndef MODULE_STUB
115
116 $(MODULE).lc:
117         echo "ioncore.load_module('$(MODULE)')" | $(LUAC) -o $@ -
118 else
119
120 LUA_SOURCES += $(MODULE_STUB)
121
122 endif #MODULE_STUB
123
124 else # !MODULE
125
126
127 %.o: %.c
128         $(CC) $(CFLAGS) -c $< -o $@
129
130
131 endif# !MODULE
132
133
134 # Clean rules
135 ######################################
136
137 _clean:
138         $(RM) -f $(TO_CLEAN) core $(DEPEND_FILE) $(OBJS)
139
140 _realclean:
141         $(RM) -f $(TO_REALCLEAN) $(TARGETS)
142
143 # Lua rules
144 ######################################
145
146 %.lc: %.lua
147         $(LUAC) -o $@ $<
148
149 lc_install:
150         $(INSTALLDIR) $(LCDIR)
151         for i in $(LUA_COMPILED); do \
152                 $(INSTALL) -m $(DATA_MODE) $$i $(LCDIR); \
153         done
154
155 etc_install:
156         $(INSTALLDIR) $(ETCDIR)
157         for i in $(ETC); do \
158                 $(INSTALL) -m $(DATA_MODE) $$i $(ETCDIR); \
159         done
160
161 # Dependencies
162 ######################################
163
164 ifdef SOURCES
165
166 _depend: $(DEPEND_DEPENDS)
167         $(MAKE_DEPEND)
168
169 ifeq ($(DEPEND_FILE),$(wildcard $(DEPEND_FILE)))
170 include $(DEPEND_FILE)
171 endif
172
173 endif
174
175 # Subdirectories
176 ######################################
177
178 ifdef SUBDIRS
179
180 subdirs:
181         set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done
182
183 subdirs-depend:
184         set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i depend; done
185
186 subdirs-clean:
187         set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
188
189 subdirs-realclean:
190         set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i realclean; done
191
192 subdirs-install:
193         set -e; for i in $(INSTALL_SUBDIRS); do $(MAKE) -C $$i install; done
194
195 endif
196
197 # Localisation
198 ######################################
199
200 TO_CLEAN += potfiles_c potfiles_lua
201
202 _potfiles:
203         echo "$(SOURCES)"|tr ' ' '\n' > potfiles_c
204         echo "$(LUA_SOURCES) $(ETC)"|tr ' ' '\n' > potfiles_lua