8786cc87980b545437dd32ac66b9f453d9578606
[sip-router] / Makefile
1 # $Id$
2 #
3 # sip_router makefile
4 #
5 # WARNING: requires gmake (GNU Make)
6 #  Arch supported: Linux, FreeBSD, SunOS (tested on Solaris 8), OpenBSD (3.2),
7 #  NetBSD (1.6).
8 #
9 #  History:
10 #  --------
11 #              created by andrei
12 #  2003-02-24  make install no longer overwrites ser.cfg  - patch provided
13 #               by Maxim Sobolev   <sobomax@FreeBSD.org> and 
14 #                  Tomas Bj√∂rklund <tomas@webservices.se>
15 #  2003-03-11  PREFIX & LOCALBASE must also be exported (andrei)
16 #  2003-04-07  hacked to work with solaris install (andrei)
17 #  2003-04-17  exclude modules overwritable from env. or cmd. line,
18 #               added include_modules and skip_modules (andrei)
19 #  2003-05-30  added extra_defs & EXTRA_DEFS
20 #               Makefile.defs force-included to allow recursive make
21 #               calls -- see comment (andrei)
22 #  2003-06-02  make tar changes -- unpacks in $NAME-$RELEASE  (andrei)
23 #  2003-06-03  make install-cfg will properly replace the module path
24 #               in the cfg (re: /usr/.*lib/ser/modules)
25 #              ser.cfg.default is installed only if there is a previous
26 #               cfg. -- fixes packages containing ser.cfg.default (andrei)
27 #  2003-08-29  install-modules-doc split from install-doc, added 
28 #               install-modules-all, removed README.cfg (andrei)
29 #              added skip_cfg_install (andrei)
30 #  2004-09-02  install-man will automatically "fix" the path of the files
31 #               referred in the man pages
32 #  2006-02-14  added utils & install-utils (andrei)
33 #  2006-03-15  added nodeb parameter for make tar (andrei)
34 #  2006-09-29  added modules-doc as target and doc_format= as make option (greger)
35 #  2006-12-09  added new group_include as make option and defined groups 
36 #               defining which modules to include. Also added new target 
37 #               print-modules that you can use to check which modules will be 
38 #               compiled (greger)
39 #  2007-01-10  added new group_include targets mysql, radius, and presence 
40 #               improved print-modules output fixed problem in include/exclude
41 #               logic when using group_include (greger)
42 #  2007-03-01  fail if a module or a required utility make fail unless 
43 #              err_fail=0; don't try to make modules with no Makefiles (andrei)
44 #  2007-03-16  moved the exports to Makefile.defs (andrei)
45 #  2007-03-29  install-modules changed to use make -C modpath install (andrei)
46 #  2007-05-04  "if ! foo" not supported in standard sh, switched to 
47 #                "if foo; then :; else ... ; fi" (andrei)
48 #  2008-06-23  added 2 new targets: README and man (re-generate the README
49 #              or manpages for all the modules) (andrei)
50 #  2008-06-25  make cfg support (use a pre-built cfg.: config.mak) (andrei)
51 #  2008-06-28  added clean-all, proper-all, install-modules-man and error 
52 #               checks for install-utils & doc (andrei)
53 #  2008-07-01  split module list from config.mak into modules.lst so that
54 #               the modules list can be changed without rebuilding the whole
55 #               ser (andrei)
56 #              added cfg-defs, new target that only rebuilds config.mak
57 #  2009-03-10  replaced DEFS with C_DEFS (DEFS are now used only for
58 #              "temporary" defines inside modules or libs) (andrei)
59 #  2009-03-27  multiple modules directory support, see modules_dirs (andrei)
60 #  2009-04-02  workaround for export not supported in gnu make 3.80
61 #               target specific variables: use mk_params for each
62 #               $(MAKE) invocation (andrei)
63 #  2009-04-22  don't rebuild config.mak or modules.lst if not needed
64 #              (e.g. on clean) (andrei)
65 #  2009-06-24  auto-generate autover.h, containing the REPO_VER macro, defined
66 #               to the top git commit sha (if git is found) (andrei)
67 #
68
69 # check make version
70 # everything works with 3.80, except evals inside ifeq/endif
71 # (see https://savannah.gnu.org/bugs/index.php?func=detailitem&item_id=1516).
72 # recommended 3.81
73 req_ver=3.81
74 # the check below works for version number of the type x.yy or x.yy.z*
75 # (from the GNU Make Cookbook)
76 ifeq (,$(filter $(req_ver),$(firstword $(sort $(MAKE_VERSION) $(req_ver)))))
77 $(error make version $(MAKE_VERSION) not supported, use at least $(req_ver))
78 endif
79
80
81 auto_gen=lex.yy.c cfg.tab.c #lexx, yacc etc
82 auto_gen_others=cfg.tab.h # auto generated, non-c
83 auto_gen_keep=autover.h # auto generated, should be included in archives
84
85 COREPATH=.
86 #include  source related defs
87 include Makefile.sources
88 #include special targets lists
89 include Makefile.targets
90
91 # whether or not the entire build process should fail if building a module or
92 #  an utility fails
93 err_fail?=1
94
95 # whether or not to install $(MAIN_NAME).cfg or just $(MAIN_NAME).cfg.default
96 # ($(MAIN_NAME).cfg will never be overwritten by make install, this is usefull
97 #  when creating packages)
98 skip_cfg_install?=
99
100 #extra modules to exclude
101 skip_modules?=
102
103 # see Makefile.dirs for the directories used for the modules
104 include Makefile.dirs
105
106 # Set document format
107 # Alternatives are txt, html, xhtml, and pdf (see Makefile.doc)
108 doc_format?=html
109
110 # don't force modules.lst generation if the makefile goals do not
111 # require it (but if present use it)
112 ifeq (,$(strip $(filter-out $(clean_targets) $(aux_targets),$(MAKECMDGOALS))))
113 ifneq (,$(strip $(wildcard modules.lst)))
114 -include modules.lst
115 endif
116 else
117 include modules.lst
118 endif # ifneq (,$(strip $(filter-out ...,$(MAKECMDGOALS))))
119
120 #if called with group_include, ignore the modules from modules.lst
121 ifneq ($(group_include),)
122         include_modules=
123         exclude_modules=
124         modules_configured:=0
125 endif
126
127 # get the groups of modules to compile
128 include Makefile.groups
129
130 # - automatically build the list of excluded modules
131 # if not set on the cmd. line, env or in the modules.lst (cfg_group_include)
132 # exclude the below modules.
133 ifneq ($(group_include)$(cfg_group_include),)
134         # For group_include, default all modules are excluded except those in
135         # include_modules
136         exclude_modules?=
137 else
138         # Old defaults for backwards compatibility
139         # excluded because they depend on external libraries
140 ifeq ($(origin exclude_modules), undefined)
141         exclude_modules:= $(sort \
142                                 $(filter-out $(module_group_default), $(mod_list_all)))
143 endif
144 endif
145
146 # always add skip_modules list - it is done now in modules.lst (dcm)
147 # override exclude_modules+= $(skip_modules)
148
149 # Test for the groups and add to include_modules
150 ifneq (,$(group_include))
151 $(eval override include_modules+= $(foreach grp, $(group_include), \
152                                                                                 $(module_group_$(grp)) ))
153 endif
154
155 ALLDEP=config.mak Makefile Makefile.dirs Makefile.sources Makefile.rules
156
157 #include general defs (like CC, CFLAGS  a.s.o)
158 # hack to force makefile.defs re-inclusion (needed when make calls itself with
159 # other options -- e.g. make bin)
160 #makefile_defs=0
161 #C_DEFS:=
162
163
164 # try saved cfg, unless we are in the process of building it or if we're doing
165 # a clean
166 ifeq (,$(strip \
167         $(filter config.mak config cfg cfg-defs $(clean_targets),$(MAKECMDGOALS))))
168 include config.mak
169 ifeq ($(makefile_defs),1)
170 ifeq ($(quiet),verbose)
171 $(info config.mak loaded)
172 endif # verbose
173 export makefile_defs
174 # config_make valid & used
175 config_mak=1
176 ifeq ($(MAIN_NAME),)
177 $(error "bad config.mak, try re-running make cfg")
178 endif
179 endif
180 else # config.mak doesn't need to be used
181 ifneq (,$(filter cfg config cfg-defs,$(word 1,$(MAKECMDGOALS))))
182 # needed here to avoid starting a config submake 
183 # (e.g. rm -f config.mak; make config.mak), which would either require 
184 # double Makefile.defs defines execution (suboptimal), would loose
185 # $(value ...) expansion or would cause some warning (if Makefile.defs exec. 
186 # is skipped in the "main" makefile invocation).
187 $(shell rm -rf config.mak)
188 config_mak=0
189 makefile_defs=0
190 exported_vars=0
191 else
192 # config.mak not strictly needed, but try to load it if exists for $(Q)
193 config_mak=skip
194 -include config.mak
195 export makefile_defs
196 endif
197 endif
198
199
200 main_makefile=1
201 include Makefile.defs
202
203 static_modules_path=$(addprefix modules/, $(static_modules))
204 extra_sources=$(wildcard $(addsuffix /*.c, $(static_modules_path)))
205 extra_objs=$(extra_sources:.c=.o)
206
207 static_defs:= $(foreach  mod, $(static_modules), \
208                 -DSTATIC_$(shell echo $(mod) | tr [:lower:] [:upper:]) )
209
210 override extra_defs+=$(static_defs) $(EXTRA_DEFS)
211 export extra_defs
212
213 # Historically, the resultant set of modules is: modules/* - exclude_modules +
214 # include_modules
215 # When group_include is used, we want: include_modules (based on group_include)
216 # - exclude_modules
217
218 ifneq ($(modules_configured),1) 
219 #modules_all=$(filter-out modules/CVS,$(wildcard modules/*))
220
221 # create modules*_all vars
222 $(foreach mods,$(modules_dirs),$(eval \
223         $(mods)_all=$$(filter-out $(mods)/CVS,$$(wildcard $(mods)/*))))
224 #debugging
225 #$(foreach mods,$(modules_dirs),$(info "$(mods)_all=$($(mods)_all)"))
226
227 ifneq ($(group_include),)
228 $(foreach mods,$(modules_dirs),$(eval \
229         $(mods)=$$(filter-out $$(addprefix $(mods)/, \
230                         $$(exclude_modules) $$(static_modules)), \
231                         $$(addprefix $(mods)/, $$(include_modules) )) ))
232 else    
233         # Standard, old resultant set
234 $(foreach mods,$(modules_dirs),$(eval \
235         $(mods)_noinc=$$(filter-out $$(addprefix $(mods)/, \
236                         $$(exclude_modules) $$(static_modules)), $$($(mods)_all)) \
237 ))
238 $(foreach mods,$(modules_dirs),$(eval \
239         $(mods)=$$(filter-out $$(modules_noinc), \
240                         $$(addprefix $(mods)/, $$(include_modules) )) $$($(mods)_noinc) \
241 ))
242 endif # ifneq($(group_include),)
243 endif # ifneq($(modules_configured),1)
244
245 $(foreach mods,$(modules_dirs),$(eval \
246         $(mods)_names=$$(shell echo $$($(mods))| \
247                                 sed -e "s/$(mods)"'\/\([^/ ]*\)\/*/\1.so/g' ) \
248 ))
249 $(foreach mods,$(modules_dirs),$(eval \
250         $(mods)_basenames:=$$(shell echo $$($(mods))| \
251                                 sed -e "s/$(mods)"'\/\([^/ ]*\)\/*/\1/g' ) \
252 ))
253
254 # all modules from all the $(modules_dirs)
255 all_modules_lst=$(foreach mods,$(modules_dirs), $($(mods)_all))
256
257 # compile modules list (all the compiled mods from  $(modules_dirs))
258 cmodules=$(foreach mods,$(modules_dirs), $($(mods)))
259
260 #modules_names=$(patsubst modules/%, %.so, $(modules))
261 #modules_full_path=$(join  $(modules), $(addprefix /, $(modules_names)))
262
263
264
265 # list of utils directories that should be compiled by make utils
266 C_COMPILE_UTILS=        utils/sercmd
267 # list of binaries that should be installed alongside
268 # (they should be created after make utils, see C_COMPILE_UTILS)
269 C_INSTALL_BIN=  # sercmd is now installed by ctl
270
271 # which utils know to install themselves and should be installed
272 # along the core (list of utils directories)
273 ifeq ($(FLAVOUR),kamailio)
274 C_INSTALL_UTILS= utils/kamctl
275 else
276 C_INSTALL_UTILS=
277 endif
278 # list of scripts that should be installed along the core 
279 # (here a script is something that doesn't have a Makefile)
280 C_INSTALL_SCRIPTS=
281 # list of extra configs that should be installed along the core
282 # Note: all the paths of the form /usr/*lib/$(CFG_NAME)/<module_dir>
283 # will be updated to the directory where the modules will be installed.
284 C_INSTALL_CFGS=
285 # list of files that should be installed in the arch-independent 
286 # directory (by default /usr/local/share/$(MAIN_NAME)))
287 C_INSTALL_SHARE=
288
289
290
291
292 NAME=$(MAIN_NAME)
293
294 tar_name=$(NAME)-$(RELEASE)_src
295
296 tar_extra_args+=$(addprefix --exclude=$(notdir $(CURDIR))/, \
297                                         $(auto_gen) $(auto_gen_others))
298 ifeq ($(CORE_TLS), 1)
299         tar_extra_args+=
300 else
301         tar_extra_args+=--exclude=$(notdir $(CURDIR))/tls/* 
302 endif
303
304 ifneq ($(nodeb),)
305         tar_extra_args+=--exclude=$(notdir $(CURDIR))/debian 
306         tar_name:=$(tar_name)_nodeb
307 endif
308
309 # sanity checks
310 ifneq ($(TLS),)
311         $(warning "make TLS option is obsoleted, try TLS_HOOKS or CORE_TLS")
312 endif
313
314 # include the common rules
315 include Makefile.rules
316
317 #extra targets 
318
319 $(NAME): $(extra_objs) # static_modules
320
321 lex.yy.c: cfg.lex cfg.tab.h $(ALLDEP)
322         $(LEX) $<
323
324 cfg.tab.c cfg.tab.h: cfg.y  $(ALLDEP)
325         $(YACC) $(YACC_FLAGS) $<
326
327 nullstring=
328 space=$(nullstring) $(nullstring)
329
330 modules_search_path=$(subst $(space),:,$(strip\
331                                                 $(foreach m,$(modules_dirs),$($(m)_target))))
332                 #                               $(addprefix $(modules_target),$(modules_dirs))))
333
334 # special depends for main.o
335 main.o: DEFS+=-DMODS_DIR='"$(modules_search_path)"'
336
337
338 #special depends for ver.c
339 ver.d ver.o: autover.h
340
341 include Makefile.shared
342
343 ifeq ($(config_mak),1)
344
345 include Makefile.cfg
346
347 # fix basedir path (relative -> absolute)
348 ifneq (,$(basedir))
349 ifeq (,$(filter /%, $(basedir)))
350 override basedir:=$(CURDIR)/$(basedir)
351 # remove basedir from command line overrides
352 MAKEOVERRIDES:=$(filter-out basedir=%,$ $(MAKEOVERRIDES))
353 endif # (,$(filter /%, $(basedir)))
354 endif # (,$(basedir))
355
356 else ifneq ($(config_mak),skip)
357
358 config.mak: Makefile.defs Makefile.groups
359         @echo making config...
360         @echo "# this file is autogenerated by make cfg" >$@
361         @$(call mapf2,cfg_save_var,saved_fixed_vars,$(@))
362         @$(call mapf2,cfg_save_var2,saved_chg_vars,$(@))
363         @echo "override makefile_defs:=1" >>$@
364         @echo "C_DEFS:=\$$(filter-out \$$(DEFS_RM) \$$(extra_defs),\$$(C_DEFS))" \
365                                         "\$$(extra_defs)"  >>$@
366         @echo "CFLAGS:=\$$(filter-out \$$(CFLAGS_RM) \$$(CC_EXTRA_OPTS)," \
367                                                 "\$$(CFLAGS)) \$$(CC_EXTRA_OPTS)" >>$@
368
369 endif # ifeq ($(config_mak),1)
370
371 modules.lst: Makefile.groups
372         @echo  saving modules list...
373         @echo "# this file is autogenerated by make modules-cfg" >$@
374         @echo >>$@
375         @echo "# the list of sub-directories with modules" >>$@
376         @echo "modules_dirs:=$(modules_dirs)" >>$@
377         @echo >>$@
378         @echo "# the list of module groups to compile" >>$@
379         @echo "cfg_group_include=$(group_include)" >>$@
380         @echo >>$@
381         @echo "# the list of extra modules to compile" >>$@
382         @$(call cfg_save_var2,include_modules,$@)
383         @echo >>$@
384         @echo "# the list of static modules" >>$@
385         @$(call cfg_save_var2,static_modules,$@)
386         @echo >>$@
387         @echo "# the list of modules to skip from compile list" >>$@
388         @$(call cfg_save_var2,skip_modules,$@)
389         @echo >>$@
390         @echo "# the list of modules to exclude from compile list" >>$@
391         @$(call cfg_save_var3,exclude_modules,skip_modules,$@)
392         @echo >>$@
393         @$(foreach mods,$(modules_dirs), \
394                 $(call cfg_save_var2,$(mods)_all,$@))
395         @$(foreach mods,$(modules_dirs), \
396                 $(call cfg_save_var2,$(mods)_noinc,$@))
397         @$(foreach mods,$(modules_dirs), \
398                 $(call cfg_save_var2,$(mods),$@))
399         @echo "modules_configured:=1" >>$@
400
401
402 .PHONY: cfg config cfg-defs
403 cfg-defs: config.mak
404
405 cfg config: cfg-defs modules-cfg
406
407 .PHONY: modules-cfg modules-list modules-lst
408 modules-cfg modules-list modules-lst:
409         rm -f modules.lst
410         $(MAKE) modules.lst
411
412 ifneq ($(wildcard .git),)
413 # if .git/ exists
414 repo_ver=$(shell  RV=`git rev-parse --verify --short=6 HEAD 2>/dev/null`;\
415                                         [ -n "$$RV" ] && \
416                                         test -n "`git update-index --refresh --unmerged >/dev/null\
417                                                         ; git diff-index --name-only HEAD 2>/dev/null | \
418                                                                 grep -v Makefile`" &&\
419                                                 RV="$$RV"-dirty; echo "$$RV")
420 repo_hash=$(subst -dirty,,$(repo_ver))
421 repo_state=$(subst %-dirty,dirty,$(findstring -dirty,$(repo_ver)))
422 autover_h_dep=.git $(filter-out $(auto_gen), $(sources)) cfg.y cfg.lex Makefile
423 else
424 # else if .git/ does not exist
425 repo_ver=
426 repo_hash="unknown"
427 repo_state=
428 autover_h_dep=
429 endif
430
431
432 autover.h: $(autover_h_dep)
433         @echo  "generating autover.h ..."
434         @echo "/* this file is autogenerated by make autover.h" >$@
435         @echo " * DO NOT EDIT IT" >>$@
436         @echo " */" >>$@
437         @echo "" >>$@
438         @echo "#define REPO_VER \"$(repo_ver)\"" >>$@
439         @echo "#define REPO_HASH \"$(repo_hash)\"" >>$@
440         @echo "#define REPO_STATE \"$(repo_state)\"" >>$@
441
442 .PHONY: all
443 all: $(NAME) every-module
444
445 .PHONY: print-modules
446 print-modules:
447         @echo The following modules were chosen to be included: \
448                 $(include_modules) ; \
449         echo ---------------------------------------------------------- ; \
450         echo The following modules will be excluded: $(exclude_modules) ; \
451         echo ---------------------------------------------------------- ; \
452         echo The following modules will be made; \
453         $(foreach mods,$(modules_dirs), \
454                 echo $(mods)/: $($(mods)_basenames) ; ) \
455         #echo DBG: The following modules will be made: $(modules_basenames) ; \
456
457
458 # modules templates (instantiated based on modules_dirs contents)
459 define MODULES_RULES_template
460
461 $(1)_dst=$(modules_prefix)/$(modules_dir)$(1)
462 $(1)_target=$(prefix)/$(modules_dir)$(1)
463
464 .PHONY: $(1)
465 $(1): modules.lst
466         @$(foreach r,$($(1)),$(call module_make,$(r),$(mk_params)))
467
468 .PHONY: $(1)-doc
469 $(1)-doc: modules.lst
470         +@for r in $($(1)) "" ; do \
471                 if [ -n "$$$$r" -a -r "$$$$r/Makefile" ]; then \
472                         $(call oecho, "" ;) \
473                         $(call oecho, "" ;) \
474                         $(MAKE) -C $$$$r/doc $(doc_format) $$(mk_params); \
475                 fi ; \
476         done
477
478 .PHONY: $(1)-readme
479
480 $(1)-readme: modules.lst
481         -+@for r in $($(1)) "" ; do \
482                 if [ -n "$$$$r" -a -r "$$$$r/Makefile" ]; then \
483                         $(call oecho, "" ;) \
484                         $(call oecho, "" ;) \
485                         if  $(MAKE) -C $$$$r $$(mk_params) README || [ ${err_fail} != 1 ];\
486                         then \
487                                 :; \
488                         else \
489                                 exit 1; \
490                         fi ; \
491                 fi ; \
492         done; true
493
494 .PHONY: $(1)-man
495 $(1)-man: modules.lst
496         -+@for r in $($(1)_basenames) "" ; do \
497                 if [ -n "$$$$r" -a -r $(1)/"$$$$r/Makefile" -a \
498                          -r $(1)/"$$$$r/$$$$r.xml" ]; then \
499                         $(call oecho, "" ;) \
500                         $(call oecho, "" ;) \
501                         if  $(MAKE) -C $(1)/"$$$$r" $$(mk_params) man || \
502                                 [ ${err_fail} != 1 ] ;\
503                         then \
504                                 :; \
505                         else \
506                                 exit 1; \
507                         fi ; \
508                 fi ; \
509         done; true
510
511 .PHONY: install-$(1)
512
513 install-$(1): modules.lst $$($(1)_dst)
514         +@for r in $($(1)) "" ; do \
515                 if [ -n "$$$$r" -a -r "$$$$r/Makefile" ]; then \
516                         $(call oecho, "" ;) \
517                         $(call oecho, "" ;) \
518                         if  $(MAKE) -C $$$$r install mods_dst=$$($(1)_dst) $$(mk_params) \
519                                 || [ ${err_fail} != 1 ] ; then \
520                                 :; \
521                         else \
522                                 exit 1; \
523                         fi ; \
524                 fi ; \
525         done; true
526
527
528 .PHONY: install-$(1)-doc
529
530 install-$(1)-doc: modules.lst $(doc_prefix)/$(doc_dir)$(1)
531         @for r in $($(1)_basenames) "" ; do \
532                 if [ -n "$$$$r" -a -r $(1)/"$$$$r/Makefile" ]; then \
533                         if [ -f $(1)/"$$$$r"/README ]; then \
534                                 $$(call try_err,\
535                                         $(INSTALL_TOUCH) $(doc_prefix)/$(doc_dir)$(1)/README ); \
536                                 $$(call try_err,\
537                                         $(INSTALL_DOC)  $(1)/"$$$$r"/README  \
538                                                                         $(doc_prefix)/$(doc_dir)$(1)/README ); \
539                                 $$(call try_err,\
540                                         mv -f $(doc_prefix)/$(doc_dir)$(1)/README \
541                                                         $(doc_prefix)/$(doc_dir)$(1)/README."$$$$r" ); \
542                         fi ; \
543                 fi ; \
544         done; true
545
546 .PHONY: install-$(1)-man
547
548 install-$(1)-man: $(1)-man $(man_prefix)/$(man_dir)/man7
549         @for r in $($(1)_basenames) "" ; do \
550                 if [ -n "$$$$r" -a -r $(1)/"$$$$r/Makefile" ]; then \
551                         if [ -f $(1)/"$$$$r"/"$$$$r".7 ]; then \
552                                 $$(call try_err,\
553                                   $(INSTALL_TOUCH) $(man_prefix)/$(man_dir)/man7/"$$$$r".7 );\
554                                 $$(call try_err,\
555                                         $(INSTALL_MAN)  $(1)/"$$$$r"/"$$$$r".7  \
556                                                                         $(man_prefix)/$(man_dir)/man7 ); \
557                         fi ; \
558                 fi ; \
559         done; true
560
561
562 $(modules_prefix)/$(modules_dir)$(1):
563                 mkdir -p $$(@)
564
565 $(doc_prefix)/$(doc_dir)$(1):
566                 mkdir -p $$(@)
567
568
569 endef
570
571 # instantiate the template
572 $(foreach mods,$(modules_dirs),$(eval $(call MODULES_RULES_template,$(mods))))
573
574 #$(foreach mods,$(modules_dirs),$(eval  $(info DUMP: $(call MODULES_RULES_template,$(mods)))))
575
576 # build all the modules
577 modules-all every-module: $(modules_dirs)
578
579 $(extra_objs):
580         @echo "Extra objs: $(extra_objs)" 
581         @for r in $(static_modules_path) "" ; do \
582                 if [ -n "$$r" -a -r "$$r/Makefile"  ]; then \
583                         $(call oecho, "" ;) \
584                         $(call oecho, "Making static module $r" ;) \
585                         if $(MAKE) -C $$r static $(mk_params) ; then  \
586                                 :; \
587                         else \
588                                 exit 1; \
589                         fi ;  \
590                 fi ; \
591         done
592
593 .PHONY: utils
594 utils:
595         @for r in $(C_COMPILE_UTILS) "" ; do \
596                 if [ -n "$$r" ]; then \
597                         $(call oecho, "" ;) \
598                         $(call oecho, "" ;) \
599                         if  $(MAKE) -C $$r $(mk_params) || [ ${err_fail} != 1 ] ; \
600                         then \
601                                 :; \
602                         else \
603                                 exit 1; \
604                         fi ; \
605                 fi ; \
606         done; true
607
608
609 dbg: sip-router
610         gdb -command debug.gdb
611
612 .PHONY: makefile_vars makefile-vars
613 makefile_vars makefile-vars:
614         echo "FLAVOUR?=$(FLAVOUR)" > Makefile.vars
615
616 .PHONY: tar
617 .PHONY: dist
618
619 dist: tar
620
621 tar: makefile_vars $(auto_gen_keep)
622         $(TAR) -C .. \
623                 --exclude=$(notdir $(CURDIR))/test* \
624                 --exclude=$(notdir $(CURDIR))/tmp* \
625                 --exclude=$(notdir $(CURDIR))/debian \
626                 --exclude=$(notdir $(CURDIR))/debian/$(MAIN_NAME) \
627                 --exclude=$(notdir $(CURDIR))/debian/$(MAIN_NAME)-* \
628                 --exclude=$(notdir $(CURDIR))/$(MAIN_NAME)_tls* \
629                 --exclude=.git* \
630                 --exclude=CVS* \
631                 --exclude=.svn* \
632                 --exclude=.cvsignore \
633                 --exclude=librpath.lst \
634                 --exclude=libiname.lst \
635                 --exclude=makecfg.lst \
636                 --exclude=config.mak \
637                 --exclude=modules.lst \
638                 --exclude=*.[do] \
639                 --exclude=*.so \
640                 --exclude=*.il \
641                 --exclude=$(notdir $(CURDIR))/$(MAIN_NAME) \
642                 --exclude=*.gz \
643                 --exclude=*.bz2 \
644                 --exclude=*.tar \
645                 --exclude=*.patch \
646                 --exclude=.\#* \
647                 --exclude=*.swp \
648                 --exclude=*.swo \
649                 ${tar_extra_args} \
650                 -cf - $(notdir $(CURDIR)) | \
651                         (mkdir -p tmp/_tar1; mkdir -p tmp/_tar2 ; \
652                             cd tmp/_tar1; $(TAR) -xf - ) && \
653                             mv tmp/_tar1/$(notdir $(CURDIR)) \
654                                tmp/_tar2/"$(NAME)-$(RELEASE)" && \
655                             (cd tmp/_tar2 && $(TAR) \
656                                             -zcf ../../"$(tar_name)".tar.gz \
657                                                        "$(NAME)-$(RELEASE)" ) ; \
658                             rm -rf tmp/_tar1; rm -rf tmp/_tar2
659
660 # binary dist. tar.gz
661 .PHONY: bin
662 bin:
663         mkdir -p tmp/$(MAIN_NAME)/usr/local
664         $(MAKE) install basedir=$(CURDIR)/tmp/$(MAIN_NAME) $(mk_params)
665         $(TAR) -C tmp/$(MAIN_NAME)/ -zcf ../$(NAME)-$(RELEASE)_$(OS)_$(ARCH).tar.gz .
666         rm -rf tmp/$(MAIN_NAME)
667
668 .PHONY: deb
669 deb:
670         -@if [ -d debian ]; then \
671                 dpkg-buildpackage -rfakeroot -tc; \
672                 rm debian; \
673         else \
674                 ln -s pkg/$(MAIN_NAME)/deb/debian debian; \
675                 dpkg-buildpackage -rfakeroot -tc; \
676                 rm debian; \
677         fi
678
679 .PHONY: deb-stable
680 deb-stable:
681         -@if [ -d debian ]; then \
682                 dpkg-buildpackage -rfakeroot -tc; \
683                 rm debian; \
684         else \
685                 ln -s pkg/$(MAIN_NAME)/deb/wheezy debian; \
686                 dpkg-buildpackage -rfakeroot -tc; \
687                 rm debian; \
688         fi
689
690 .PHONY: sunpkg
691 sunpkg:
692         mkdir -p tmp/$(MAIN_NAME)
693         mkdir -p tmp/$(MAIN_NAME)_sun_pkg
694         $(MAKE) install basedir=$(CURDIR)/tmp/$(MAIN_NAME) \
695                         prefix=/usr/local $(mk_params)
696         (cd pkg/$(MAIN_NAME)/solaris; \
697         pkgmk -r ../../tmp/$(MAIN_NAME)/usr/local -o -d ../../tmp/$(MAIN_NAME)_sun_pkg/ -v "$(RELEASE)" ;\
698         cd ../..)
699         cat /dev/null > ../$(NAME)-$(RELEASE)-$(OS)-$(ARCH)-local
700         pkgtrans -s tmp/$(MAIN_NAME)_sun_pkg/ ../$(NAME)-$(RELEASE)-$(OS)-$(ARCH)-local \
701                 IPTEL$(MAIN_NAME)
702         gzip -9 ../$(NAME)-$(RELEASE)-$(OS)-$(ARCH)-local
703         rm -rf tmp/$(MAIN_NAME)
704         rm -rf tmp/$(MAIN_NAME)_sun_pkg
705
706
707 .PHONY: install
708 install: mk_params="compile_for_install=yes"
709 install: install-bin install-every-module install-cfg \
710         install-doc install-man install-utils install-share
711
712 .PHONY: dbinstall
713 dbinstall:
714         -@echo "Initializing $(MAIN_NAME) database"
715         scripts/mysql/$(SCR_NAME)_mysql.sh create
716         -@echo "Done"
717
718 .PHONY: README
719 README: $(foreach mods,$(modules_dirs),$(mods)-readme)
720
721 .PHONY: man
722 man: $(foreach mods,$(modules_dirs),$(mods)-man)
723
724 mk-install_dirs: $(cfg_prefix)/$(cfg_dir) $(bin_prefix)/$(bin_dir) \
725                         $(modules_prefix)/$(modules_dir) $(doc_prefix)/$(doc_dir) \
726                         $(man_prefix)/$(man_dir)/man8 $(man_prefix)/$(man_dir)/man5 \
727                         $(share_prefix)/$(share_dir) \
728                         $(foreach mods,$(modules_dirs),\
729                                 $(modules_prefix)/$(modules_dir)$(mods) \
730                                 $(doc_prefix)/$(doc_dir)$(mods) )
731
732 $(cfg_prefix)/$(cfg_dir): 
733                 mkdir -p $(cfg_prefix)/$(cfg_dir)
734
735 $(bin_prefix)/$(bin_dir):
736                 mkdir -p $(bin_prefix)/$(bin_dir)
737
738 $(share_prefix)/$(share_dir):
739                 mkdir -p $(share_prefix)/$(share_dir)
740
741 $(modules_prefix)/$(modules_dir):
742                 mkdir -p $(modules_prefix)/$(modules_dir)
743
744 $(doc_prefix)/$(doc_dir):
745                 mkdir -p $(doc_prefix)/$(doc_dir)
746
747 $(man_prefix)/$(man_dir)/man8:
748                 mkdir -p $(man_prefix)/$(man_dir)/man8
749
750 $(man_prefix)/$(man_dir)/man7:
751                 mkdir -p $(man_prefix)/$(man_dir)/man7
752
753 $(man_prefix)/$(man_dir)/man5:
754                 mkdir -p $(man_prefix)/$(man_dir)/man5
755
756 # note: sed with POSIX.1 regex doesn't support |, + or ? (darwin, solaris ...) 
757 install-cfg: $(cfg_prefix)/$(cfg_dir)
758         @if [ -f etc/$(CFG_NAME).cfg ]; then \
759                         sed $(foreach m,$(modules_dirs),\
760                                         -e "s#/usr/[^:]*lib/$(CFG_NAME)/$(m)\([:/\"]\)#$($(m)_target)\1#g") \
761                                         -e "s#/usr/local/etc/$(CFG_NAME)/#$(cfg_target)#g" \
762                                 < etc/$(CFG_NAME).cfg \
763                                 > $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME).cfg.sample; \
764                         chmod 644 $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME).cfg.sample; \
765                         if [ -z "${skip_cfg_install}" -a \
766                                         ! -f $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME).cfg ]; then \
767                                 mv -f $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME).cfg.sample \
768                                         $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME).cfg; \
769                         fi; \
770                 fi
771         @if [ -f etc/$(CFG_NAME)-basic.cfg ]; then \
772                         sed $(foreach m,$(modules_dirs),\
773                                         -e "s#/usr/[^:]*lib/$(CFG_NAME)/$(m)\([:/\"]\)#$($(m)_target)\1#g") \
774                                         -e "s#/usr/local/etc/$(CFG_NAME)/#$(cfg_target)#g" \
775                                 < etc/$(CFG_NAME)-basic.cfg \
776                                 > $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-basic.cfg.sample; \
777                         chmod 644 $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-basic.cfg.sample; \
778                         if [ -z "${skip_cfg_install}" -a \
779                                         ! -f $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-basic.cfg ]; then \
780                                 mv -f $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-basic.cfg.sample \
781                                         $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-basic.cfg; \
782                         fi; \
783                 fi
784         @if [ -f etc/$(CFG_NAME)-oob.cfg ]; then \
785                         sed $(foreach m,$(modules_dirs),\
786                                         -e "s#/usr/[^:]*lib/$(CFG_NAME)/$(m)\([:/\"]\)#$($(m)_target)\1#g") \
787                                         -e "s#/usr/local/etc/$(CFG_NAME)/#$(cfg_target)#g" \
788                                 < etc/$(CFG_NAME)-oob.cfg \
789                                 > $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-advanced.cfg.sample; \
790                         chmod 644 $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-advanced.cfg.sample; \
791                         if [ -z "${skip_cfg_install}" -a \
792                                         ! -f $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-advanced.cfg ]; \
793                         then \
794                                 mv -f $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-advanced.cfg.sample \
795                                         $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-advanced.cfg; \
796                         fi; \
797                 fi
798         @# other configs
799         @for r in $(C_INSTALL_CFGS) ""; do \
800                         if [ -n "$$r" ]; then \
801                                 if [ -f "$$r" ]; then \
802                                         n=`basename "$$r"` ; \
803                                         sed $(foreach m,$(modules_dirs),\
804                                                         -e "s#/usr/[^:]*lib/$(CFG_NAME)/$(m)\([:/\"]\)#$($(m)_target)\1#g") \
805                                                 < "$$r" \
806                                                 > "$(cfg_prefix)/$(cfg_dir)$$n.sample" ; \
807                                         chmod 644 "$(cfg_prefix)/$(cfg_dir)$$n.sample" ; \
808                                         if [ -z "${skip_cfg_install}" -a \
809                                                         ! -f "$(cfg_prefix)/$(cfg_dir)$$n" ]; \
810                                         then \
811                                                 mv -f "$(cfg_prefix)/$(cfg_dir)$$n.sample" \
812                                                                 "$(cfg_prefix)/$(cfg_dir)$$n"; \
813                                         fi ; \
814                                 else \
815                                         echo "ERROR: $$r not found" ; \
816                                         if [ ${err_fail} = 1 ] ; then \
817                                                 exit 1; \
818                                         fi ; \
819                                 fi ; \
820                         fi ; \
821                         : ; done; true
822         @# radius dictionary
823         @$(INSTALL_TOUCH) $(cfg_prefix)/$(cfg_dir)/dictionary.$(CFG_NAME)
824         @$(INSTALL_CFG) etc/dictionary.$(CFG_NAME) $(cfg_prefix)/$(cfg_dir)
825         @echo "config files installed"
826
827 install-bin: $(bin_prefix)/$(bin_dir) $(NAME)
828         $(INSTALL_TOUCH) $(bin_prefix)/$(bin_dir)/$(NAME)
829         $(INSTALL_BIN) $(NAME) $(bin_prefix)/$(bin_dir)
830
831
832 install-share: $(share_prefix)/$(share_dir)
833         @for r in $(C_INSTALL_SHARE) "" ; do \
834                 if [ -n "$$r" ]; then \
835                         if [ -f "$$r" ]; then \
836                                 $(call try_err, $(INSTALL_TOUCH) \
837                                                 $(share_prefix)/$(share_dir)/`basename "$$r"` ); \
838                                 $(call try_err, \
839                                         $(INSTALL_SHARE)  "$$r"  $(share_prefix)/$(share_dir) );\
840                         else \
841                                 echo "ERROR: $$r not found" ; \
842                                 if [ ${err_fail} = 1 ] ; then \
843                                         exit 1; \
844                                 fi ; \
845                         fi ;\
846                 fi ; \
847         done; true
848
849
850 install-every-module: $(foreach mods,$(modules_dirs),install-$(mods))
851
852 install-every-module-doc: $(foreach mods,$(modules_dirs),install-$(mods)-doc)
853
854 install-every-module-man: $(foreach mods,$(modules_dirs),install-$(mods)-man)
855
856 install-utils: utils $(bin_prefix)/$(bin_dir)
857         @for r in $(C_INSTALL_BIN) "" ; do \
858                 if [ -n "$$r" ]; then \
859                         if [ -f "$$r" ]; then \
860                                 $(call try_err, $(INSTALL_TOUCH) \
861                                                 $(bin_prefix)/$(bin_dir)/`basename "$$r"` ); \
862                                 $(call try_err,\
863                                         $(INSTALL_BIN)  "$$r"  $(bin_prefix)/$(bin_dir) ); \
864                         else \
865                                 echo "ERROR: $$r not compiled" ; \
866                                 if [ ${err_fail} = 1 ] ; then \
867                                         exit 1; \
868                                 fi ; \
869                         fi ;\
870                 fi ; \
871         done; true
872         @for r in $(C_INSTALL_SCRIPTS) "" ; do \
873                 if [ -n "$$r" ]; then \
874                         if [ -f "$$r" ]; then \
875                                 $(call try_err, $(INSTALL_TOUCH) \
876                                                 $(bin_prefix)/$(bin_dir)/`basename "$$r"` ); \
877                                 $(call try_err,\
878                                         $(INSTALL_SCRIPT)  "$$r"  $(bin_prefix)/$(bin_dir) ); \
879                         else \
880                                 echo "ERROR: $$r not compiled" ; \
881                                 if [ ${err_fail} = 1 ] ; then \
882                                         exit 1; \
883                                 fi ; \
884                         fi ;\
885                 fi ; \
886         done; true
887         @for ut in $(C_INSTALL_UTILS) "" ; do \
888                 if [ -n "$$ut" ]; then \
889                         if [ -d "$$ut" ]; then \
890                                 $(call try_err, $(MAKE) -C "$${ut}" install-if-newer ) ;\
891                         fi ;\
892                 fi ; \
893         done; true
894
895
896 install-modules-all: install-every-module install-every-module-doc
897
898
899 install-doc: $(doc_prefix)/$(doc_dir) install-every-module-doc
900         $(INSTALL_TOUCH) $(doc_prefix)/$(doc_dir)/INSTALL 
901         $(INSTALL_DOC) INSTALL $(doc_prefix)/$(doc_dir)
902         $(INSTALL_TOUCH) $(doc_prefix)/$(doc_dir)/README-MODULES 
903         $(INSTALL_DOC) README-MODULES $(doc_prefix)/$(doc_dir)
904         $(INSTALL_TOUCH) $(doc_prefix)/$(doc_dir)/AUTHORS 
905         $(INSTALL_DOC) AUTHORS $(doc_prefix)/$(doc_dir)
906         $(INSTALL_TOUCH) $(doc_prefix)/$(doc_dir)/NEWS
907         $(INSTALL_DOC) NEWS $(doc_prefix)/$(doc_dir)
908         $(INSTALL_TOUCH) $(doc_prefix)/$(doc_dir)/README 
909         $(INSTALL_DOC) README $(doc_prefix)/$(doc_dir)
910
911
912 install-sr-man: $(man_prefix)/$(man_dir)/man8 $(man_prefix)/$(man_dir)/man5
913                 @sed -e "s#/etc/$(CFG_NAME)/$(CFG_NAME)\.cfg#$(cfg_target)$(MAIN_NAME).cfg#g" \
914                         -e "s#/usr/sbin/#$(bin_target)#g" \
915                         $(foreach m,$(modules_dirs),\
916                                 -e "s#/usr/lib/$(CFG_NAME)/$(m)\([^_]\)#$($(m)_target)\1#g") \
917                         -e "s#/usr/share/doc/$(CFG_NAME)/#$(doc_target)#g" \
918                         -e "s#$(SRC_NAME)#$(MAIN_NAME)#g" \
919                         < $(SRC_NAME).8 >  \
920                                                         $(man_prefix)/$(man_dir)/man8/$(MAIN_NAME).8
921                 @chmod 644  $(man_prefix)/$(man_dir)/man8/$(MAIN_NAME).8
922                 @sed -e "s#/etc/$(CFG_NAME)/$(CFG_NAME)\.cfg#$(cfg_target)$(MAIN_NAME).cfg#g" \
923                         -e "s#/usr/sbin/#$(bin_target)#g" \
924                         $(foreach m,$(modules_dirs),\
925                                 -e "s#/usr/lib/$(CFG_NAME)/$(m)\([^_]\)#$($(m)_target)\1#g") \
926                         -e "s#/usr/share/doc/$(CFG_NAME)/#$(doc_target)#g" \
927                         -e "s#$(SRC_NAME)#$(MAIN_NAME)#g" \
928                         < $(SRC_NAME).cfg.5 >  \
929                         $(man_prefix)/$(man_dir)/man5/$(MAIN_NAME).cfg.5
930                 @chmod 644  $(man_prefix)/$(man_dir)/man5/$(MAIN_NAME).cfg.5
931
932 install-man:  install-sr-man install-every-module-man
933
934
935
936 # libs cleaning targets
937 .PHONY: clean-libs
938 clean-libs:
939                         $(MAKE) -C lib clean
940
941 .PHONY: proper-libs realclean-libs distclean-libs maintainer-clean-libs
942 proper-libs realclean-libs distclean-libs maintainer-clean-libs:
943                         $(MAKE) -C lib $(patsubst %-libs,%,$@)
944
945 # utils cleaning targets
946
947 .PHONY: clean-utils
948 clean-utils:
949         @for r in $(C_COMPILE_UTILS) $(C_INSTALL_UTILS) "" ; do \
950                 if [ -d "$$r" ]; then \
951                          $(MAKE) -C "$$r" clean ; \
952                 fi ; \
953         done
954
955 .PHONY: proper-utils
956 .PHONY: distclean-utils
957 .PHONY: realclean-utils
958 .PHONY: maintainer-clean-utils
959 proper-utils realclean-utils distclean-utils maintainer-clean-utils: \
960  clean_target=$(patsubst %-utils,%,$@)
961 proper-utils realclean-utils distclean-utils maintainer-clean-utils:
962         @for r in $(C_COMPILE_UTILS) $(C_INSTALL_UTILS) "" ; do \
963                 if [ -d "$$r" ]; then \
964                          $(MAKE) -C "$$r" $(clean_target); \
965                 fi ; \
966         done
967
968 # clean extra binary names (common "flavour" names)
969 clean: clean-extra-names
970 # clean modules on make clean
971 clean: clean-modules
972 # clean utils on make clean
973 clean: clean-utils
974 # cleaning in libs always when cleaning sip-router
975 clean: clean-libs
976
977 .PHONY: clean-extra-names
978 clean-extra-names:
979         @rm -f $(filter-out $(MAIN_NAME), sip-router ser kamailio)
980
981 # proper/distclean a.s.o modules, utils and libs too
982
983 proper: clean-extra-names proper-modules proper-utils proper-libs
984 distclean: distclean-modules distclean-utils distclean-libs
985 realclean: realclean-modules realclean-utils realclean-libs
986 maintainer-clean: maintainer-clean-modules maintainer-clean-utils \
987  maintainer-clean-libs
988
989 #try to clean everything (including all the modules, even ones that are not
990 # configured/compiled normally
991 .PHONY: clean-all
992 clean-all: cmodules=$(all_modules_lst)
993 clean-all: clean
994 maintainer-clean: modules=$(modules_all)
995
996 # on make proper clean also the build config (w/o module list)
997 proper realclean distclean maintainer-clean: clean_cfg
998
999 # on maintainer clean, remove also the configured module list
1000 maintainer-clean: clean_modules_cfg clean_makefile_vars
1001
1002 .PHONY: proper-all realclean-all distclean-all
1003 proper-all realclean-all distclean-all: cmodules=$(all_modules_lst)
1004 proper-all realclean-all distclean-all: proper
1005
1006
1007 .PHONY: clean_cfg clean-cfg
1008 clean_cfg clean-cfg:
1009         rm -f config.mak
1010
1011 .PHONY: clean_modules_cfg clean-modules-cfg
1012 clean_modules_cfg clean-modules-cfg:
1013         rm -f modules.lst
1014
1015 .PHONY: clean_makefile_vars clean-makefile-vars
1016         rm -f Makefile.vars
1017
1018 # clean everything generated - shortcut on maintainer-clean
1019 .PHONY: pure
1020 pure: maintainer-clean
1021
1022 .PHONY: install_initd_debian install-initd-debian
1023 install_initd_debian install-initd-debian:
1024         sed -e "s#DAEMON=/usr/sbin/kamailio#DAEMON=$(bin_prefix)/$(bin_dir)$(NAME)#g" \
1025                 -e "s#NAME=kamailio#NAME=$(NAME)#g" \
1026                 -e "s#DESC=Kamailio#DESC=$(NAME)#g" \
1027                 -e "s#HOMEDIR=/var/run/kamailio#HOMEDIR=/var/run/$(NAME)#g" \
1028                 -e "s#DEFAULTS=/etc/default/kamailio#DEFAULTS=/etc/default/$(NAME)#g" \
1029                 -e "s#CFGFILE=/etc/kamailio/kamailio.cfg#CFGFILE=$(cfg_prefix)/$(cfg_dir)$(NAME).cfg#g" \
1030                 < pkg/kamailio/deb/debian/kamailio.init \
1031                 > /etc/init.d/$(NAME)
1032         chmod +x /etc/init.d/$(NAME)
1033         sed -e "s#RUN_KAMAILIO=no#RUN_KAMAILIO=yes#g" \
1034                 < pkg/kamailio/deb/debian/kamailio.default \
1035                 > /etc/default/$(NAME)
1036         mkdir -p /var/run/$(NAME)
1037         adduser --quiet --system --group --disabled-password \
1038         --shell /bin/false --gecos "$(NAME)" \
1039         --home /var/run/$(NAME) $(NAME)
1040         chown $(NAME):$(NAME) /var/run/$(NAME)
1041
1042 .PHONY: install_initd_centos install-initd-centos
1043 install_initd_centos install-initd-centos:
1044         sed -e "s#KAM=/usr/sbin/kamailio#KAM=$(bin_prefix)/$(bin_dir)$(NAME)#g" \
1045                 -e "s#PROG=kamailio#PROG=$(NAME)#g" \
1046                 -e "s#DEFAULTS=/etc/default/kamailio#DEFAULTS=/etc/default/$(NAME)#g" \
1047                 -e "s#PID_FILE=/var/run/kamailio.pid#PID_FILE=/var/run/$(NAME).pid#g" \
1048                 -e "s#LOCK_FILE=/var/lock/subsys/kamailio#LOCK_FILE=/var/lock/subsys/$(NAME)#g" \
1049                 -e "s#KAMCFG=/etc/kamailio/kamailio.cfg#KAMCFG=$(cfg_prefix)/$(cfg_dir)$(NAME).cfg#g" \
1050                 < pkg/kamailio/rpm/kamailio.init \
1051                 > /etc/init.d/$(NAME)
1052         chmod +x /etc/init.d/$(NAME)
1053         sed -e "s#RUN_KAMAILIO=no#RUN_KAMAILIO=yes#g" \
1054                 -e "s#USER=kamailio#USER=$(NAME)#g" \
1055                 -e "s#GROUP=kamailio#GROUP=$(NAME)#g" \
1056                 < pkg/kamailio/rpm/kamailio.default \
1057                 > /etc/default/$(NAME)
1058         /usr/sbin/groupadd -r $(NAME)
1059         /usr/sbin/useradd -r -g $(NAME) -s /bin/false -c "Kamailio Daemon" \
1060                   -d ${lib_prefix}/${lib_dir} $(NAME)
1061
1062 .PHONY: dbschema
1063 dbschema:
1064         -@echo "Build database schemas"
1065         $(MAKE) -C lib/srdb1/schema
1066         -@echo "Done"
1067
1068 .PHONY: printcdefs
1069 printcdefs:
1070         @echo -n $(C_DEFS)
1071
1072 .PHONY: printvar
1073 printvar:
1074         @echo "Content of <$(v)> is:"
1075         @echo -n $($(v))
1076         @echo
1077
1078 .PHONY: uninstall
1079 uninstall:
1080         @echo "-Installation details:"
1081         @echo " *PREFIX Path is: ${PREFIX}"
1082         @echo " *BINDIR Path is: ${bin_prefix}/${bin_dir}"
1083         @echo " *CFGDIR Path is: ${cfg_prefix}/${cfg_dir}"
1084         @echo " *DOCDIR Path is: ${doc_prefix}/${doc_dir}"
1085         @echo " *LIBDIR Path is: ${lib_prefix}/${lib_dir}"
1086         @echo " *MANDIR Path is: ${man_prefix}/${man_dir}"
1087         @echo " *SHRDIR Path is: ${share_prefix}/${share_dir}"
1088         @if [ "${PREFIX}" != "/usr/local" ] ; then \
1089                 echo "-Custom PREFIX Path" ; \
1090                 if [ "${PREFIX}" = "/" -o "${PREFIX}" = "/usr" ] ; then \
1091                         echo "-Custom installation in a system folder" ; \
1092                         echo "-This is advanced installation" ; \
1093                         echo "-You seem to be in control of what files were deployed" ; \
1094                         echo "-Folders listed above should give hints about what to delete" ; \
1095                 else \
1096                         echo "-Uninstall should be just removal of the folder: ${PREFIX}" ; \
1097                         echo "-WARNING: before deleting, be sure ${PREFIX} is not a system directory" ; \
1098                 fi ; \
1099         else \
1100                 echo "-Run following commands to uninstall:" ; \
1101                 echo ; \
1102                 echo "rm ${bin_prefix}/${bin_dir}${MAIN_NAME}" ; \
1103                 if [ "${FLAVOUR}" = "kamailio" ] ; then \
1104                         echo "rm ${bin_prefix}/${bin_dir}kamctl" ; \
1105                         echo "rm ${bin_prefix}/${bin_dir}kamdbctl" ; \
1106                 fi ; \
1107                 echo "rm ${bin_prefix}/${bin_dir}kamcmd" ; \
1108                 echo "rm ${man_prefix}/${man_dir}man5/$(MAIN_NAME).cfg.5" ; \
1109                 echo "rm ${man_prefix}/${man_dir}man8/$(MAIN_NAME).8" ; \
1110                 if [ "${FLAVOUR}" = "kamailio" ] ; then \
1111                         echo "rm ${man_prefix}/${man_dir}kamctl.8" ; \
1112                         echo "rm ${man_prefix}/${man_dir}kamdbctl.8" ; \
1113                 fi ; \
1114                 echo "rm -rf ${cfg_prefix}/${cfg_dir}" ; \
1115                 echo "rm -rf ${doc_prefix}/${doc_dir}" ; \
1116                 echo "rm -rf ${lib_prefix}/${lib_dir}" ; \
1117                 echo "rm -rf ${share_prefix}/${share_dir}" ; \
1118                 echo ; \
1119                 echo "-WARNING: before running the commands, be sure they don't delete any system directory or file" ; \
1120         fi ;
1121         @echo