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