Released version 3-2015061300
[notion.git] / libtu / build / rules.mk
bloba6c2845ba1cdd74fe2abd1cac3f2703b758e42cc
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-install
31 .PHONY: _install
32 .PHONY: _exports
34 all: subdirs _exports $(TARGETS)
36 clean: subdirs-clean _clean
38 realclean: subdirs-realclean _clean _realclean
40 install: subdirs-install _install
43 # Exports
44 ######################################
46 ifdef MAKE_EXPORTS
48 EXPORTS_C = exports.c
49 EXPORTS_H = exports.h
51 TO_CLEAN := $(TO_CLEAN) $(EXPORTS_C) $(EXPORTS_H)
53 _exports: $(EXPORTS_C)
55 # this funny syntax (more than one pattern-based target) is meant to tell Make
56 # that this rule makes BOTH of these targets. Look at the last paragraph of
57 # http://www.gnu.org/software/make/manual/html_node/Pattern-Intro.html
58 %xports.c %xports.h:
59 $(MKEXPORTS) -module $(MAKE_EXPORTS) -o $(EXPORTS_C) -h $(EXPORTS_H) $(SOURCES)
61 else # !MAKE_EXPORTS
63 EXPORTS_C =
64 EXPORTS_H =
66 endif # !MAKE_EXPORTS
69 # Compilation and linking
70 ######################################
72 OBJS=$(subst .c,.o,$(SOURCES) $(EXPORTS_C))
74 ifdef MODULE
76 ifneq ($(PRELOAD_MODULES),1)
78 CC_PICFLAGS=-fPIC -DPIC
79 LD_SHAREDFLAGS=-shared
81 %.o: %.c
82 $(CC) $(CC_PICFLAGS) $(CFLAGS) -c $< -o $@
84 $(MODULE).so: $(OBJS) $(EXT_OBJS)
85 $(CC) $(LD_SHAREDFLAGS) $(LDFLAGS) $(OBJS) $(EXT_OBJS) -o $@
88 module_install: module_stub_install
89 $(INSTALLDIR) $(MODULEDIR)
90 $(INSTALL) -m $(BIN_MODE) $(MODULE).so $(MODULEDIR)
92 else # PRELOAD_MODULES
94 PICOPT=-fPIC -DPIC
95 LINKOPT=-shared
97 %.o: %.c
98 $(CC) $(CFLAGS) -c $< -o $@
100 $(MODULE).a: $(OBJS) $(EXT_OBJS)
101 $(AR) $(ARFLAGS) $@ $+
102 $(RANLIB) $@
104 module_install: module_stub_install
106 endif # PRELOAD_MODULES
108 module_stub_install:
109 $(INSTALLDIR) $(LCDIR)
110 $(INSTALL) -m $(DATA_MODE) $(MODULE).lc $(LCDIR)
112 ifndef MODULE_STUB
114 $(MODULE).lc:
115 echo "ioncore.load_module('$(MODULE)')" | $(LUAC) -o $@ -
116 else
118 LUA_SOURCES += $(MODULE_STUB)
120 endif #MODULE_STUB
122 else # !MODULE
125 %.o: %.c
126 $(CC) $(CFLAGS) -c $< -o $@
129 endif# !MODULE
132 # Clean rules
133 ######################################
135 _clean:
136 $(RM) -f $(TO_CLEAN) core *.d $(OBJS)
138 _realclean:
139 $(RM) -f $(TO_REALCLEAN) $(TARGETS)
141 # Lua rules
142 ######################################
144 %.lc: %.lua
145 $(LUAC) -o $@ $<
147 lc_install:
148 $(INSTALLDIR) $(LCDIR)
149 for i in $(LUA_COMPILED); do \
150 $(INSTALL) -m $(DATA_MODE) $$i $(LCDIR); \
151 done
153 etc_install:
154 $(INSTALLDIR) $(ETCDIR)
155 for i in $(ETC); do \
156 $(INSTALL) -m $(DATA_MODE) $$i $(ETCDIR); \
157 done
159 # Dependencies
160 ######################################
162 CFLAGS += -MMD
163 -include *.d
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