trunk: changeset 1970
[notion/jeffpc.git] / rules.mk
blob6bdf86c40fc317a75a17f5e5062d243c7f2ae75f
1 ##
2 ## Some make rules
3 ##
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
14 ifdef LUA_SOURCES
15 LUA_COMPILED := $(subst .lua,.lc, $(LUA_SOURCES))
16 TARGETS := $(TARGETS) $(LUA_COMPILED)
17 endif
20 # Main targets
21 ######################################
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
31 all: subdirs $(TARGETS)
33 clean: subdirs-clean _clean
35 realclean: subdirs-realclean _clean _realclean
37 depend: subdirs-depend _depend
39 install: subdirs-install _install
42 # Exports
43 ######################################
45 ifdef MAKE_EXPORTS
47 TO_CLEAN := $(TO_CLEAN) exports.c
49 EXPORTS_C = exports.c
51 exports.c: $(SOURCES)
52 $(MKEXPORTS) -module $(MAKE_EXPORTS) -o exports.c $(SOURCES)
54 else # !MAKE_EXPORTS
56 EXPORTS_C =
58 endif # !MAKE_EXPORTS
61 # Compilation and linking
62 ######################################
64 OBJS=$(subst .c,.o,$(SOURCES) $(EXPORTS_C))
66 ifdef MODULE
68 ifneq ($(PRELOAD_MODULES),1)
70 CC_PICFLAGS=-fPIC -DPIC
71 LD_SHAREDFLAGS=-shared
73 %.o: %.c
74 $(CC) $(CC_PICFLAGS) $(CFLAGS) -c $< -o $@
76 $(MODULE).so: $(OBJS) $(EXT_OBJS)
77 $(CC) $(LD_SHAREDFLAGS) $(LDFLAGS) $(OBJS) $(EXT_OBJS) -o $@
80 module_install: module_stub_install
81 $(INSTALLDIR) $(MODULEDIR)
82 $(INSTALL) -m $(BIN_MODE) $(MODULE).so $(MODULEDIR)
84 else # PRELOAD_MODULES
86 PICOPT=-fPIC -DPIC
87 LINKOPT=-shared
89 %.o: %.c
90 $(CC) $(CFLAGS) -c $< -o $@
92 $(MODULE).a: $(OBJS) $(EXT_OBJS)
93 $(AR) $(ARFLAGS) $@ $+
94 $(RANLIB) $@
96 module_install: module_stub_install
98 endif # PRELOAD_MODULES
100 module_stub_install:
101 $(INSTALLDIR) $(LCDIR)
102 $(INSTALL) -m $(DATA_MODE) $(MODULE).lc $(LCDIR)
104 ifndef MODULE_STUB
106 $(MODULE).lc:
107 echo "ioncore.load_module('$(MODULE)')" | $(LUAC) -o $@ -
108 else
110 LUA_SOURCES += $(MODULE_STUB)
112 endif #MODULE_STUB
114 else # !MODULE
117 %.o: %.c
118 $(CC) $(CFLAGS) -c $< -o $@
121 endif# !MODULE
124 # Clean rules
125 ######################################
127 _clean:
128 $(RM) -f $(TO_CLEAN) core $(DEPEND_FILE) $(OBJS)
130 _realclean:
131 $(RM) -f $(TO_REALCLEAN) $(TARGETS)
133 # Lua rules
134 ######################################
136 %.lc: %.lua
137 $(LUAC) -o $@ $<
139 lc_install:
140 $(INSTALLDIR) $(LCDIR)
141 for i in $(LUA_COMPILED); do \
142 $(INSTALL) -m $(DATA_MODE) $$i $(LCDIR); \
143 done
145 etc_install:
146 $(INSTALLDIR) $(ETCDIR)
147 for i in $(ETC); do \
148 $(INSTALL) -m $(DATA_MODE) $$i $(ETCDIR); \
149 done
151 # Dependencies
152 ######################################
154 ifdef SOURCES
156 _depend: $(DEPEND_DEPENDS)
157 $(MAKE_DEPEND)
159 ifeq ($(DEPEND_FILE),$(wildcard $(DEPEND_FILE)))
160 include $(DEPEND_FILE)
161 endif
163 endif
165 # Subdirectories
166 ######################################
168 ifdef SUBDIRS
170 subdirs:
171 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done
173 subdirs-depend:
174 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i depend; done
176 subdirs-clean:
177 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
179 subdirs-realclean:
180 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i realclean; done
182 subdirs-install:
183 set -e; for i in $(INSTALL_SUBDIRS); do $(MAKE) -C $$i install; done
185 endif
187 # Localisation
188 ######################################
190 TO_CLEAN += potfiles_c potfiles_lua
192 _potfiles:
193 echo "$(SOURCES)"|tr ' ' '\n' > potfiles_c
194 echo "$(LUA_SOURCES) $(ETC)"|tr ' ' '\n' > potfiles_lua