# # Makefile for Zaptel driver modules and utilities # # Copyright (C) 2001-2007 Digium, Inc. # # CFLAGS+=-DSTANDALONE_ZAPATA -DBUILDING_TONEZONE ifeq ($(MAKELEVEL),0) PWD:=$(shell pwd) endif ARCH:=$(shell uname -m | sed -e s/i.86/i386/) ifeq ($(DEB_HOST_GNU_TYPE),) UNAME_M:=$(shell uname -m) else UNAME_M:=$(DEB_HOST_GNU_TYPE) endif # If you want to build for a kernel other than the current kernel, set KVERS ifndef KVERS KVERS:=$(shell uname -r) endif ifndef KSRC ifneq (,$(wildcard /lib/modules/$(KVERS)/build)) KSRC:=/lib/modules/$(KVERS)/build else KSRC_SEARCH_PATH:=/usr/src/linux-2.4 /usr/src/linux KSRC:=$(shell for dir in $(KSRC_SEARCH_PATH); do if [ -d $$dir ]; then echo $$dir; break; fi; done) endif endif KVERS_MAJ:=$(shell echo $(KVERS) | cut -d. -f1-2) KINCLUDES:=$(KSRC)/include ifeq ($(KVERS_MAJ),2.4) BUILDVER:=linux24 else BUILDVER:=linux26 endif # Set HOTPLUG_FIRMWARE=no to override automatic building with hotplug support # if it is enabled in the kernel. ifeq ($(BUILDVER),linux26) ifneq (,$(wildcard $(DESTDIR)/etc/udev/rules.d)) DYNFS=yes UDEVRULES=yes endif HOTPLUG_FIRMWARE:=$(shell if grep CONFIG_FW_LOADER $(KINCLUDES)/linux/autoconf.h | grep -q undef; then echo "no"; else echo "yes"; fi) else # Hotplug firmware loading is not supported on any other version then 2.6 HOTPLUG_FIRMWARE:=no endif ifeq ($(HOTPLUG_FIRMWARE),yes) CFLAGS+=-DHOTPLUG_FIRMWARE endif ifeq ($(ARCH),i386) ifneq ($(wildcard $(PWD)/hpec/hpec_x86_32.o_shipped),) HPEC_PRESENT=yes endif endif ifeq ($(ARCH),x86_64) ifneq ($(wildcard $(PWD)/hpec/hpec_x86_64.o_shipped),) HPEC_PRESENT=yes endif endif # If the file .zaptel.makeopts is present in your home directory, you can # include all of your favorite menuselect options so that every time you download # a new version of Asterisk, you don't have to run menuselect to set them. # The file /etc/zaptel.makeopts will also be included but can be overridden # by the file in your home directory. GLOBAL_MAKEOPTS=$(wildcard /etc/zaptel.makeopts) USER_MAKEOPTS=$(wildcard ~/.zaptel.makeopts) ifeq ($(strip $(foreach var,clean distclean dist-clean update,$(findstring $(var),$(MAKECMDGOALS)))),) ifneq ($(wildcard menuselect.makeopts),) include menuselect.makeopts endif endif ifeq ($(strip $(foreach var,clean distclean dist-clean update,$(findstring $(var),$(MAKECMDGOALS)))),) ifneq ($(wildcard makeopts),) include makeopts endif endif ifeq ($(BUILDVER),linux24) MENUSELECT_MODULES+=xpp wctc4xxp wctdm24xxp zttranscode endif ifeq ($(findstring xpp,$(MENUSELECT_MODULES)),) BUILD_XPP:=yes endif SUBDIRS_UTILS_ALL:= xpp/utils ppp SUBDIRS_UTILS := ifeq ($(BUILD_XPP),yes) SUBDIRS_UTILS += xpp/utils endif #SUBDIRS_UTILS += ppp TOPDIR_MODULES:=pciradio tor2 torisa wcfxo wct1xxp wctdm wcte11xp wcusb zaptel ztd-eth ztd-loc ztdummy ztdynamic zttranscode SUBDIR_MODULES:=wct4xxp wctc4xxp xpp wctdm24xxp wcte12xp TOPDIR_MODULES+=$(MODULES_EXTRA) SUBDIR_MODULES+=$(SUBDIRS_EXTRA) BUILD_TOPDIR_MODULES:=$(filter-out $(MENUSELECT_MODULES),$(TOPDIR_MODULES)) BUILD_SUBDIR_MODULES:=$(filter-out $(MENUSELECT_MODULES),$(SUBDIR_MODULES)) BUILD_MODULES:=$(BUILD_TOPDIR_MODULES) $(BUILD_SUBDIR_MODULES) MOD_DESTDIR:=zaptel #NOTE NOTE NOTE # # all variables set before the include of Makefile.kernel26 are needed by the 2.6 kernel module build process ifneq ($(KBUILD_EXTMOD),) obj-m:=$(BUILD_TOPDIR_MODULES:%=%.o) obj-m+=$(BUILD_SUBDIR_MODULES:%=%/) include $(src)/Makefile.kernel26 else ifeq ($(BUILDVER),linux24) INSTALL_MODULES:=$(BUILD_TOPDIR_MODULES:%=%.o) INSTALL_MODULES+=$(foreach mod,$(BUILD_SUBDIR_MODULES),$(mod)/$(mod).o) ALL_MODULES:=$(TOPDIR_MODULES:%=%.o) ALL_MODULES+=$(SUBDIR_MODULES:%=%/%.o) else INSTALL_MODULES:=$(BUILD_TOPDIR_MODULES:%=%.ko) INSTALL_MODULES+=$(foreach mod,$(filter-out xpp,$(BUILD_SUBDIR_MODULES)),$(mod)/$(mod).ko) ifneq ($(filter xpp,$(BUILD_SUBDIR_MODULES)),) INSTALL_MODULES+=$(patsubst %,xpp/%.ko,xpp_usb xpd_fxo xpd_fxs xpp) endif ALL_MODULES:=$(TOPDIR_MODULES:%=%.ko) ALL_MODULES+=$(foreach mod,$(filter-out xpp,$(SUBDIR_MODULES)),$(mod)/$(mod).ko) ALL_MODULES+=$(patsubst %,xpp/%.ko,xpp_usb xpd_fxo xpd_fxs xpp) endif OPTFLAG=-O2 CFLAGS+=-I. $(OPTFLAGS) -g -fPIC -Wall -DBUILDING_TONEZONE #-DTONEZONE_DRIVER ifneq (,$(findstring ppc,$(UNAME_M))) CFLAGS_PPC:=-fsigned-char endif ifneq (,$(findstring x86_64,$(UNAME_M))) CFLAGS_x86_64:=-m64 endif CFLAGS+=$(CFLAGS_PPC) $(CFLAGS_x86_64) KFLAGS=-I$(KINCLUDES) -O6 KFLAGS+=-DMODULE -D__KERNEL__ -DEXPORT_SYMTAB -I$(KSRC)/drivers/net \ -Wall -I. -Wstrict-prototypes -fomit-frame-pointer -I$(KSRC)/drivers/net/wan -I$(KINCLUDES)/net ifneq (,$(wildcard $(KINCLUDES)/linux/modversions.h)) KFLAGS+=-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h endif ifneq (,$(findstring ppc,$(UNAME_M))) KFLAGS_PPC:=-msoft-float -fsigned-char endif KFLAGS+=$(KFLAGS_PPC) ifeq ($(KVERS_MAJ),2.4) ifneq (,$(findstring x86_64,$(UNAME_M))) KFLAGS+=-mcmodel=kernel endif endif # # Features are now configured in zconfig.h # MODULE_ALIASES=wcfxs wctdm8xxp wct2xxp KFLAGS+=-DSTANDALONE_ZAPATA CFLAGS+=-DSTANDALONE_ZAPATA KMAKE = $(MAKE) -C $(KSRC) SUBDIRS=$(PWD) HOTPLUG_FIRMWARE=$(HOTPLUG_FIRMWARE) KMAKE_INST = $(KMAKE) \ INSTALL_MOD_PATH=$(DESTDIR) INSTALL_MOD_DIR=misc modules_install ROOT_PREFIX= CONFIG_FILE=/etc/zaptel.conf CFLAGS+=-DZAPTEL_CONFIG=\"$(CONFIG_FILE)\" # sample makefile "trace print" #tracedummy=$(shell echo ====== GOT HERE ===== >&2; echo >&2) CHKCONFIG := $(wildcard /sbin/chkconfig) UPDATE_RCD := $(wildcard /usr/sbin/update-rc.d) ifeq (,$(DESTDIR)) ifneq (,$(CHKCONFIG)) ADD_INITD := $(CHKCONFIG) --add zaptel else ifndef (,$(UPDATE_RCD)) ADD_INITD := $(UPDATE_RCD) zaptel defaults 15 30 endif endif endif INITRD_DIR := $(firstword $(wildcard /etc/rc.d/init.d /etc/init.d)) ifneq (,$(INITRD_DIR)) INIT_TARGET := $(DESTDIR)$(INITRD_DIR)/zaptel COPY_INITD := install -D zaptel.init $(INIT_TARGET) endif RCCONF_DIR := $(firstword $(wildcard /etc/sysconfig /etc/default)) NETSCR_DIR := $(firstword $(wildcard /etc/sysconfig/network-scripts )) ifneq (,$(NETSCR_DIR)) NETSCR_TARGET := $(DESTDIR)$(NETSCR_DIR)/ifup-hdlc COPY_NETSCR := install -D ifup-hdlc $(NETSCR_TARGET) endif ifneq ($(wildcard .version),) ZAPTELVERSION:=$(shell cat .version) else ifneq ($(wildcard .svn),) ZAPTELVERSION=SVN-$(shell build_tools/make_svn_branch_name) endif endif LTZ_A:=libtonezone.a LTZ_A_OBJS:=zonedata.o tonezone.o LTZ_SO:=libtonezone.so LTZ_SO_OBJS:=zonedata.lo tonezone.lo LTZ_SO_MAJOR_VER:=1 LTZ_SO_MINOR_VER:=0 # libdir, includedir and mandir are defined in makeopts (from # configure). # we use /sbin, rather than configure's $(sbindir) because we use /sbin # for historical reasons. BIN_DIR:=/sbin LIB_DIR:=$(libdir) INC_DIR:=$(includedir)/zaptel MAN_DIR:=$(mandir)/man8 MOD_DIR:=$(DESTDIR)/lib/modules/$(KVERS)/misc # Utilities we build with a standard build procedure: UTILS = zttool zttest ztmonitor ztspeed sethdlc-new ztcfg \ ztcfg-dude usbfxstest fxstest fxotune ztdiag torisatool \ ztscan # Makefile mentions them. Source is not included (anynore?) UTILS += fxsdump ztprovision # some tests: UTILS += patgen pattest patlooptest hdlcstress hdlctest hdlcgen \ hdlcverify timertest UTILSO = $(UTILS:%=%.o) BINS:=fxotune fxstest sethdlc-new ztcfg ztdiag ztmonitor ztspeed zttest ztscan ifeq (1,$(PBX_LIBNEWT)) BINS+=zttool endif BINS:=$(filter-out $(MENUSELECT_UTILS),$(BINS)) MAN_PAGES:=$(wildcard $(BINS:%=doc/%.8)) all: menuselect.makeopts @$(MAKE) _all _all: $(if $(BUILD_MODULES),modules) programs libs: $(LTZ_SO) $(LTZ_A) utils-subdirs: @for dir in $(SUBDIRS_UTILS); do \ $(MAKE) -C $$dir; \ done programs: libs utils utils: $(BINS) utils-subdirs modules: prereq @if [ -z "$(KSRC)" -o ! -d "$(KSRC)" ]; then echo "You do not appear to have the sources for the $(KVERS) kernel installed."; exit 1 ; fi ifeq ($(BUILDVER),linux26) $(KMAKE) modules else modules: $(INSTALL_MODULES) endif ifeq ($(HPEC_PRESENT),yes) ifeq ($(ARCH),i386) ZAPTEL_HPEC:=hpec/hpec_x86_32.o_shipped endif ifeq ($(ARCH),x86_64) ZAPTEL_HPEC:=hpec/hpec_x86_64.o_shipped endif KFLAGS+=-DECHO_CAN_HPEC -I$(PWD)/hpec zaptel-base.o: hpec/hpec_zaptel.h hpec/hpec_user.h endif version.h: @ZAPTELVERSION="${ZAPTELVERSION}" build_tools/make_version_h > $@.tmp @if cmp -s $@.tmp $@ ; then :; else \ mv $@.tmp $@ ; \ fi @rm -f $@.tmp tests: patgen pattest patlooptest hdlcstress hdlctest hdlcgen hdlcverify timertest zonedata.lo: zonedata.c $(CC) -c $(CFLAGS) -o $@ $^ tonezone.lo: tonezone.c $(CC) -c $(CFLAGS) -o $@ $^ tor2fw.h: tormenta2.rbt makefw ./makefw $< tor2fw > $@ radfw.h: pciradio.rbt makefw ./makefw $< radfw > $@ makefw: makefw.c $(HOSTCC) -o $@ $^ prereq: config.status tor2fw.h radfw.h version.h zttool.o: zaptel.h zttool.o: CFLAGS+=$(NEWT_INCLUDE) zttool: LDLIBS+=$(NEWT_LIB) ztscan.o: zaptel.h ztprovision.o: zaptel.h ztmonitor.o: zaptel.h ztspeed: CFLAGS= sethdlc-new: CFLAGS+=-I$(KINCLUDES) $(LTZ_A): $(LTZ_A_OBJS) ar rcs $@ $^ ranlib $@ $(LTZ_SO): $(LTZ_SO_OBJS) $(CC) $(CFLAGS) -shared -Wl,-soname,$(LTZ_SO).$(LTZ_SO_MAJOR_VER).$(LTZ_SO_MINOR_VER) -o $@ $^ $(LDFLAGS) $(LDLIBS) -lm ztcfg.o: ztcfg.h zaptel.h ztcfg: ztcfg.o $(LTZ_A) ztcfg: LDLIBS+=-lm ztcfg-shared: ztcfg.o $(LTZ_SO) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS) -lm ztcfg-dude: ztcfg-dude.o mknotch.o complex.o $(LTZ_SO) ztcfg-dude: LDLIBS+=-lm -lstdc++ data: $(MAKE) -C datamods datamods # FIXME: we assume CC can build the C++ modules: complex.o mknotch.o: %.o: %.cc $(CC) $(CFLAGS) -o $@ -c $< usbfxstest: LDLIBS+=-lzap fxstest: $(LTZ_SO) fxstest: LDLIBS+=-lm fxotune: LDLIBS+=-lm fxsdump: LDLIBS+=-lm ifeq ($(BUILDVER),linux24) wct4xxp/wct4xxp.o: $(MAKE) -C wct4xxp KFLAGS="$(KFLAGS) -I.." CFLAGS="$(CFLAGS) -I.." tor2.o: tor2-hw.h tor2fw.h zaptel-base.o: digits.h arith.h sec.h sec-2.h kb1ec.h mg2ec.h zconfig.h wcusb.o: wcusb.h wctdm.o: wctdm.h wctdm24xxp/wctdm24xxp.o: $(MAKE) -C wctdm24xxp KFLAGS="$(KFLAGS) -I.." CFLAGS="$(CFLAGS) -I.." wcte12xp/wcte12xp.o: $(MAKE) -C wcte12xp KFLAGS="$(KFLAGS) -I.." CFLAGS="$(CFLAGS) -I.." pciradio.o: radfw.h ztdummy.o: ztdummy.h zaptel.o: zaptel-base.o $(ZAPTEL_HPEC) $(LD) -r -o $@ $< $(ZAPTEL_HPEC) $(filter-out zaptel.o,$(BUILD_TOPDIR_MODULES:%=%.o)) zaptel-base.o: %.o: %.c zaptel.h $(CC) $(KFLAGS) -o $@ -c $< endif stackcheck: checkstack modules ./checkstack *.ko */*.ko README.html: README $(ASCIIDOC) -n -a toc -a toclevel=3 $< xpp/README.Astribank.html: xpp/README.Astribank cd $(@D); $(ASCIIDOC) -o $(@F) -n -a toc $( $(DESTDIR)/etc/udev/rules.d/zaptel.rules else # !UDEVRULES @echo "**** Dynamic filesystem detected -- not creating device nodes" endif endif install-udev: devices uninstall-hotplug: $(MAKE) -C firmware hotplug-uninstall DESTDIR=$(DESTDIR) BASENAMES=$(sort $(shell for x in $(ALL_MODULES); do basename $x; done)) uninstall-modules: ifeq ($(BUILDVER),linux24) else @./build_tools/uninstall-modules $(DESTDIR)/lib/modules/$(KVERS) $(BASENAMES) @for x in $(ALL_MODULES); do \ rm -f $(DESTDIR)/lib/modules/$(KVERS)/extra/$$x ; \ rm -f $(DESTDIR)/lib/modules/$(KVERS)/misc/$$x ; \ rm -f $(DESTDIR)/lib/modules/$(KVERS)/zaptel/$$x ; \ done; endif BASENAMES=$(sort $(shell for mod in $(ALL_MODULES); do basename $$mod; done)) install-modules: $(INSTALL_MODULES) uninstall-modules ifeq ($(BUILDVER),linux24) $(INSTALL) -d $(DESTDIR)$(MOD_DIR) $(INSTALL) -m 644 $(INSTALL_MODULES) $(DESTDIR)$(MOD_DIR) else $(KMAKE_INST) ifneq (,$(wildcard datamods/syncppp.ko)) $(MAKE) -C datamods install endif endif [ `id -u` = 0 ] && /sbin/depmod -a $(KVERS) || : config: ifneq (,$(COPY_INITD)) $(COPY_INITD) endif ifneq (,$(RCCONF_DIR)) ifeq (,$(wildcard $(DESTDIR)$(RCCONF_DIR)/zaptel)) $(INSTALL) -D -m 644 zaptel.sysconfig $(DESTDIR)$(RCCONF_DIR)/zaptel endif endif ifneq (,$(COPY_NETSCR)) $(COPY_NETSCR) endif ifneq (,$(ADD_INITD)) $(ADD_INITD) endif @echo "Zaptel has been configured." @echo "" @echo "If you have any zaptel hardware it is now recommended to " @echo "edit /etc/default/zaptel or /etc/sysconfig/zaptel and set there an " @echo "optimal value for the variable MODULES ." @echo "" @echo "I think that the zaptel hardware you have on your system is:" @xpp/utils/zaptel_hardware || true update: @if [ -d .svn ]; then \ echo "Updating from Subversion..." ; \ svn update | tee update.out; \ rm -f .version; \ if [ `grep -c ^C update.out` -gt 0 ]; then \ echo ; echo "The following files have conflicts:" ; \ grep ^C update.out | cut -b4- ; \ fi ; \ rm -f update.out; \ else \ echo "Not under version control"; \ fi clean: -@$(MAKE) -C menuselect clean rm -f torisatool makefw tor2fw.h radfw.h rm -f $(BINS) rm -f *.o ztcfg tzdriver sethdlc sethdlc-new rm -f $(LTZ_SO) $(LTZ_A) *.lo ifeq ($(BUILDVER),linux26) ifneq (,$(KSRC)) $(KMAKE) clean endif else $(MAKE) -C wct4xxp clean endif @for dir in $(SUBDIRS_UTILS_ALL); do \ $(MAKE) -C $$dir clean; \ done $(MAKE) -C firmware clean rm -rf .tmp_versions rm -f gendigits tones.h rm -f libtonezone* rm -f fxotune rm -f core rm -f ztcfg-shared fxstest rm -rf misdn* rm -rf mISDNuser* rm -rf README.html xpp/README.Astribank.html distclean: dist-clean dist-clean: clean @$(MAKE) -C menuselect dist-clean @$(MAKE) -C firmware dist-clean rm -f makeopts menuselect.makeopts menuselect-tree rm -f config.log config.status config.status: configure @CFLAGS="" ./configure @echo "****" @echo "**** The configure script was just executed, so 'make' needs to be" @echo "**** restarted." @echo "****" @exit 1 menuselect.makeopts: menuselect/menuselect menuselect-tree @menuselect/menuselect --check-deps ${GLOBAL_MAKEOPTS} ${USER_MAKEOPTS} $@ menuconfig: menuselect menuselect: menuselect/menuselect menuselect-tree -@menuselect/menuselect $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts && echo "menuselect changes saved!" || echo "menuselect changes NOT saved!" menuselect/menuselect: menuselect/menuselect.c menuselect/menuselect_curses.c menuselect/menuselect_stub.c menuselect/menuselect.h menuselect/linkedlists.h config.status @CFLAGS="" $(MAKE) -C menuselect CC=$(HOSTCC) menuselect-tree: zaptel.xml firmware/firmware.xml @echo "Generating input for menuselect ..." @build_tools/make_tree > $@ .EXPORT_ALL_VARIABLES: .PHONY: menuselect distclean dist-clean clean version.h all _all install b410p devices programs modules tests devel data stackcheck install-udev config update install-programs install-modules install-include install-libs install-utils-subdirs utils-subdirs uninstall-modules endif