File: Makefile.common

package info (click to toggle)
lua-gtk 0.9%2B20100528-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,176 kB
  • ctags: 1,934
  • sloc: ansic: 9,571; sh: 373; makefile: 241
file content (257 lines) | stat: -rwxr-xr-x 6,254 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257

# Common Makefile rules to build a library module.  Following variables need
# to be set before including this file:
#
# MODULE (optional)
# Name of the module to build.  Source is in src/$(MODULE), and the build
# directory (with configure-generated config files) is in
# build/$(ARCH)/$(MODULE).  If not given, only targets not related to
# individual modules are available (i.e., install)
#
# SRC (optional)
# list of module specific source files in addition to init.c and the
# files generated from the headers (types, functions etc.)
#

# Read state file if exists.  Don't use :=, because then the new state (if
# changed) wouldn't be used in the submake invocation.  May be overridden on
# the command line.
FILE = $(wildcard build/make.state)
ifneq ($(FILE), )
    include $(FILE)
endif

# The $(MODULE) is defined in src/*/Makefile
ifeq ($(MODULE), )

all:
	$(error You have to define $$MODULE)

install:
	script/install.lua build/$(ARCH)
else

# include the config file, which must exist.
ifeq ($(wildcard build/$(ARCH)/$(MODULE)/config.make), )

clean:
	@true

all:
	$(error Library $(ARCH)/$(MODULE) not yet configured)
else



all: module_$(MODULE) dummy

# avoid "nothing to do for ..." messages
dummy:
	@true

include build/$(ARCH)/$(MODULE)/config.make


ifdef NOT_AVAILABLE
  $(warning The module $(MODULE) is not buildable.)
module_$(MODULE):
	@true
else

# -- general configuration --
O	:=o
LIBINSTALL := cp
LIBFINAL := touch
IDIR	:=src/$(MODULE)
DYNLINK_PREFIX :=$(MODULE)
BINDIR	=build/$(ARCH)/
DEVMOD	:=build/$(ARCH)/gnomedev.so
# -- end general configuration --

# use the compiler as linker, unless it has been set in the environment.
ifeq "$(origin LD)" "default"
LD	:=$(CC)
endif

# -- non-core-module settings --
ifeq ($(COREMODULE), )
SRC	:=init generated module $(SRC)
OFILES	=$(SRC) types globals fundamentals

#$(DEVMOD):
#	$(error Build the gnome module first)

else
OFILES	=$(SRC)
endif

# Run make with "H=" as an argument to show all build commands; otherwise
# just show each build target.
H	:=@
ifeq ($(H), @)
 I	=@echo $@
else
 I	:=
endif

# how to recursively call make (if required)
#submake = $(MAKE) -r --no-print-directory
#MAKEFLAGS	+=-r --no-print-directory


module_$(MODULE): $(ODIR)/$(MODULE)$(DLLEXT)

# cleanup
clean:
	$H rm -f $(addprefix $(ODIR)/,$(addsuffix .$O,$(OFILES)) $(CLEAN)) \
		$(ODIR)/$(MODULE)$(DLLEXT) \
		$(ODIR)/constants* $(ODIR)/functions* $(ODIR)/link.[ch] \
		$(ODIR)/types.* $(ODIR)/fundamentals.* \
		$(ODIR)/types.xml $(ODIR)/globals.c $(ODIR)/generated.c \
		$(ODIR)/parse-xml.log



mrproper: clean
	$H rm -f $(ODIR)/config.{h,lua,make}

size: $(addprefix $(ODIR)/, $(addsuffix .$O,$(OFILES)))
	$H size -t $(addprefix $(ODIR)/, $(addsuffix .$O,$(OFILES)))
	$H size $(ODIR)/$(MODULE)$(DLLEXT)

