Makefile
e60a9728
 # $Id$
 #
 # sip_router makefile
 #
1b1b19d8
 # WARNING: requires gmake (GNU Make)
aee4712e
 #  Arch supported: Linux, FreeBSD, SunOS (tested on Solaris 8), OpenBSD (3.2),
0762e9d5
 #  NetBSD (1.6).
a2786e3e
 #
 #  History:
 #  --------
 #              created by andrei
 #  2003-02-24  make install no longer overwrites ser.cfg  - patch provided
 #               by Maxim Sobolev   <sobomax@FreeBSD.org> and 
cbd93cf4
 #                  Tomas Björklund <tomas@webservices.se>
56c2dabd
 #  2003-03-11  PREFIX & LOCALBASE must also be exported (andrei)
90907c3f
 #  2003-04-07  hacked to work with solaris install (andrei)
fc50bc47
 #  2003-04-17  exclude modules overwritable from env. or cmd. line,
 #               added include_modules and skip_modules (andrei)
3dae72a3
 #  2003-05-30  added extra_defs & EXTRA_DEFS
 #               Makefile.defs force-included to allow recursive make
 #               calls -- see comment (andrei)
f742de6a
 #  2003-06-02  make tar changes -- unpacks in $NAME-$RELEASE  (andrei)
 #  2003-06-03  make install-cfg will properly replace the module path
 #               in the cfg (re: /usr/.*lib/ser/modules)
 #              ser.cfg.default is installed only if there is a previous
 #               cfg. -- fixes packages containing ser.cfg.default (andrei)
d48f0d9b
 #  2003-08-29  install-modules-doc split from install-doc, added 
 #               install-modules-all, removed README.cfg (andrei)
 #              added skip_cfg_install (andrei)
c3e5dd3e
 #  2004-09-02  install-man will automatically "fix" the path of the files
 #               referred in the man pages
eddda8ce
 #  2006-02-14  added utils & install-utils (andrei)
6309eded
 #  2006-03-15  added nodeb parameter for make tar (andrei)
cbd93cf4
 #  2006-09-29  added modules-doc as target and doc_format= as make option (greger)
3f93b05e
 #  2006-12-09  added new group_include as make option and defined groups 
 #               defining which modules to include. Also added new target 
 #               print-modules that you can use to check which modules will be 
 #               compiled (greger)
 #  2007-01-10  added new group_include targets mysql, radius, and presence 
 #               improved print-modules output fixed problem in include/exclude
 #               logic when using group_include (greger)
 #  2007-03-01  fail if a module or a required utility make fail unless 
 #              err_fail=0; don't try to make modules with no Makefiles (andrei)
3922c022
 #  2007-03-16  moved the exports to Makefile.defs (andrei)
 #  2007-03-29  install-modules changed to use make -C modpath install (andrei)
1bd1a2ef
 #  2007-05-04  "if ! foo" not supported in standard sh, switched to 
 #                "if foo; then :; else ... ; fi" (andrei)
7742b1d2
 #  2008-06-23  added 2 new targets: README and man (re-generate the README
617ced39
 #              or manpages for all the modules) (andrei)
7742b1d2
 #  2008-06-25  make cfg support (use a pre-built cfg.: config.mak) (andrei)
299781b1
 #  2008-06-28  added clean-all, proper-all, install-modules-man and error 
 #               checks for install-utils & doc (andrei)
0bd6adc6
 #  2008-07-01  split module list from config.mak into modules.lst so that
 #               the modules list can be changed without rebuilding the whole
 #               ser (andrei)
 #              added cfg-defs, new target that only rebuilds config.mak
f072585d
 #  2009-03-10  replaced DEFS with C_DEFS (DEFS are now used only for
 #              "temporary" defines inside modules or libs) (andrei)
27cdfd2c
 #  2009-03-27  multiple modules directory support, see modules_dirs (andrei)
724ca087
 #  2009-04-02  workaround for export not supported in gnu make 3.80
 #               target specific variables: use mk_params for each
 #               $(MAKE) invocation (andrei)
3f52ab26
 #  2009-04-22  don't rebuild config.mak or modules.lst if not needed
 #              (e.g. on clean) (andrei)
a868066e
 #  2009-06-24  auto-generate autover.h, containing the REPO_VER macro, defined
 #               to the top git commit sha (if git is found) (andrei)
0bd6adc6
 #
e60a9728
 
96d9c662
 # check make version
e2a88d5b
 # everything works with 3.80, except evals inside ifeq/endif
 # (see https://savannah.gnu.org/bugs/index.php?func=detailitem&item_id=1516).
 # recommended 3.81
 req_ver=3.81
96d9c662
 # the check below works for version number of the type x.yy or x.yy.z*
 # (from the GNU Make Cookbook)
 ifeq (,$(filter $(req_ver),$(firstword $(sort $(MAKE_VERSION) $(req_ver)))))
 $(error make version $(MAKE_VERSION) not supported, use at least $(req_ver))
 endif
 
 
9de818a2
 auto_gen=lex.yy.c cfg.tab.c #lexx, yacc etc
1849815b
 auto_gen_others=cfg.tab.h # auto generated, non-c
 auto_gen_keep=autover.h # auto generated, should be included in archives
247c2b65
 
3514d04c
 COREPATH=.
247c2b65
 #include  source related defs
 include Makefile.sources
3f52ab26
 #include special targets lists
 include Makefile.targets
247c2b65
 
3f93b05e
 # whether or not the entire build process should fail if building a module or
 #  an utility fails
 err_fail?=1
 
91ced801
 # whether or not to install $(MAIN_NAME).cfg or just $(MAIN_NAME).cfg.default
 # ($(MAIN_NAME).cfg will never be overwritten by make install, this is usefull
d48f0d9b
 #  when creating packages)
 skip_cfg_install?=
 
fc50bc47
 #extra modules to exclude
 skip_modules?=
 
27cdfd2c
 # see Makefile.dirs for the directories used for the modules
 include Makefile.dirs
 
cbd93cf4
 # Set document format
 # Alternatives are txt, html, xhtml, and pdf (see Makefile.doc)
 doc_format?=html
 
