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 
 #                  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)
56c2dabd
 #
e60a9728
 
96001c50
 auto_gen=lex.yy.c cfg.tab.c   #lexx, yacc etc
247c2b65
 
 #include  source related defs
 include Makefile.sources
 
d48f0d9b
 # whether or not to install ser.cfg or just ser.cfg.default
 # (ser.cfg will never be overwritten by make install, this is usefull
 #  when creating packages)
 skip_cfg_install?=
 
fc50bc47
 #extra modules to exclude
 skip_modules?=
 
 # if not set on the cmd. line or the env, exclude this modules:
c05b9131
 exclude_modules?= 			cpl cpl-c ext extcmd mangler pdt \
a9cd95b5
 							postgres snmp \
fc50bc47
 							im radius_acc radius_auth \
c05b9131
 							jabber mysql \
fc50bc47
 							auth_radius group_radius uri_radius 
 # always exclude the CVS dir
 override exclude_modules+= CVS $(skip_modules)
 
 #always include this modules
 include_modules?=
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
 #
c64e586d
 static_modules=
404073d3
 static_modules_path=$(addprefix modules/, $(static_modules))
 extra_sources=$(wildcard $(addsuffix /*.c, $(static_modules_path)))
 extra_objs=$(extra_sources:.c=.o)
 
 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
 
404073d3
 modules=$(filter-out $(addprefix modules/, \
 			$(exclude_modules) $(static_modules)), \
 			$(wildcard modules/*))
fc50bc47
 modules:=$(filter-out $(modules), $(addprefix modules/, $(include_modules) )) \
 			$(modules)
6ac71d10
 modules_names=$(shell echo $(modules)| \
 				sed -e 's/modules\/\([^/ ]*\)\/*/\1.so/g' )
addb384d
 modules_basenames=$(shell echo $(modules)| \
 				sed -e 's/modules\/\([^/ ]*\)\/*/\1/g' )
6ac71d10
 #modules_names=$(patsubst modules/%, %.so, $(modules))
 modules_full_path=$(join  $(modules), $(addprefix /, $(modules_names)))
e60a9728
 
f20a56a2
 NAME=ser
e60a9728
 
247c2b65
 ALLDEP=Makefile Makefile.sources Makefile.defs Makefile.rules
f8734075
 
247c2b65
 #include general defs (like CC, CFLAGS  a.s.o)
3dae72a3
 # hack to force makefile.defs re-inclusion (needed when make calls itself with
 # other options -- e.g. make bin)
 makefile_defs=0
 DEFS:=
247c2b65
 include Makefile.defs
0ae4dfdc
 
247c2b65
 #export relevant variables to the sub-makes
 export DEFS PROFILE CC  LD MKDEP MKTAGS CFLAGS LDFLAGS MOD_CFLAGS MOD_LDFLAGS
 export LEX YACC YACC_FLAGS
56c2dabd
 export PREFIX LOCALBASE
3dae72a3
 # export relevant variables for recursive calls of this makefile 
 # (e.g. make deb)
 #export LIBS
 #export TAR 
 #export NAME RELEASE OS ARCH 
 #export cfg-prefix cfg-dir bin-prefix bin-dir modules-prefix modules-dir
 #export doc-prefix doc-dir man-prefix man-dir ut-prefix ut-dir
 #export cfg-target modules-target
 #export INSTALL INSTALL-CFG INSTALL-BIN INSTALL-MODULES INSTALL-DOC INSTALL-MAN 
 #export INSTALL-TOUCH
0ae4dfdc
 
04bb7a49
 
247c2b65
 # include the common rules
 include Makefile.rules
e60a9728
 
247c2b65
 #extra targets 
3e429f5c
 
04bb7a49
 $(NAME): static_modules
 
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) $<
 
e60a9728
 .PHONY: all
96001c50
 all: $(NAME) modules
e60a9728
 
404073d3
 
96001c50
 
 .PHONY: modules
 modules:
e7a9bd30
 	-@for r in $(modules) "" ; do \
 		if [ -n "$$r" ]; then \
 			echo  "" ; \
 			echo  "" ; \
 			$(MAKE) -C $$r ; \
 		fi ; \
 	done 
404073d3
 
 .PHONY: static_modules
 static_modules:
e7a9bd30
 	-@echo "Extra objs: $(extra_objs)" 
 	-@for r in $(static_modules_path) "" ; do \
 		if [ -n "$$r" ]; then \
 			echo  "" ; \
 			echo  "Making static module $r" ; \
 			$(MAKE) -C $$r static ; \
 		fi ; \
 	done 
404073d3
 
 
247c2b65
 	
f571aa35
 dbg: ser
 	gdb -command debug.gdb
247c2b65
 
0bafb279
 .PHONY: tar
31521f89
 .PHONY: dist
 
 dist: tar
 
 tar: 
054cb6cf
 	$(TAR) -C .. \
3dae72a3
 		--exclude=$(notdir $(CURDIR))/test* \
 		--exclude=$(notdir $(CURDIR))/tmp* \
 		--exclude=$(notdir $(CURDIR))/debian/ser* \
e8f8146e
 		--exclude=$(notdir $(CURDIR))/tls* \
 		--exclude=$(notdir $(CURDIR))/ser_tls* \
3dae72a3
 		--exclude=CVS* \
31521f89
 		--exclude=*.[do] \
 		--exclude=*.so \
 		--exclude=*.il \
 		--exclude=$(notdir $(CURDIR))/ser \
 		--exclude=*.gz \
 		--exclude=*.bz2 \
 		--exclude=*.tar \
 		-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) \
