forked from OpenSIPS/opensips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.rules
201 lines (164 loc) · 5.53 KB
/
Makefile.rules
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
#
#
# common Makefile rules, included by main Makefile & the modules
#
#
# Uses: NAME, ALLDEP, CC, CFLAGS, DEFS, LIBS, MKDEP, auto_gen, depends, objs,
# extra_objs, misclibs, static_modules, static_modules_path
# (all this must be defined previously!, see Makefile.defs & Makefile)
#
#directory lists for clean rules
all_modules=$(shell [ -d modules -a -d utils ] && ls modules)
all_utils=$(shell [ -d modules -a -d utils ] && ls utils)
builtin_modules=$(shell [ -d net ] && ls net | grep ^proto_ )
all_nostatic_modules=$(filter-out $(addprefix modules/, $(static_modules)), \
$(wildcard modules/*))
all_modules:=$(addprefix modules/, $(all_modules))
all_modules:=$(addprefix net/, $(builtin_modules)) $(all_modules)
all_utils:=$(addprefix utils/, $(all_utils))
all_misclibs=digest_auth reg
all_misclibs:=$(addprefix lib/, $(all_misclibs))
#implicit rules
%.o: %.c $(ALLDEP) $(DEPS)
ifeq (,$(FASTER))
@echo "Compiling $<"
endif
$(Q)$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
%.d: %.c $(ALLDEP)
@set -e; $(MKDEP) $(DEFS) $< \
| sed 's#\(\($*D)\)\?$(*F)\)\.o[ :]*#$*.o $@ : #g' > $@; \
[ -s $@ ] || rm -f $@
# normal rules
$(NAME): $(objs) $(extra_objs) $(misclibs) $(ALLDEP)
ifeq (,$(FASTER))
@echo "Linking $(NAME)"
endif
$(Q)$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(misclibs) $(LIBS) $(TWEAK_LIBS) -o $(NAME)
main.o: main.c $(ALLDEP) $(NEWREVISION)
ifeq (,$(FASTER))
@echo "Compiling $<"
endif
$(Q)$(CC) $(CFLAGS) $(DEFS) $(TWEAK_DEFS) -c $< -o $@
.PHONY: all
all: $(NAME) modules
.PHONY: dep
dep: $(depends)
.PHONY: static
static: $(objs)
.PHONY: generate-mem-stats
generate-mem-stats: mem/mem_stats.h mem/mem_stats.c
Makefile.conf: Makefile.conf.template
@if ! [ -e "$@" ]; then \
echo Creating new $@; \
cp $< $@; \
fi
# no need to generate mem/mem_stats.c from anywhere else
mem/mem_stats.c: mem/mem_stats.h
@find modules/ -maxdepth 2 -name "[Mm]akefile" -exec grep "NAME\s*=" {} \; \
| sort -u | awk 'BEGIN { FS = "[=\\. ]"; \
print "/* This file is auto-generated by running \"make generate-mem-stats\" */"; \
print "/* You should NOT edit this file manually */"; \
print "#ifdef SHM_EXTRA_STATS"; \
print "unsigned long core_mem_stat; /* core statistic */"; } \
{ print "unsigned long " $$(NF-1) "_mem_stat;" } \
END { print "#endif /* SHM_EXTRA_STATS */"; fflush()}' > $@
.PHONY: remove-mem-stats
remove-mem-stats:
-@rm -f $(MEM_STATS_HDR)
%mem_stats.h: $(REGENERATE_MEM_STATS)
@find $(dir $@)/../modules/ -maxdepth 2 -name "[Mm]akefile" -exec grep "NAME\s*=" {} \; \
| sort -u | awk 'BEGIN { FS = "[=\\. ]"; \
print "/* This file is auto-generated by running \"make generate-mem-stats\" */"; \
print "/* You should NOT edit this file manually */"; \
print "#ifdef SHM_EXTRA_STATS"; \
print "#ifndef __MEM_STAT_H_"; \
print "#define __MEM_STAT_H_"; \
print "extern unsigned long core_mem_stat; /* core statistic */"; } \
{ print "extern unsigned long " $$(NF-1) "_mem_stat;" } \
END { print "#endif /* __MEM_STAT_H_ */\n#endif /* SHM_EXTRA_STATS */"; \
print "/* modules MD5: $(MODULES_MD5) */"; fflush()}' > $@
$(cfg_prefix)/$(cfg_dir):
mkdir -m 700 -p $(cfg_prefix)/$(cfg_dir)
$(bin_prefix)/$(bin_dir):
mkdir -p $(bin_prefix)/$(bin_dir)
$(modules_prefix)/$(modules_dir):
mkdir -p $(modules_prefix)/$(modules_dir)
$(doc_prefix)/$(doc_dir):
mkdir -p $(doc_prefix)/$(doc_dir)
$(man_prefix)/$(man_dir)/man8:
mkdir -p $(man_prefix)/$(man_dir)/man8
$(man_prefix)/$(man_dir)/man5:
mkdir -p $(man_prefix)/$(man_dir)/man5
$(data_prefix)/$(data_dir):
mkdir -p $(data_prefix)/$(data_dir)
.PHONY: dosetrev
dosetrev:
@echo "New $(VERSIONTYPE) revision: $(THISREVISION)"
@if [ -f "main.o" ] ; then \
rm main.o ; \
fi
@echo "$(THISREVISION)" >.$(VERSIONTYPE)revision
.PHONY: docbook-clean
docbook-clean:
-@for r in $(modules) $(static_modules_path) "" ; do \
if [ -d "$$r" ]; then \
if [ -d "$$r"/doc ]; then \
rm -f "$$r"/doc/*.txt ; \
rm -f "$$r"/doc/*.html ; \
rm -f "$$r"/doc/*.pdf ; \
fi ; \
fi ; \
done
.PHONY: dbschema-docbook-clean
dbschema-docbook-clean:
-@if [ -d doc/database ] ; then \
rm -f doc/database/*.txt ; \
rm -f doc/database/*.html ; \
rm -f doc/database/*.pdf ; \
$(MAKE) -C db/schema docbook_clean; \
fi
.PHONY: clean
clean: docbook-clean dbschema-docbook-clean
-@rm -f $(objs) $(NAME) $(objs:.o=.il) 2>/dev/null
-@for r in $(all_modules) $(all_utils) $(all_misclibs); do \
if [ -d "$$r" -a -f "$$r/Makefile" ]; then \
$(MAKE) -C $$r clean ; \
fi ; \
done
.PHONY: proper
.PHONY: distclean
.PHONY: realclean
proper realclean distclean: clean
-@rm -f $(depends) $(deps_gen) $(auto_gen) 2>/dev/null
-@rm -f cfg.tab.h 2>/dev/null
-@for r in $(all_nostatic_modules) $(all_misclibs) ; do \
if [ -d "$$r" -a -f "$$r/Makefile" ]; then \
$(MAKE) -C $$r proper ; \
fi ; \
done
-@if [ -d menuconfig ]; then $(MAKE) -C menuconfig proper; fi
-@if [ -d utils/db_berkeley ]; then $(MAKE) -C utils/db_berkeley proper; fi
-@if [ -d utils/db_oracle ]; then $(MAKE) -C utils/db_oracle proper; fi
.PHONY: maintainer-clean
maintainer-clean: distclean
-rm -f TAGS tags *.dbg .*.swp
-@for r in $(modules) "" ; do \
if [ -d "$$r" ]; then \
$(MAKE) -C $$r maintainer-clean; \
fi ; \
done
.PHONY: mantainer-clean
mantainer-clean:
@printf "\nERROR: Please use 'maintainer-clean', not 'mantainer-clean'\n\n" >&2
@false
.PHONY: install_module_custom install_module_dbschema
.PHONY: TAGS
TAGS:
$(MKTAGS)
ifeq (,$(MAKECMDGOALS))
-include $(depends)
endif
ifneq (,$(filter-out clean proper distclean realclean maintainer-clean TAGS \
test tar modules, $(MAKECMDGOALS)))
-include $(depends)
endif