3f52ab26
 # don't force modules.lst generation if the makefile goals do not
 # require it (but if present use it)
 ifeq (,$(strip $(filter-out $(clean_targets) $(aux_targets),$(MAKECMDGOALS))))
 ifneq (,$(strip $(wildcard modules.lst)))
 -include modules.lst
 endif
 else
898376a7
 include modules.lst
3f52ab26
 endif # ifneq (,$(strip $(filter-out ...,$(MAKECMDGOALS))))
898376a7
 
 #if called with group_include, ignore the modules from modules.lst
 ifneq ($(group_include),)
 	include_modules=
 	exclude_modules=
 	modules_configured:=0
 endif
 
1ec7aeb1
 # Module group definitions, default only include the standard group
 # Make backwards compatible, don't set group_include default...
 #group_include?="standard"
 
3f93b05e
 # Modules in this group are considered a standard part of SER (due to 
 # widespread usage) and have no external compile or link dependencies (note 
 # that some of these interplay with external systems).
608888ec
 module_group_standard=acc_syslog auth avp ctl dispatcher diversion enum\
543f9a53
 				eval exec fifo db_flatstore gflags maxfwd mediaproxy \
1ec7aeb1
 				nathelper options pdt permissions pike print ratelimit \
 				registrar rr sanity sl textops timer tm uac unixsock uri \
c6c91622
 				usrloc xlog cfg_rpc
1ec7aeb1
 
3f93b05e
 # Modules in this group are considered a standard part of SER (due to 
 # widespread usage) but they have dependencies that must be satisfied for 
 # compilation.
543f9a53
 # acc_radius, auth_radius, misc_radius => radiusclient-ng
3f93b05e
 # acc_db, auth_db, avp_db, db_ops, domain, lcr, msilo, dialog, speeddial,
543f9a53
 # uri_db => database module (db_mysql, db_postgres, dbtext ...)
3f93b05e
 # mysql, postgres => mysql server and client libraries or postgres server and
 #  client libraries or other database back-end (ex. mysql-devel)
1ec7aeb1
 # pa, xmlrpc => libxml2
 # rls => pa
 #
3f93b05e
 # NOTE! All presence modules (dialog, pa, presence_b2b, rls, xcap) have been
 # included in this group due to interdependencies
 module_group_standard_dep=acc_db acc_radius auth_db auth_radius avp_db \
543f9a53
 				auth_identity db_ops domain lcr misc_radius \
 				msilo dialog pa \
52bcc791
 				presence_b2b rls speeddial uri_db xcap xmlrpc
1ec7aeb1
 
380398ad
 # For db use (db modules, excluding drivers)
56a54e94
 module_group_db=acc_db auth_db avp_db db_ops db_flatstore db_text \
380398ad
 				uri_db domain lcr msilo speeddial
56a54e94
 				#dbtext (s) not migrated yet to the new db interface
380398ad
 
fd564b72
 # For mysql
380398ad
 module_group_mysql_driver=db_mysql
 module_group_mysql=$(module_group_mysql_driver) $(module_group_db)
 
 # For postgress
 module_group_postgres_driver=db_postgres
 module_group_postgres=$(module_group_postgres_driver) $(module_group_db)
fd564b72
 
 # For radius
543f9a53
 module_group_radius=acc_radius auth_radius misc_radius peering
fd564b72
 
 # For presence
52bcc791
 module_group_presence=dialog pa presence_b2b rls xcap
fd564b72
 
3f93b05e
 # Modules in this group satisfy specific or niche applications, but are 
 # considered stable for production use. They may or may not have dependencies
1ec7aeb1
 # cpl-c => libxml2
 # jabber => expat (library)
 # osp => OSP Toolkit (sipfoundry)
 # sms => none (external modem)
 module_group_stable=cpl-c dbtext jabber osp sms
 
3f93b05e
 # Modules in this group are either not complete, untested, or without enough
 # reports of usage to allow the module into the stable group. They may or may
 # not have dependencies
12f28ced
 module_group_experimental=tls oracle iptrtpproxy
1ec7aeb1
 
898376a7
 # if not set on the cmd. line, env or in the modules.lst (cfg_group_include)
 # exclude the below modules.
 ifneq ($(group_include)$(cfg_group_include),)
3f93b05e
 	# For group_include, default all modules are excluded except those in 
 	# include_modules
fd564b72
 	exclude_modules?=
1ec7aeb1
 else
 	# Old defaults for backwards compatibility
4e4228db
 	# excluded because they depend on external libraries
ee9b2b68
 	exclude_modules?= 		cpl mangler postgres jabber mysql cpl-c \
543f9a53
 							auth_radius misc_radius \
7d95baf3
 							acc_radius dialog pa rls presence_b2b xcap xmlrpc\
6aeed6db
 							osp tls oracle \
b0f6ec87
 							unixsock dbg print_lib auth_identity ldap \
 							db_berkeley db_mysql db_postgres db_oracle \
 							db_unixodbc memcached mi_xmlrpc \
4e4228db
 							nat_traversal perl perlvdb purple seas siptrace \
b0f6ec87
 							snmpstats uac_redirect xmpp \
4e4228db
 							carrierroute misc_radius peering \
 							dialplan lcr utils presence \
 							presence_dialoginfo presence_xml pua pua_bla \
 							pua_dialoginfo pua_usrloc pua_xmpp \
 							regex xcap_client
 	#excluded because they depend on external *.h files
 	exclude_modules+= h350
7eec6c23
 	# excluded because they do not compile (remove them only after they are
 	#  fixed) -- andrei
db2eed95
 	exclude_modules+= bdb dbtext iptrtpproxy pa rls
1ec7aeb1
 endif
 
fc50bc47
 # always exclude the CVS dir
 override exclude_modules+= CVS $(skip_modules)
 
1ec7aeb1
 # Test for the groups and add to include_modules
380398ad
 ifneq (,$(group_include))
2af7504f
 $(eval override include_modules+= $(foreach grp, $(group_include), \
 										$(module_group_$(grp)) ))
1ec7aeb1
 endif
 
0762e9d5
 # first 2 lines are excluded because of the experimental or incomplete
 # status of the modules
 # the rest is excluded because it depends on external libraries
 #
b89da7b7
 static_modules:=
7742b1d2
 
27cdfd2c
 ALLDEP=config.mak Makefile Makefile.dirs Makefile.sources Makefile.rules
