rules.mk

changeset 82
895f6304179d
parent 51
2d95d77aa954
equal deleted inserted replaced
81:ebefcbcb126f 82:895f6304179d
1 ## 1 ##
2 ## Some make rules 2 ## Some make rules
3 ## 3 ##
4 4
5 ###################################### 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
6 13
7 ifdef MODULE 14 ifdef LUA_SOURCES
8 ifneq ($(STATIC_MODULES),1) 15 LUA_COMPILED := $(subst .lua,.lc, $(LUA_SOURCES))
9 TARGETS := $(TARGETS) $(MODULE).so 16 TARGETS := $(TARGETS) $(LUA_COMPILED)
10 else
11 TARGETS := $(TARGETS) $(MODULE).a
12 endif
13 endif 17 endif
14 18
15 19
16 ifdef SUBDIRS 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
17 30
18 all: subdirs $(TARGETS) 31 all: subdirs $(TARGETS)
19 32
20 clean: subdirs-clean _clean 33 clean: subdirs-clean _clean
21 34
22 realclean: subdirs-realclean _clean _realclean 35 realclean: subdirs-realclean _clean _realclean
23 36
24 depend: subdirs-depend _depend 37 depend: subdirs-depend _depend
25 38
26 else
27
28 all: $(TARGETS)
29
30 clean: _clean
31
32 realclean: _clean _realclean
33
34 depend: _depend
35
36 endif
37
38 ifdef INSTALL_SUBDIRS
39
40 install: subdirs-install _install 39 install: subdirs-install _install
41 40
42 else
43 41
44 install: _install 42 # Exports
45
46 endif
47
48 ###################################### 43 ######################################
49
50 OBJS=$(subst .c,.o,$(SOURCES))
51 44
52 ifdef MAKE_EXPORTS 45 ifdef MAKE_EXPORTS
53 46
54 TO_CLEAN := $(TO_CLEAN) exports.c 47 TO_CLEAN := $(TO_CLEAN) exports.c
55 48
56 OBJS := $(OBJS) exports.o 49 EXPORTS_C = exports.c
57 50
58 exports.c: $(SOURCES) 51 exports.c: $(SOURCES)
59 $(PERL) $(TOPDIR)/mkexports.pl $(MAKE_EXPORTS) 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
60 162
61 endif 163 endif
62 164
63 ifdef MODULE 165 # Subdirectories
166 ######################################
64 167
65 ifneq ($(STATIC_MODULES),1) 168 ifdef SUBDIRS
66
67 $(MODULE).so: $(OBJS) $(EXT_OBJS)
68 $(CC) $(CFLAGS) $(LDFLAGS) $(MODULE_LDFLAGS) $(OBJS) $(EXT_OBJS) -o $@
69
70 module_install:
71 $(INSTALLDIR) $(MODULEDIR)
72 $(INSTALL) -m $(BIN_MODE) $(MODULE).so $(MODULEDIR)
73 # $(STRIP) $(MODULEDIR)/$(MODULE).so
74
75 else
76
77 $(MODULE).a: $(OBJS)
78 $(AR) $(ARFLAGS) $@ $+
79 $(RANLIB) $@
80
81 module_install:
82
83 endif
84
85 .c.o:
86 $(CC) $(CFLAGS) $(MODULE_CFLAGS) -c $< -o $@
87
88 else
89
90 .c.o:
91 $(CC) $(CFLAGS) -c $< -o $@
92
93 endif
94
95 _clean:
96 rm -f core $(DEPEND_FILE) $(OBJS) $(TO_CLEAN)
97
98 _realclean:
99 rm -f $(TARGETS) $(TO_REALCLEAN)
100
101
102 ifdef SOURCES
103 _depend:
104 $(MAKE_DEPEND) $(SOURCES)
105 else
106 _depend:
107
108 endif
109
110 ######################################
111 169
112 subdirs: 170 subdirs:
113 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done 171 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done
114 172
115 subdirs-depend: 173 subdirs-depend:
122 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i realclean; done 180 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i realclean; done
123 181
124 subdirs-install: 182 subdirs-install:
125 set -e; for i in $(INSTALL_SUBDIRS); do $(MAKE) -C $$i install; done 183 set -e; for i in $(INSTALL_SUBDIRS); do $(MAKE) -C $$i install; done
126 184
185 endif
186
187 # Localisation
127 ###################################### 188 ######################################
128 189
129 ifeq ($(DEPEND_FILE),$(wildcard $(DEPEND_FILE))) 190 TO_CLEAN += potfiles_c potfiles_lua
130 include $(DEPEND_FILE) 191
131 endif 192 _potfiles:
193 echo "$(SOURCES)"|tr ' ' '\n' > potfiles_c
194 echo "$(LUA_SOURCES) $(ETC)"|tr ' ' '\n' > potfiles_lua

mercurial