Import libtu instead of using submodules
[notion.git] / libtu / build / rules.mk
blob3d5eda7535263ec896f1c4d2c9cfc9fd4561d3d1
1 ##
2 ## Some make rules
3 ##
5 # Beware: in releases, the Notion rules.mk is used to build both libtu,
6 # libextl and notion - so structural changes to this file should also be
7 # carried out on the Notion rules.mk
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
18 ifdef LUA_SOURCES
19 LUA_COMPILED := $(subst .lua,.lc, $(LUA_SOURCES))
20 TARGETS := $(TARGETS) $(LUA_COMPILED)
21 endif
24 # Main targets
25 ######################################
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
36 all: subdirs _exports $(TARGETS)
38 clean: subdirs-clean _clean
40 realclean: subdirs-realclean _clean _realclean
42 depend: subdirs-depend _depend
44 install: subdirs-install _install
47 # Exports
48 ######################################
50 ifdef MAKE_EXPORTS
52 EXPORTS_C = exports.c
53 EXPORTS_H = exports.h
55 DEPEND_DEPENDS += $(EXPORTS_H)
57 TO_CLEAN := $(TO_CLEAN) $(EXPORTS_C) $(EXPORTS_H)
59 _exports: $(EXPORTS_C)
61 $(EXPORTS_H): $(EXPORTS_C)
63 $(EXPORTS_C):
64 $(MKEXPORTS) -module $(MAKE_EXPORTS) -o $(EXPORTS_C) -h $(EXPORTS_H) $(SOURCES)
66 else # !MAKE_EXPORTS
68 EXPORTS_C =
69 EXPORTS_H =
71 endif # !MAKE_EXPORTS
74 # Compilation and linking
75 ######################################
77 OBJS=$(subst .c,.o,$(SOURCES) $(EXPORTS_C))
79 ifdef MODULE
81 ifneq ($(PRELOAD_MODULES),1)
83 CC_PICFLAGS=-fPIC -DPIC
84 LD_SHAREDFLAGS=-shared
86 %.o: %.c
87 $(CC) $(CC_PICFLAGS) $(CFLAGS) -c $< -o $@
89 $(MODULE).so: $(OBJS) $(EXT_OBJS)
90 $(CC) $(LD_SHAREDFLAGS) $(LDFLAGS) $(OBJS) $(EXT_OBJS) -o $@
93 module_install: module_stub_install
94 $(INSTALLDIR) $(MODULEDIR)
95 $(INSTALL) -m $(BIN_MODE) $(MODULE).so $(MODULEDIR)
97 else # PRELOAD_MODULES
99 PICOPT=-fPIC -DPIC
100 LINKOPT=-shared
102 %.o: %.c
103 $(CC) $(CFLAGS) -c $< -o $@
105 $(MODULE).a: $(OBJS) $(EXT_OBJS)
106 $(AR) $(ARFLAGS) $@ $+
107 $(RANLIB) $@
109 module_install: module_stub_install
111 endif # PRELOAD_MODULES
113 module_stub_install:
114 $(INSTALLDIR) $(LCDIR)
115 $(INSTALL) -m $(DATA_MODE) $(MODULE).lc $(LCDIR)
117 ifndef MODULE_STUB
119 $(MODULE).lc:
120 echo "ioncore.load_module('$(MODULE)')" | $(LUAC) -o $@ -
121 else
123 LUA_SOURCES += $(MODULE_STUB)
125 endif #MODULE_STUB
127 else # !MODULE
130 %.o: %.c
131 $(CC) $(CFLAGS) -c $< -o $@
134 endif# !MODULE
137 # Clean rules
138 ######################################
140 _clean:
141 $(RM) -f $(TO_CLEAN) core $(DEPEND_FILE) $(OBJS)
143 _realclean:
144 $(RM) -f $(TO_REALCLEAN) $(TARGETS)
146 # Lua rules
147 ######################################
149 %.lc: %.lua
150 $(LUAC) -o $@ $<
152 lc_install:
153 $(INSTALLDIR) $(LCDIR)
154 for i in $(LUA_COMPILED); do \
155 $(INSTALL) -m $(DATA_MODE) $$i $(LCDIR); \
156 done
158 etc_install:
159 $(INSTALLDIR) $(ETCDIR)
160 for i in $(ETC); do \
161 $(INSTALL) -m $(DATA_MODE) $$i $(ETCDIR); \
162 done
164 # Dependencies
165 ######################################
167 ifdef SOURCES
169 _depend: $(DEPEND_DEPENDS)
170 $(MAKE_DEPEND)
172 ifeq ($(DEPEND_FILE),$(wildcard $(DEPEND_FILE)))
173 include $(DEPEND_FILE)
174 endif
176 endif
178 # Subdirectories
179 ######################################
181 ifdef SUBDIRS
183 subdirs:
184 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done
186 subdirs-depend:
187 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i depend; done
189 subdirs-clean:
190 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
192 subdirs-realclean:
193 set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i realclean; done
195 subdirs-install:
196 set -e; for i in $(INSTALL_SUBDIRS); do $(MAKE) -C $$i install; done
198 endif
200 # Localisation
201 ######################################
203 TO_CLEAN += potfiles_c potfiles_lua
205 _potfiles:
206 echo "$(SOURCES)"|tr ' ' '\n' > potfiles_c
207 echo "$(LUA_SOURCES) $(ETC)"|tr ' ' '\n' > potfiles_lua