7742b1d2
 
 #include general defs (like CC, CFLAGS  a.s.o)
 # hack to force makefile.defs re-inclusion (needed when make calls itself with
 # other options -- e.g. make bin)
 #makefile_defs=0
f072585d
 #C_DEFS:=
7742b1d2
 
 
3f52ab26
 # try saved cfg, unless we are in the process of building it or if we're doing
 # a clean
 ifeq (,$(strip \
 	$(filter config.mak config cfg cfg-defs $(clean_targets),$(MAKECMDGOALS))))
7742b1d2
 include config.mak
 ifeq ($(makefile_defs),1)
 $(info config.mak loaded)
 # config_make valid & used
 config_mak=1
b5cb01a3
 ifeq ($(MAIN_NAME),)
 $(error "bad config.mak, try re-running make cfg")
 endif
7742b1d2
 endif
3f52ab26
 else # config.mak doesn't need to be used
0bd6adc6
 ifneq (,$(filter cfg config cfg-defs,$(word 1,$(MAKECMDGOALS))))
7742b1d2
 # needed here to avoid starting a config submake 
 # (e.g. rm -f config.mak; make config.mak), which would either require 
 # double Makefile.defs defines execution (suboptimal), would loose
 # $(value ...) expansion or would cause some warning (if Makefile.defs exec. 
 # is skipped in the "main" makefile invocation).
 $(shell rm -rf config.mak)
b5cb01a3
 config_mak=0
 makefile_defs=0
 exported_vars=0
7742b1d2
 endif
 endif
 
0bd6adc6
 
7742b1d2
 main_makefile=1
 include Makefile.defs
 