wc:
	$H wc $(IDIR)/*.[ch]

.PHONY:	tags wc tar install mrproper clean tests config_h doc size
.PRECIOUS: $(ODIR)/%.txt $(ODIR)/%.c

# headers for dependencies
DEP	:=include/common.h include/module.h $(ODIR)/config.h

ifeq ($(DYNLINK), 0)
LIBS	+=$(MOD_LIBS)
else
OFILES	+=link
DEP	+=$(ODIR)/link.h
endif

# configure hash files depending on the setting in build/make.state.
ifeq ($(COREMODULE), )
 OFILES +=functions constants
else
 ifeq ($(HAVE_CMPH), 1)
  OFILES	+=hash-functions hash-cmph hash-$(HASH_METHOD)
 else
  OFILES	+=hash-simple # hash-$(HASH_METHOD) $(HASH)
 endif
endif

# the target library
$(ODIR)/$(MODULE)$(DLLEXT): $(addprefix $(ODIR)/,$(addsuffix .$O,$(OFILES)))
	$I
	$H $(LD) $(LDFLAGS) -shared -o $@ $^ $(LIBS)

# if config.h changes, chances are that make-xml must be run again.
$(ODIR)/types.xml: script/make-xml.lua $(ODIR)/config.h $(ODIR)/config.lua $(IDIR)/spec.lua
	$I
	$H script/make-xml.lua "$(ODIR)"

# changed spec.lua - must reconfigure.  This may or may not change config.lua,
# but to avoid configures every time, the timestamp is updated.
$(ODIR)/config.lua: $(IDIR)/spec.lua
	$I
	$H script/configure.lua $(CONFIG_ARGS) $(MODULE)
	$H touch "$@"

$(ODIR)/%.$O: $(ODIR)/%.c
	$I
	$H ${CC} ${CFLAGS} -c -o $@ $<

$(ODIR)/%.$O: $(IDIR)/%.c $(DEP)
	$I
	$H $(CC) $(CFLAGS) -c -o $@ $<

# module.c is code required by modules to hook up with the core module and
# must therefore be compiled into each module.
$(ODIR)/module.$O: include/module.c $(DEP)
	$I
	$H $(CC) $(CFLAGS) -c -o $@ $<


# - Dependencies for modules -
$(ODIR)/init.$O: $(IDIR)/init.c
$(ODIR)/constants.$O: include/lg-hash.h
$(ODIR)/functions.$O: include/lg-hash.h
$(ODIR)/types.$O: include/common.h $(ODIR)/config.h


# -- dynamic runtime linking --
linkh: $(ODIR)/link.h
$(ODIR)/link.c $(ODIR)/link.h: $(IDIR)/spec.lua script/make-link.lua \
	$(ODIR)/types.xml
	$I
	$H script/make-link.lua $(ODIR)/types.xml $(IDIR)/spec.lua \
		$(ODIR)/link.h $(ODIR)/link.c $(DYNLINK_PREFIX)_dynlink

# Generation of data from the XML file

# XXX with parallel building (-j), this runs multiple times at once!
# How can this be avoided?
$(ODIR)/functions.txt: $(ODIR)/types.xml script/parse-xml.lua \
	include/fundamental.lua $(ODIR)/config.lua $(DEVMOD) $(IDIR)/spec.lua
	$I
	$H script/parse-xml.lua "$(ODIR)/" "$<" "$(ODIR)/config.lua"

$(ODIR)/constants.txt $(ODIR)/types.c $(ODIR)/globals.c \
	$(ODIR)/fundamentals.c $(ODIR)/generated.c: $(ODIR)/functions.txt

#$(ODIR)/functions.txt $(ODIR)/constants.txt $(ODIR)/types.c \
#	$(ODIR)/globals.c $(ODIR)/fundamentals.c $(ODIR)/generated.c: \

ifeq ($(COREMODULE), )
endif

# Update the timestamp of parse-xml.lua whenever one of its parts changes.
# This in turn forces rebuilding its output.
script/parse-xml.lua: script/xml-types.lua script/xml-parser.lua \
	script/xml-output.lua script/xml-const.lua
	touch $@

# XXX unused
#$(ODIR)/_override.c: $(ODIR)/override.luac $(ODIR)/file2c
#	$I
#	$H $(ODIR)/file2c override < $< > $@
#

# -- hash generation --

$(ODIR)/%.c: $(ODIR)/%.txt $(DEVMOD)
	$I
	$H lua -lgnomedev -e 'gnomedev.generate_hash("$<", "$*", "$@")'

# -- general rules --

$(ODIR)/%.$O: $(IDIR)/%.c
	$I
	$H ${CC} ${CFLAGS} -c -o $@ $<

$(ODIR)/%.$O: $(ODIR)/%.c
	$I
	$H $(CC) $(CFLAGS) -c -o $@ $<

$(ODIR)/%.s: $(IDIR)/%.c
	$I
	$H ${CC} ${CFLAGS} -S -o $@ $<

$(ODIR)/%.c: $(IDIR)/%.c
	$I
	$H ${CC} ${CFLAGS} -E -o $@ $<

# could use -s to remove debugging info
$(ODIR)/%.luac: $(IDIR)/%.lua
	$I
	$H luac -o $@ $<

endif
endif
endif