31521f89
 			                    -zcf ../../"$(NAME)-$(RELEASE)_src".tar.gz \
 			                               "$(NAME)-$(RELEASE)" ) ; \
696ba02d
 			    rm -rf tmp/_tar1; rm -rf tmp/_tar2
0bafb279
 
 # binary dist. tar.gz
 .PHONY: bin
 bin:
 	mkdir -p tmp/ser/usr/local
054cb6cf
 	$(MAKE) install basedir=tmp/ser prefix=/usr/local 
0bafb279
 	$(TAR) -C tmp/ser/ -zcf ../$(NAME)-$(RELEASE)_$(OS)_$(ARCH).tar.gz .
 	rm -rf tmp/ser
04bb7a49
 
5c6101da
 .PHONY: deb
 deb:
054cb6cf
 	dpkg-buildpackage -rfakeroot -tc
5c6101da
 
bc5cc4ec
 .PHONY: sunpkg
 sunpkg:
 	mkdir -p tmp/ser
 	mkdir -p tmp/ser_sun_pkg
054cb6cf
 	$(MAKE) install basedir=tmp/ser prefix=/usr/local
bc5cc4ec
 	(cd solaris; \
054cb6cf
 	pkgmk -r ../tmp/ser/usr/local -o -d ../tmp/ser_sun_pkg/ -v "$(RELEASE)" ;\
bc5cc4ec
 	cd ..)
 	cat /dev/null > ../$(NAME)-$(RELEASE)-$(OS)-$(ARCH)-local
 	pkgtrans -s tmp/ser_sun_pkg/ ../$(NAME)-$(RELEASE)-$(OS)-$(ARCH)-local \
 		IPTELser
 	gzip -9 ../$(NAME)-$(RELEASE)-$(OS)-$(ARCH)-local
 	rm -rf tmp/ser
 	rm -rf tmp/ser_sun_pkg
 
04bb7a49
 
db1b5017
 install: all mk-install-dirs install-cfg install-bin install-modules \
6ac71d10
 	install-doc install-man
db1b5017
 
e81ea6ce
 .PHONY: dbinstall
 dbinstall:
 	-@echo "Initializing ser database"
 	scripts/ser_mysql.sh create
 	-@echo "Done"
db1b5017
 
 mk-install-dirs: $(cfg-prefix)/$(cfg-dir) $(bin-prefix)/$(bin-dir) \
6ac71d10
 			$(modules-prefix)/$(modules-dir) $(doc-prefix)/$(doc-dir) \
 			$(man-prefix)/$(man-dir)/man8 $(man-prefix)/$(man-dir)/man5
db1b5017
 
 $(cfg-prefix)/$(cfg-dir): 
 		mkdir -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)
 
6ac71d10
 $(man-prefix)/$(man-dir)/man8:
 		mkdir -p $(man-prefix)/$(man-dir)/man8
 
 $(man-prefix)/$(man-dir)/man5:
 		mkdir -p $(man-prefix)/$(man-dir)/man5
f742de6a
 		
 # note: on solaris 8 sed: ? or \(...\)* (a.s.o) do not work
054cb6cf
 install-cfg: $(cfg-prefix)/$(cfg-dir)
f742de6a
 		sed -e "s#/usr/.*lib/ser/modules/#$(modules-target)#g" \
d48f0d9b
 			< etc/ser.cfg > $(cfg-prefix)/$(cfg-dir)ser.cfg.sample
 		chmod 644 $(cfg-prefix)/$(cfg-dir)ser.cfg.sample
 		if [ -z "${skip_cfg_install}" -a \
 				! -f $(cfg-prefix)/$(cfg-dir)ser.cfg ]; then \
 			mv -f $(cfg-prefix)/$(cfg-dir)ser.cfg.sample \
a2786e3e
 				$(cfg-prefix)/$(cfg-dir)ser.cfg; \
 		fi
054cb6cf
 #		$(INSTALL-CFG) etc/ser.cfg $(cfg-prefix)/$(cfg-dir)