404073d3
 static_modules_path=$(addprefix modules/, $(static_modules))
 extra_sources=$(wildcard $(addsuffix /*.c, $(static_modules_path)))
 extra_objs=$(extra_sources:.c=.o)
 
b89da7b7
 static_defs:= $(foreach  mod, $(static_modules), \
af9d50fc
 		-DSTATIC_$(shell echo $(mod) | tr [:lower:] [:upper:]) )
3dae72a3
 
 override extra_defs+=$(static_defs) $(EXTRA_DEFS)
 export extra_defs
 
3f93b05e
 # Historically, the resultant set of modules is: modules/* - exclude_modules +
 # include_modules
 # When group_include is used, we want: include_modules (based on group_include)
 # - exclude_modules
7742b1d2
 
 ifneq ($(modules_configured),1) 
27cdfd2c
 #modules_all=$(filter-out modules/CVS,$(wildcard modules/*))
 
 # create modules*_all vars
 $(foreach mods,$(modules_dirs),$(eval \
 	$(mods)_all=$$(filter-out $(mods)/CVS,$$(wildcard $(mods)/*))))
 #debugging
 #$(foreach mods,$(modules_dirs),$(info "$(mods)_all=$($(mods)_all)"))
 
fd564b72
 ifneq ($(group_include),)
27cdfd2c
 $(foreach mods,$(modules_dirs),$(eval \
 	$(mods)=$$(filter-out $$(addprefix $(mods)/, \
 			$$(exclude_modules) $$(static_modules)), \
 			$$(addprefix $(mods)/, $$(include_modules) )) ))
fd564b72
 else	
 	# Standard, old resultant set
27cdfd2c
 $(foreach mods,$(modules_dirs),$(eval \
 	$(mods)_noinc=$$(filter-out $$(addprefix $(mods)/, \
 			$$(exclude_modules) $$(static_modules)), $$($(mods)_all)) \
 ))
 $(foreach mods,$(modules_dirs),$(eval \
 	$(mods)=$$(filter-out $$(modules_noinc), \
 			$$(addprefix $(mods)/, $$(include_modules) )) $$($(mods)_noinc) \
 ))
7742b1d2
 endif # ifneq($(group_include),)
 endif # ifneq($(modules_configured),1)
27cdfd2c
 
 $(foreach mods,$(modules_dirs),$(eval \
 	$(mods)_names=$$(shell echo $$($(mods))| \
 				sed -e "s/$(mods)"'\/\([^/ ]*\)\/*/\1.so/g' ) \
 ))
 $(foreach mods,$(modules_dirs),$(eval \
 	$(mods)_basenames:=$$(shell echo $$($(mods))| \
 				sed -e "s/$(mods)"'\/\([^/ ]*\)\/*/\1/g' ) \
 ))
 
 # all modules from all the $(modules_dirs)
 all_modules_lst=$(foreach mods,$(modules_dirs), $($(mods)_all))
 
 # compile modules list (all the compiled mods from  $(modules_dirs))
 cmodules=$(foreach mods,$(modules_dirs), $($(mods)))
 
6ac71d10
 #modules_names=$(patsubst modules/%, %.so, $(modules))
7742b1d2
 #modules_full_path=$(join  $(modules), $(addprefix /, $(modules_names)))
e60a9728
 
 
eddda8ce
 # which utils need compilation (directory path) and which to install
 # (full path including file name)
3df7e45b
 utils_compile=	utils/gen_ha1 utils/sercmd
67a79433
 utils_bin_install=	utils/gen_ha1/gen_ha1 utils/sercmd/sercmd
ee03be75
 utils_script_install=
 
 # This is the list of files to be installed into the arch-independent
91ced801
 # shared directory (by default /usr/local/share/$(MAIN_NAME))
ee03be75
 share_install= scripts/mysql/my_create.sql \
 			   scripts/mysql/my_data.sql   \
 			   scripts/mysql/my_drop.sql
eddda8ce
 
 
0ae4dfdc
 
194b6a35
 NAME=$(MAIN_NAME)
 
6309eded
 tar_name=$(NAME)-$(RELEASE)_src
 
9de818a2
 tar_extra_args+=$(addprefix --exclude=$(notdir $(CURDIR))/, \
 					$(auto_gen) $(auto_gen_others))
6c53d41a
 ifeq ($(CORE_TLS), 1)
346c7dab
 	tar_extra_args+=
 else
895cb2af
 	tar_extra_args+=--exclude=$(notdir $(CURDIR))/tls/* 
346c7dab
 endif
6309eded
 
 ifneq ($(nodeb),)
 	tar_extra_args+=--exclude=$(notdir $(CURDIR))/debian 
 	tar_name:=$(tar_name)_nodeb
 endif
6c53d41a
 
 # sanity checks
 ifneq ($(TLS),)
8ed78eb4
         $(warning "make TLS option is obsoleted, try TLS_HOOKS or CORE_TLS")
6c53d41a
 endif
 
247c2b65
 # include the common rules
 include Makefile.rules
e60a9728
 
247c2b65
 #extra targets 
3e429f5c
 
fa60aefe
 $(NAME): $(extra_objs) # static_modules
04bb7a49
 
aeb805d5
 lex.yy.c: cfg.lex cfg.tab.h $(ALLDEP)
a15c363f
 	$(LEX) $<
 
aeb805d5
 cfg.tab.c cfg.tab.h: cfg.y  $(ALLDEP)
a15c363f
 	$(YACC) $(YACC_FLAGS) $<
 
c82fe029
 nullstring=
 space=$(nullstring) $(nullstring)
 
 modules_search_path=$(subst $(space),:,$(strip\
a88b7d6f
 						$(foreach m,$(modules_dirs),$($(m)_target))))
 		#				$(addprefix $(modules_target),$(modules_dirs))))
c82fe029
 
51690b9e
 # special depends for main.o
1849815b
 main.d main.o: autover.h
c82fe029
 main.o: DEFS+=-DMODS_DIR='"$(modules_search_path)"'
 
1849815b
 
51690b9e
 #special depends for core_cmd.o
1849815b
 core_cmd.d core_cmd.o: autover.h
51690b9e
 
bb31c7ad
 include Makefile.shared
 
7742b1d2
 ifeq ($(config_mak),1)
 
 include Makefile.cfg
 
 else
 
 config.mak: Makefile.defs
 	@echo making config...
 	@echo "# this file is autogenerated by make cfg" >$@
 	@$(call mapf2,cfg_save_var,saved_fixed_vars,$(@))
 	@$(call mapf2,cfg_save_var2,saved_chg_vars,$(@))
 	@echo "override makefile_defs:=1" >>$@
f072585d
 	@echo "C_DEFS:=\$$(filter-out \$$(DEFS_RM) \$$(extra_defs),\$$(C_DEFS))" \
0bd6adc6
 					"\$$(extra_defs)"  >>$@
 	@echo "CFLAGS:=\$$(filter-out \$$(CFLAGS_RM) \$$(CC_EXTRA_OPTS)," \
 						"\$$(CFLAGS)) \$$(CC_EXTRA_OPTS)" >>$@
 
 endif # ifeq ($(config_mak),1)
 
 modules.lst:
 	@echo  saving modules list...
 	@echo "# this file is autogenerated by make modules-cfg" >$@
27cdfd2c
 	@echo "modules_dirs:=$(modules_dirs)" >>$@
898376a7
 	@echo "cfg_group_include=$(group_include)" >>$@
7742b1d2
 	@$(call cfg_save_var2,include_modules,$@)
 	@$(call cfg_save_var2,static_modules,$@)
 	@$(call cfg_save_var2,skip_modules,$@)
 	@$(call cfg_save_var2,exclude_modules,$@)
27cdfd2c
 	@$(foreach mods,$(modules_dirs), \
 		$(call cfg_save_var2,$(mods)_all,$@))
 	@$(foreach mods,$(modules_dirs), \
 		$(call cfg_save_var2,$(mods)_noinc,$@))
 	@$(foreach mods,$(modules_dirs), \
 		$(call cfg_save_var2,$(mods),$@))
7742b1d2
 	@echo "modules_configured:=1" >>$@
 
3f52ab26
 
0bd6adc6
 .PHONY: cfg config cfg-defs
 cfg-defs: config.mak
7742b1d2
 
0bd6adc6
 cfg config: cfg-defs modules-cfg
7742b1d2
 
0bd6adc6
 .PHONY: modules-cfg modules-list modules-lst
3f52ab26
 modules-cfg modules-list modules-lst:
ee9b2b68
 	rm -f modules.lst
0bd6adc6
 	$(MAKE) modules.lst
7742b1d2
 
51690b9e
 ifneq ($(wildcard .git),)
 # if .git/ exists
a868066e
 repo_ver=$(shell  RV=`git rev-parse --verify --short=6 HEAD 2>/dev/null`;\
 					[ -n "$$RV" ] && \
277225d5
 					test -n "`git update-index --refresh --unmerged >/dev/null\
 							; git diff-index --name-only HEAD 2>/dev/null | \
 								grep -v Makefile`" &&\
a868066e
 						RV="$$RV"-dirty; echo "$$RV")
277225d5
 autover_h_dep=.git $(filter-out $(auto_gen), $(sources)) cfg.y cfg.lex
51690b9e
 else
 # else if .git/ does not exist
a868066e
 repo_ver=
51690b9e
 autover_h_dep=
 endif
 
a868066e
 
51690b9e
 autover.h: $(autover_h_dep)
277225d5
 	@echo  "generating autover.h ..."
51690b9e
 	@echo "/* this file is autogenerated by make autover.h" >$@
 	@echo " * DO NOT EDIT IT" >>$@
 	@echo " */" >>$@
 	@echo "" >>$@
 	@echo "#define REPO_VER \"$(repo_ver)\"" >>$@
 
e60a9728
 .PHONY: all
27cdfd2c
 all: $(NAME) every-module
e60a9728
 
1ec7aeb1
 .PHONY: print-modules
 print-modules:
7742b1d2
 	@echo The following modules were chosen to be included: \
 		$(include_modules) ; \
1ec7aeb1
 	echo ---------------------------------------------------------- ; \
 	echo The following modules will be excluded: $(exclude_modules) ; \
fd564b72
 	echo ---------------------------------------------------------- ; \
27cdfd2c
 	echo The following modules will be made; \
 	$(foreach mods,$(modules_dirs), \
 		echo $(mods)/: $($(mods)_basenames) ; ) \
 	#echo DBG: The following modules will be made: $(modules_basenames) ; \
 
96001c50
 
27cdfd2c
 # modules templates (instantiated based on modules_dirs contents)
 define MODULES_RULES_template
 
 $(1)_dst=$(modules_prefix)/$(modules_dir)$(1)
a88b7d6f
 $(1)_target=$(prefix)/$(modules_dir)$(1)
27cdfd2c
 
 .PHONY: $(1)
 $(1): modules.lst
 	@for r in $($(1)) "" ; do \
 		if [ -n "$$$$r" -a -r "$$$$r/Makefile" ]; then \
e7a9bd30
 			echo  "" ; \
 			echo  "" ; \
27cdfd2c
 			if  $(MAKE) -C $$$$r $$(mk_params) || [ ${err_fail} != 1 ] ; then \
 				:; \
 			else \
 				exit 1; \
 			fi ; \
 		fi ; \
 	done; true
 
 .PHONY: $(1)-doc
 $(1)-doc: modules.lst
 	@for r in $($(1)) "" ; do \
 		if [ -n "$$$$r" ]; then \
 			echo  "" ; \
 			echo  "" ; \
 			$(MAKE) -C $$$$r/doc $(doc_format) $$(mk_params); \
 		fi ; \
 	done
 
 .PHONY: $(1)-readme
 
 $(1)-readme: modules.lst
 	-@for r in $($(1)) "" ; do \
 		if [ -n "$$$$r" ]; then \
 			echo  "" ; \
 			echo  "" ; \
 			if  $(MAKE) -C $$$$r $$(mk_params) README || [ ${err_fail} != 1 ];\
 			then \
 				:; \
 			else \
 				exit 1; \
 			fi ; \
 		fi ; \
 	done; true
 
 .PHONY: $(1)-man
 $(1)-man: modules.lst
 	-@for r in $($(1)) "" ; do \
 		if [ -n "$$$$r" ]; then \
 			echo  "" ; \
 			echo  "" ; \
 			if  $(MAKE) -C $$$$r $$(mk_params) man || [ ${err_fail} != 1 ] ;\
 			then \
 				:; \
 			else \
 				exit 1; \
 			fi ; \
 		fi ; \
 	done; true
 
 .PHONY: install-$(1)
 
 install-$(1): modules.lst $$($(1)_dst)
 	@for r in $($(1)) "" ; do \
 		if [ -n "$$$$r" -a -r "$$$$r/Makefile" ]; then \
 			echo  "" ; \
 			echo  "" ; \
 			if  $(MAKE) -C $$$$r install mods_dst=$$($(1)_dst) $$(mk_params) \
 				|| [ ${err_fail} != 1 ] ; then \
1bd1a2ef
 				:; \
 			else \
3f93b05e
 				exit 1; \
 			fi ; \
e7a9bd30
 		fi ; \
3f93b05e
 	done; true
404073d3
 
27cdfd2c
 
 .PHONY: install-$(1)-doc
 
 install-$(1)-doc: modules.lst $(doc_prefix)/$(doc_dir)$(1)
 	@for r in $($(1)_basenames) "" ; do \
 		if [ -n "$$$$r" ]; then \
 			if [ -f $(1)/"$$$$r"/README ]; then \
 				$$(call try_err,\
 					$(INSTALL_TOUCH) $(doc_prefix)/$(doc_dir)$(1)/README ); \
 				$$(call try_err,\
 					$(INSTALL_DOC)  $(1)/"$$$$r"/README  \
 									$(doc_prefix)/$(doc_dir)$(1)/README ); \
 				$$(call try_err,\
 					mv -f $(doc_prefix)/$(doc_dir)$(1)/README \
 							$(doc_prefix)/$(doc_dir)$(1)/README."$$$$r" ); \
 			fi ; \
 		fi ; \
 	done; true
 
 .PHONY: install-$(1)-man
 
 install-$(1)-man: $(1)-man $(man_prefix)/$(man_dir)/man7
 	@for r in $($(1)_basenames) "" ; do \
 		if [ -n "$$$$r" ]; then \
 			if [ -f $(1)/"$$$$r"/"$$$$r".7 ]; then \
 				$$(call try_err,\
 				  $(INSTALL_TOUCH) $(man_prefix)/$(man_dir)/man7/"$$$$r".7 );\
 				$$(call try_err,\
89fd860c
 					$(INSTALL_MAN)  $(1)/"$$$$r"/"$$$$r".7  \
27cdfd2c
 									$(man_prefix)/$(man_dir)/man7 ); \
 			fi ; \
 		fi ; \
 	done; true
 
 
 $(modules_prefix)/$(modules_dir)$(1):
 		mkdir -p $$(@)
 
 $(doc_prefix)/$(doc_dir)$(1):
 		mkdir -p $$(@)
 
 
 endef
 
 # instantiate the template
 $(foreach mods,$(modules_dirs),$(eval $(call MODULES_RULES_template,$(mods))))
 
 #$(foreach mods,$(modules_dirs),$(eval  $(info DUMP: $(call MODULES_RULES_template,$(mods)))))
 
 # build all the modules
380398ad
 modules-all every-module: $(modules_dirs)
27cdfd2c
 
fa60aefe
 $(extra_objs):
3f93b05e
 	@echo "Extra objs: $(extra_objs)" 
 	@for r in $(static_modules_path) "" ; do \
 		if [ -n "$$r" -a -r "$$r/Makefile"  ]; then \
e7a9bd30
 			echo  "" ; \
 			echo  "Making static module $r" ; \
724ca087
 			if $(MAKE) -C $$r static $(mk_params) ; then  \
1bd1a2ef
 				:; \
 			else \
3f93b05e
 				exit 1; \
 			fi ;  \
e7a9bd30
 		fi ; \
3f93b05e
 	done
404073d3
 
eddda8ce
 .PHONY: utils
 utils:
3f93b05e
 	@for r in $(utils_compile) "" ; do \
eddda8ce
 		if [ -n "$$r" ]; then \
 			echo  "" ; \
 			echo  "" ; \
724ca087
 			if  $(MAKE) -C $$r $(mk_params) || [ ${err_fail} != 1 ] ; \
 			then \
1bd1a2ef
 				:; \
 			else \
3f93b05e
 				exit 1; \
 			fi ; \
eddda8ce
 		fi ; \
3f93b05e
 	done; true
404073d3
 
cbd93cf4
 
5d1a75a6
 dbg: sip-router
f571aa35
 	gdb -command debug.gdb
247c2b65
 
0bafb279
 .PHONY: tar
31521f89
 .PHONY: dist
 
 dist: tar
 
1849815b
 tar: $(auto_gen_keep)
054cb6cf
 	$(TAR) -C .. \
3dae72a3
 		--exclude=$(notdir $(CURDIR))/test* \
 		--exclude=$(notdir $(CURDIR))/tmp* \
91ced801
 		--exclude=$(notdir $(CURDIR))/debian/$(MAIN_NAME) \
 		--exclude=$(notdir $(CURDIR))/debian/$(MAIN_NAME)-* \
 		--exclude=$(notdir $(CURDIR))/$(MAIN_NAME)_tls* \
1849815b
 		--exclude=.git* \
3dae72a3
 		--exclude=CVS* \
871a6a07
 		--exclude=.svn* \
346c7dab
 		--exclude=.cvsignore \
3922c022
 		--exclude=librpath.lst \
5cace4ed
 		--exclude=libiname.lst \
 		--exclude=makecfg.lst \
7742b1d2
 		--exclude=config.mak \
0bd6adc6
 		--exclude=modules.lst \
31521f89
 		--exclude=*.[do] \
 		--exclude=*.so \
 		--exclude=*.il \
91ced801
 		--exclude=$(notdir $(CURDIR))/$(MAIN_NAME) \
31521f89
 		--exclude=*.gz \
 		--exclude=*.bz2 \
 		--exclude=*.tar \
346c7dab
 		--exclude=*.patch \
 		--exclude=.\#* \
 		--exclude=*.swp \
1849815b
 		--exclude=*.swo \
346c7dab
 		${tar_extra_args} \
31521f89
 		-cf - $(notdir $(CURDIR)) | \
696ba02d
 			(mkdir -p tmp/_tar1; mkdir -p tmp/_tar2 ; \
 			    cd tmp/_tar1; $(TAR) -xf - ) && \
 			    mv tmp/_tar1/$(notdir $(CURDIR)) \
 			       tmp/_tar2/"$(NAME)-$(RELEASE)" && \
 			    (cd tmp/_tar2 && $(TAR) \
6309eded
 			                    -zcf ../../"$(tar_name)".tar.gz \
31521f89
 			                               "$(NAME)-$(RELEASE)" ) ; \
696ba02d
 			    rm -rf tmp/_tar1; rm -rf tmp/_tar2
0bafb279
 
 # binary dist. tar.gz
 .PHONY: bin
 bin:
91ced801
 	mkdir -p tmp/$(MAIN_NAME)/usr/local
 	$(MAKE) install basedir=tmp/$(MAIN_NAME) $(mk_params)
 	$(TAR) -C tmp/$(MAIN_NAME)/ -zcf ../$(NAME)-$(RELEASE)_$(OS)_$(ARCH).tar.gz .
 	rm -rf tmp/$(MAIN_NAME)
04bb7a49
 
5c6101da
 .PHONY: deb
 deb:
df42e163
 	-@if [ -d debian ]; then \
 		dpkg-buildpackage -rfakeroot -tc; \
 	else \
 		ln -s pkg/debian debian; \
 		dpkg-buildpackage -rfakeroot -tc; \
 		rm debian; \
 	fi
5c6101da
 
bc5cc4ec
 .PHONY: sunpkg
 sunpkg:
91ced801
 	mkdir -p tmp/$(MAIN_NAME)
 	mkdir -p tmp/$(MAIN_NAME)_sun_pkg
 	$(MAKE) install basedir=tmp/$(MAIN_NAME) prefix=/usr/local $(mk_params)
df42e163
 	(cd pkg/solaris; \
91ced801
 	pkgmk -r ../../tmp/$(MAIN_NAME)/usr/local -o -d ../../tmp/$(MAIN_NAME)_sun_pkg/ -v "$(RELEASE)" ;\
df42e163
 	cd ../..)
bc5cc4ec
 	cat /dev/null > ../$(NAME)-$(RELEASE)-$(OS)-$(ARCH)-local
91ced801
 	pkgtrans -s tmp/$(MAIN_NAME)_sun_pkg/ ../$(NAME)-$(RELEASE)-$(OS)-$(ARCH)-local \
 		IPTEL$(MAIN_NAME)
bc5cc4ec
 	gzip -9 ../$(NAME)-$(RELEASE)-$(OS)-$(ARCH)-local
91ced801
 	rm -rf tmp/$(MAIN_NAME)
 	rm -rf tmp/$(MAIN_NAME)_sun_pkg
bc5cc4ec
 
617ced39
 
ecd11721
 .PHONY: install
724ca087
 install: mk_params="compile_for_install=yes"
27cdfd2c
 install: install-bin install-every-module install-cfg \
ee03be75
 	install-doc install-man install-utils install-share
db1b5017
 
e81ea6ce
 .PHONY: dbinstall
 dbinstall:
91ced801
 	-@echo "Initializing $(MAIN_NAME) database"
6f816e54
 	scripts/mysql/$(SCR_NAME)_mysql.sh create
e81ea6ce
 	-@echo "Done"
db1b5017
 
27cdfd2c
 .PHONY: README
 README: $(foreach mods,$(modules_dirs),$(mods)-readme)
 
 .PHONY: man
 man: $(foreach mods,$(modules_dirs),$(mods)-man)
 
28b28d2c
 mk-install_dirs: $(cfg_prefix)/$(cfg_dir) $(bin_prefix)/$(bin_dir) \
 			$(modules_prefix)/$(modules_dir) $(doc_prefix)/$(doc_dir) \
ee03be75
 			$(man_prefix)/$(man_dir)/man8 $(man_prefix)/$(man_dir)/man5 \
27cdfd2c
 			$(share_prefix)/$(share_dir) \
 			$(foreach mods,$(modules_dirs),\
 				$(modules_prefix)/$(modules_dir)$(mods) \
 				$(doc_prefix)/$(doc_dir)$(mods) )
3543f7dc
 
28b28d2c
 $(cfg_prefix)/$(cfg_dir): 
 		mkdir -p $(cfg_prefix)/$(cfg_dir)
db1b5017
 
28b28d2c
 $(bin_prefix)/$(bin_dir):
 		mkdir -p $(bin_prefix)/$(bin_dir)
db1b5017
 
ee03be75
 $(share_prefix)/$(share_dir):
 		mkdir -p $(share_prefix)/$(share_dir)
 
28b28d2c
 $(modules_prefix)/$(modules_dir):
 		mkdir -p $(modules_prefix)/$(modules_dir)
db1b5017
 
28b28d2c
 $(doc_prefix)/$(doc_dir):
 		mkdir -p $(doc_prefix)/$(doc_dir)
db1b5017
 
28b28d2c
 $(man_prefix)/$(man_dir)/man8:
 		mkdir -p $(man_prefix)/$(man_dir)/man8
6ac71d10
 
bb31c7ad
 $(man_prefix)/$(man_dir)/man7:
 		mkdir -p $(man_prefix)/$(man_dir)/man7
 
28b28d2c
 $(man_prefix)/$(man_dir)/man5:
 		mkdir -p $(man_prefix)/$(man_dir)/man5
befa138d
 
eac2c677
 # note: sed with POSIX.1 regex doesn't support |, + or ? (darwin, solaris ...) 
28b28d2c
 install-cfg: $(cfg_prefix)/$(cfg_dir)
a88b7d6f
 		sed $(foreach m,$(modules_dirs),\
6f816e54
 				-e "s#/usr/[^:]*lib/$(CFG_NAME)/$(m)\([:/\"]\)#$($(m)_target)\1#g") \
 			< etc/$(CFG_NAME)-basic.cfg > \
 			$(cfg_prefix)/$(cfg_dir)$(MAIN_NAME).cfg.sample
91ced801
 		chmod 644 $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME).cfg.sample
d48f0d9b
 		if [ -z "${skip_cfg_install}" -a \
91ced801
 				! -f $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME).cfg ]; then \
 			mv -f $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME).cfg.sample \
 				$(cfg_prefix)/$(cfg_dir)$(MAIN_NAME).cfg; \
