File: rules.mk

package info (click to toggle)
ion2 20040729-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,816 kB
  • ctags: 3,434
  • sloc: ansic: 28,432; makefile: 473; sh: 230; perl: 16
file content (186 lines) | stat: -rw-r--r-- 2,797 bytes parent folder | download | duplicates (6)
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
##
## Some make rules
##

RM=$(LIBTOOL) --mode=clean rm

# Main targets
######################################

ifdef MODULE
TARGETS := $(TARGETS) $(MODULE).la
endif

ifdef LUA_SOURCES
LUA_COMPILED := $(subst .lua,.lc, $(LUA_SOURCES))
TARGETS := $(TARGETS) $(LUA_COMPILED)
TO_CLEAN := $(TO_CLEAN) $(LUA_COMPILED)
endif


ifdef SUBDIRS

all: subdirs $(TARGETS)

clean: subdirs-clean _clean

realclean: subdirs-realclean _clean _realclean

depend: subdirs-depend _depend

else

all: $(TARGETS)

clean: _clean

realclean: _clean _realclean

depend: _depend

endif

ifdef INSTALL_SUBDIRS

install: subdirs-install _install

else

install: _install

endif


# The rules
######################################

ifdef MAKE_EXPORTS

TO_CLEAN := $(TO_CLEAN) exports.c

EXPORTS_C = exports.c

exports.c: $(SOURCES)
	$(LUA) $(TOPDIR)/mkexports.lua -module $(MAKE_EXPORTS) -o exports.c $(SOURCES)

else # !MAKE_EXPORTS

EXPORTS_C = 

endif # !MAKE_EXPORTS

ifdef MODULE

OBJS=$(subst .c,.lo,$(SOURCES) $(EXPORTS_C))

ifneq ($(PRELOAD_MODULES),1)
PICOPT=-prefer-pic
LINKOPT=-module -avoid-version
else
PICOPT=-static -prefer-non-pic
LINKOPT=-static -module -avoid-version
endif

%.lo: %.c
	$(LIBTOOL) --mode=compile $(CC) $(PICOPT) $(CFLAGS) -c $< -o $@

$(MODULE).la: $(OBJS) $(EXT_OBJS)
	$(LIBTOOL) --mode=link $(CC) $(LINKOPT) $(LDFLAGS) \
 	-rpath $(MODULEDIR) $(OBJS) $(EXT_OBJS) -o $@

module_install:
	$(INSTALLDIR) $(MODULEDIR)
	$(LIBTOOL) --mode=install $(INSTALL) -s -m $(BIN_MODE) $(MODULE).la $(MODULEDIR)

clean_objs:
	$(RM) -f $(OBJS)

clean_target:
	$(RM) -f $(MODULE).la

else #!MODULE

ifdef SOURCES

OBJS=$(subst .c,.o,$(SOURCES) $(EXPORTS_C))

clean_objs:
	$(RM) -f $(OBJS)

else #!SOURCES

clean_objs:

endif #!SOURCES


%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

clean_target:
	$(RM) -f $(TARGETS)

endif #!MODULE

_clean: clean_objs
	$(RM) -f core $(DEPEND_FILE) $(TO_CLEAN)

_realclean: clean_target
	$(RM) -f $(TO_REALCLEAN)

# Lua rules
######################################

%.lc: %.lua
	$(LUAC) -o $@ $<


# Dependencies
######################################

ifdef SOURCES

ifdef MODULE

_depend:
	$(MAKE_DEPEND_MOD)
	
else

_depend:
	$(MAKE_DEPEND)

endif

else #!SOURCES

_depend:
	
endif #!SOURCES


# Subdirectories
######################################

subdirs:
	set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i; done

subdirs-depend:
	set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i depend; done

subdirs-clean:
	set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done

subdirs-realclean:
	set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i realclean; done

subdirs-install:
	set -e; for i in $(INSTALL_SUBDIRS); do $(MAKE) -C $$i install; done


# Dependencies
######################################

ifeq ($(DEPEND_FILE),$(wildcard $(DEPEND_FILE)))
include $(DEPEND_FILE)
endif