db1b5017
 
054cb6cf
 install-bin: $(bin-prefix)/$(bin-dir) utils/gen_ha1/gen_ha1
15dde484
 		$(INSTALL-TOUCH) $(bin-prefix)/$(bin-dir)/ser 
db1b5017
 		$(INSTALL-BIN) ser $(bin-prefix)/$(bin-dir)
15dde484
 		$(INSTALL-TOUCH)   $(bin-prefix)/$(bin-dir)/sc
 		$(INSTALL-BIN) scripts/sc $(bin-prefix)/$(bin-dir)
 		mv -f $(bin-prefix)/$(bin-dir)/sc $(bin-prefix)/$(bin-dir)/serctl
 		$(INSTALL-TOUCH)   $(bin-prefix)/$(bin-dir)/ser_mysql.sh  
054cb6cf
 		$(INSTALL-BIN) scripts/ser_mysql.sh  $(bin-prefix)/$(bin-dir)
15dde484
 		$(INSTALL-TOUCH)   $(bin-prefix)/$(bin-dir)/gen_ha1
054cb6cf
 		$(INSTALL-BIN) utils/gen_ha1/gen_ha1 $(bin-prefix)/$(bin-dir)
db1b5017
 
054cb6cf
 utils/gen_ha1/gen_ha1:
 		cd utils/gen_ha1; $(MAKE) all
db1b5017
 
054cb6cf
 install-modules: modules $(modules-prefix)/$(modules-dir)
db1b5017
 	-@for r in $(modules_full_path) "" ; do \
 		if [ -n "$$r" ]; then \
15dde484
 			if [ -f "$$r" ]; then \
 				$(INSTALL-TOUCH) \
 					$(modules-prefix)/$(modules-dir)/`basename "$$r"` ; \
 				$(INSTALL-MODULES)  "$$r"  $(modules-prefix)/$(modules-dir) ; \
 			else \
 				echo "ERROR: module $$r not compiled" ; \
 			fi ;\
db1b5017
 		fi ; \
 	done 
 
 
d48f0d9b
 install-modules-all: install-modules install-modules-doc
 
 
 install-doc: $(doc-prefix)/$(doc-dir) install-modules-doc
15dde484
 	$(INSTALL-TOUCH) $(doc-prefix)/$(doc-dir)/INSTALL 
5b0cb4c6
 	$(INSTALL-DOC) INSTALL $(doc-prefix)/$(doc-dir)
15dde484
 	$(INSTALL-TOUCH) $(doc-prefix)/$(doc-dir)/README-MODULES 
4490b8e2
 	$(INSTALL-DOC) README-MODULES $(doc-prefix)/$(doc-dir)
15dde484
 	$(INSTALL-TOUCH) $(doc-prefix)/$(doc-dir)/AUTHORS 
d615a5cd
 	$(INSTALL-DOC) AUTHORS $(doc-prefix)/$(doc-dir)
0cec5ece
 	$(INSTALL-TOUCH) $(doc-prefix)/$(doc-dir)/NEWS
 	$(INSTALL-DOC) NEWS $(doc-prefix)/$(doc-dir)
d48f0d9b
 	$(INSTALL-TOUCH) $(doc-prefix)/$(doc-dir)/README 
 	$(INSTALL-DOC) README $(doc-prefix)/$(doc-dir)
 
 
 install-modules-doc: $(doc-prefix)/$(doc-dir)
addb384d
 	-@for r in $(modules_basenames) "" ; do \
 		if [ -n "$$r" ]; then \
 			if [ -f modules/"$$r"/README ]; then \
15dde484
 				$(INSTALL-TOUCH)  $(doc-prefix)/$(doc-dir)/README ; \
addb384d
 				$(INSTALL-DOC)  modules/"$$r"/README  \
15dde484
 									$(doc-prefix)/$(doc-dir)/README ; \
 				mv -f $(doc-prefix)/$(doc-dir)/README \
 						$(doc-prefix)/$(doc-dir)/README."$$r" ; \
addb384d
 			fi ; \
 		fi ; \
 	done 
d48f0d9b
 
db1b5017
 
054cb6cf
 install-man: $(man-prefix)/$(man-dir)/man8 $(man-prefix)/$(man-dir)/man5
15dde484
 	$(INSTALL-TOUCH)  $(man-prefix)/$(man-dir)/man8/ser.8 
6ac71d10
 	$(INSTALL-MAN)  ser.8 $(man-prefix)/$(man-dir)/man8
15dde484
 	$(INSTALL-TOUCH)  $(man-prefix)/$(man-dir)/man5/ser.cfg.5 
6ac71d10
 	$(INSTALL-MAN)  ser.cfg.5 $(man-prefix)/$(man-dir)/man5
db1b5017