a2786e3e
 		fi
a88b7d6f
 		sed $(foreach m,$(modules_dirs),\
6f816e54
 			-e "s#/usr/[^:]*lib/$(CFG_NAME)/$(m)\([:/\"]\)#$($(m)_target)\1#g") \
 			< etc/$(CFG_NAME)-oob.cfg \
91ced801
 			> $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-advanced.cfg.sample
 		chmod 644 $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-advanced.cfg.sample
a184875a
 		if [ -z "${skip_cfg_install}" -a \
6f816e54
 				! -f $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-advanced.cfg ]; \
 		then \
91ced801
 			mv -f $(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-advanced.cfg.sample \
 				$(cfg_prefix)/$(cfg_dir)$(MAIN_NAME)-advanced.cfg; \
a184875a
 		fi
b5a32e1a
 		# radius dictionary
6f816e54
 		$(INSTALL_TOUCH) $(cfg_prefix)/$(cfg_dir)/dictionary.$(CFG_NAME)
 		$(INSTALL_CFG) etc/dictionary.$(CFG_NAME) $(cfg_prefix)/$(cfg_dir)
befa138d
 
0e10bff2
 		# TLS configuration
0421ab67
 		$(INSTALL_TOUCH) $(cfg_prefix)/$(cfg_dir)/tls.cfg
3390d4cf
 		#$(INSTALL_CFG) modules/tls/tls.cfg $(cfg_prefix)/$(cfg_dir)
 		#modules/tls/$(SCR_NAME)_cert.sh -d $(cfg_prefix)/$(cfg_dir)
db1b5017
 
28b28d2c
 install-bin: $(bin_prefix)/$(bin_dir) $(NAME)
 		$(INSTALL_TOUCH) $(bin_prefix)/$(bin_dir)/$(NAME)
 		$(INSTALL_BIN) $(NAME) $(bin_prefix)/$(bin_dir)
bbc882db
 
28b28d2c
 
ee03be75
 install-share: $(share_prefix)/$(share_dir)
 	@for r in $(share_install) "" ; do \
 		if [ -n "$$r" ]; then \
 			if [ -f "$$r" ]; then \
bb31c7ad
 				$(call try_err, $(INSTALL_TOUCH) \
 						$(share_prefix)/$(share_dir)/`basename "$$r"` ); \
 				$(call try_err, \
 					$(INSTALL_SHARE)  "$$r"  $(share_prefix)/$(share_dir) );\
ee03be75
 			else \
 				echo "ERROR: $$r not found" ; \
 				if [ ${err_fail} = 1 ] ; then \
 					exit 1; \
 				fi ; \
 			fi ;\
 		fi ; \
 	done; true
 
27cdfd2c
 
 install-every-module: $(foreach mods,$(modules_dirs),install-$(mods))
 
 install-every-module-doc: $(foreach mods,$(modules_dirs),install-$(mods)-doc)
 
 install-every-module-man: $(foreach mods,$(modules_dirs),install-$(mods)-man)
db1b5017
 
28b28d2c
 install-utils: utils $(bin_prefix)/$(bin_dir)
1c5f04ac
 	@for r in $(utils_bin_install) "" ; do \
eddda8ce
 		if [ -n "$$r" ]; then \
 			if [ -f "$$r" ]; then \
bb31c7ad
 				$(call try_err, $(INSTALL_TOUCH) \
 						$(bin_prefix)/$(bin_dir)/`basename "$$r"` ); \
 				$(call try_err,\
 					$(INSTALL_BIN)  "$$r"  $(bin_prefix)/$(bin_dir) ); \
eddda8ce
 			else \
 				echo "ERROR: $$r not compiled" ; \
3f93b05e
 				if [ ${err_fail} = 1 ] ; then \
 					exit 1; \
 				fi ; \
eddda8ce
 			fi ;\
 		fi ; \
3f93b05e
 	done; true
1c5f04ac
 	@for r in $(utils_script_install) "" ; do \
 		if [ -n "$$r" ]; then \
 			if [ -f "$$r" ]; then \
bb31c7ad
 				$(call try_err, $(INSTALL_TOUCH) \
 						$(bin_prefix)/$(bin_dir)/`basename "$$r"` ); \
 				$(call try_err,\
 					$(INSTALL_SCRIPT)  "$$r"  $(bin_prefix)/$(bin_dir) ); \
1c5f04ac
 			else \
 				echo "ERROR: $$r not compiled" ; \
 				if [ ${err_fail} = 1 ] ; then \
 					exit 1; \
 				fi ; \
 			fi ;\
 		fi ; \
 	done; true
ee03be75
 	# FIXME: This is a hack, this should be (and will be) done properly in
     # per-module Makefiles
 	sed -e "s#^DEFAULT_SCRIPT_DIR.*#DEFAULT_SCRIPT_DIR=\"$(share_prefix)/$(share_dir)\"#g" \
6f816e54
 		< scripts/mysql/$(SCR_NAME)_mysql.sh > \
 			$(bin_prefix)/$(bin_dir)/$(MAIN_NAME)_mysql.sh
91ced801
 	chmod 755 $(bin_prefix)/$(bin_dir)/$(MAIN_NAME)_mysql.sh
eddda8ce
 
db1b5017
 
27cdfd2c
 install-modules-all: install-every-module install-every-module-doc
d48f0d9b
 
 
27cdfd2c
 install-doc: $(doc_prefix)/$(doc_dir) install-every-module-doc
28b28d2c
 	$(INSTALL_TOUCH) $(doc_prefix)/$(doc_dir)/INSTALL 
 	$(INSTALL_DOC) INSTALL $(doc_prefix)/$(doc_dir)
08067fd5
 	$(INSTALL_TOUCH) $(doc_prefix)/$(doc_dir)/README-MODULES 
 	$(INSTALL_DOC) README-MODULES $(doc_prefix)/$(doc_dir)
28b28d2c
 	$(INSTALL_TOUCH) $(doc_prefix)/$(doc_dir)/AUTHORS 
 	$(INSTALL_DOC) AUTHORS $(doc_prefix)/$(doc_dir)
 	$(INSTALL_TOUCH) $(doc_prefix)/$(doc_dir)/NEWS
 	$(INSTALL_DOC) NEWS $(doc_prefix)/$(doc_dir)
 	$(INSTALL_TOUCH) $(doc_prefix)/$(doc_dir)/README 
 	$(INSTALL_DOC) README $(doc_prefix)/$(doc_dir)
d48f0d9b
 
 
6f816e54
 install-sr-man: $(man_prefix)/$(man_dir)/man8 $(man_prefix)/$(man_dir)/man5
 		sed -e "s#/etc/$(CFG_NAME)/$(CFG_NAME)\.cfg#$(cfg_target)$(MAIN_NAME).cfg#g" \
28b28d2c
 			-e "s#/usr/sbin/#$(bin_target)#g" \
a88b7d6f
 			$(foreach m,$(modules_dirs),\
6f816e54
 				-e "s#/usr/lib/$(CFG_NAME)/$(m)\([^_]\)#$($(m)_target)\1#g") \
 			-e "s#/usr/share/doc/$(CFG_NAME)/#$(doc_target)#g" \
 			< $(CFG_NAME).8 >  \
 							$(man_prefix)/$(man_dir)/man8/$(MAIN_NAME).8
91ced801
 		chmod 644  $(man_prefix)/$(man_dir)/man8/$(MAIN_NAME).8
6f816e54
 		sed -e "s#/etc/$(CFG_NAME)/$(CFG_NAME)\.cfg#$(cfg_target)$(MAIN_NAME).cfg#g" \
28b28d2c
 			-e "s#/usr/sbin/#$(bin_target)#g" \
a88b7d6f
 			$(foreach m,$(modules_dirs),\
6f816e54
 				-e "s#/usr/lib/$(CFG_NAME)/$(m)\([^_]\)#$($(m)_target)\1#g") \
 			-e "s#/usr/share/doc/$(CFG_NAME)/#$(doc_target)#g" \
 			< $(CFG_NAME).cfg.5 >  \
 			$(man_prefix)/$(man_dir)/man5/$(MAIN_NAME).cfg.5
91ced801
 		chmod 644  $(man_prefix)/$(man_dir)/man5/$(MAIN_NAME).cfg.5
52bcc791
 
6f816e54
 install-man:  install-sr-man install-every-module-man
bb31c7ad
 
 
52bcc791
 
8ca5d8dd
 # libs cleaning targets
 .PHONY: clean-libs
 clean-libs:
 			$(MAKE) -C lib clean
52bcc791
 
8ca5d8dd
 .PHONY: proper-libs realclean-libs distclean-libs maintainer-clean-libs
 proper-libs realclean-libs distclean-libs maintainer-clean-libs:
 			$(MAKE) -C lib $(patsubst %-libs,%,$@)
52bcc791
 
97915408
 
8ca5d8dd
 # clean modules on make clean
 clean: clean-modules
 # clean utils on make clean
 clean: clean-utils
5d1a75a6
 # cleaning in libs always when cleaning sip-router
8ca5d8dd
 clean: clean-libs
 
 # proper/distclean a.s.o modules, utils and libs too
 
 proper: proper-modules proper-utils proper-libs
 distclean: distclean-modules distclean-utils distclean-libs
 realclean: realclean-modules realclean-utils realclean-libs
 maintainer-clean: maintainer-clean-modules maintainer-clean-utils \
  maintainer-clean-libs
52bcc791
 
299781b1
 #try to clean everything (including all the modules, even ones that are not
 # configured/compiled normally
 .PHONY: clean-all
27cdfd2c
 clean-all: cmodules=$(all_modules_lst)
299781b1
 clean-all: clean
8ca5d8dd
 maintainer-clean: modules=$(modules_all)
299781b1
 
0bd6adc6
 # on make proper clean also the build config (w/o module list)
8ca5d8dd
 proper realclean distclean maintainer-clean: clean_cfg
7742b1d2
 
0bd6adc6
 # on maintainer clean, remove also the configured module list
 maintainer-clean: clean_modules_cfg
 
299781b1
 .PHONY: proper-all realclean-all distclean-all
27cdfd2c
 proper-all realclean-all distclean-all: cmodules=$(all_modules_lst)
299781b1
 proper-all realclean-all distclean-all: proper
 
 
3f52ab26
 .PHONY: clean_cfg clean-cfg
 clean_cfg clean-cfg:
7742b1d2
 	rm -f config.mak
 
0bd6adc6
 .PHONY: clean_modules_cfg clean-modules-cfg
 clean_modules_cfg clean-modules-cfg:
 	rm -f modules.lst