# # 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 ifndef MACHINE MACHINE :=$(shell uname -m) endif # FIXME: this variable sets ARCH in the kernel Makefile. ARCH :=$(shell echo $(MACHINE) | sed -e s/i.86/i386/) # 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 KINCLUDES:=$(KSRC)/include ifeq (2.6,$(shell echo $(KVERS) | cut -d. -f1-2)) BUILDVER:=linux26 else BUILDVER:=linux24 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 MODULES:=zaptel tor2 torisa wcusb wcfxo wctdm wctdm24xxp \ ztdynamic ztd-eth wct1xxp wcte11xp pciradio \ ztd-loc wcte12xp # ztdummy #MODULES+=wcfxsusb ifeq ($(BUILDVER),linux26) MODULES+=ztdummy zttranscode endif MODULE_ALIASES=wcfxs wctdm8xxp wct2xxp MODULESO:=$(MODULES:%=%.o) MODULESKO:=$(MODULES:%=%.ko) # add this later, so it doesn't become part of MODULESO/MODULESKO MODULES+=wct4xxp wctc4xxp 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 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),) include $(src)/Makefile.kernel26 else HOSTCC=gcc INSTALL_PREFIX := /usr CFLAGS+=-I. -O4 -g -Wall ifneq (,$(findstring ppc,$(PACHINE))) CFLAGS += -fsigned-char KFLAGS += -msoft-float -fsigned-char endif ifneq (,$(findstring x86_64,$(PACHINE))) CFLAGS += -m64 KFLAGS += -mcmodel=kernel endif LCFLAGS:=-fPIC $(CFLAGS) -DBUILDING_TONEZONE 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 # # Features are now configured in zconfig.h # KFLAGS+=-DSTANDALONE_ZAPATA KMAKE:= $(MAKE) -C $(KSRC) SUBDIRS=$(PWD) KMAKE_INST:= $(KMAKE) INSTALL_MOD_PATH=$(DESTDIR) INSTALL_MOD_DIR=misc modules_install CONFIG_FILE:=/etc/zaptel.conf CFLAGS+=-DZAPTEL_CONFIG=\"$(CONFIG_FILE)\" ifeq ($(BUILDVER),linux24) #We only support DEVFS in linux 2.4 kernels, since its considered obsolete post 2.4 DYNFS:=$(shell ps ax | grep -v grep | grep -q devfsd && echo "yes") endif # sample makefile "trace print" #tracedummy=$(shell echo ====== GOT HERE ===== >&2; echo >&2) ifeq ($(HOTPLUG_FIRMWARE),yes) FIRMWARE_DIR := $(firstword $(wildcard /usr/lib/hotplug/firmware /lib/firmware )) endif CHKCONFIG := $(wildcard /sbin/chkconfig) UPDATE_RCD := $(wildcard /usr/sbin/update-rc.d) ifneq (,$(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 NETSCR_DIR := $(firstword $(wildcard /etc/sysconfig/network-scripts )) ifneq (,$(NET_SCR_DIR)) NETSCR_TARGET := $(DESTDIR)$(NETSCR_DIR)/ifup-hdlc COPY_NETSCR := install -D ifup-hdlc $(NETSCR_TARGET) endif RCCONF_DIR := $(firstword $(wildcard /etc/default /etc/sysconfig)) ifneq (,$(RCCONF_DIR)) RCCONF_TARGET := $(DESTDIR)$(RCCONF_DIR)/zaptel # Let's not step over an existing config file: ifeq (,$(wildcard $(RCCONF_TARGET))) COPY_RCCONF := install -D -m 644 zaptel.sysconfig $(RCCONF_TARGET) endif endif SELINUX_ENABLED := $(shell [ -x /usr/sbin/sestatus ] && {/usr/sbin/sestatus | grep "SELinux status:" | grep -q "enabled"}) ifneq ($(wildcard .version),) ZAPTELVERSION:=$(shell cat .version) else ifneq ($(wildcard .svn),) ZAPTELVERSION=SVN-$(shell build_tools/make_svn_branch_name) endif endif TZOBJS:=zonedata.lo tonezone.lo LIBTONEZONE_SO:=libtonezone.so LIBTONEZONE_SO_MAJOR_VER:=1 LIBTONEZONE_SO_MINOR_VER:=0 LIBDIR := $(INSTALL_PREFIX)/lib INCLUDE_DIR := $(INSTALL_PREFIX)/include # Note: Zaptel's use of /sbin is slightly non-standard: SBINDIR := /sbin # No better default. If INSTALL_PREFIX != /usr, I'm not sure # where the man page sit. So they need to be manually overriden anyway. MANDIR = /usr/share/man/man8 MODS_DIR := /lib/modules/$(KVERS)/misc MAN_PAGES_BASE = ztcfg BINS=ztcfg torisatool makefw ztmonitor ztspeed zttest fxotune ifneq (,$(wildcard /usr/include/newt.h)) BINS+=zttool MAN_PAGES_BASE += zttool endif MAN_PAGES = $(MAN_PAGES_BASE:%=doc/%.8) all: programs modules programs: $(BINS) $(LIBTONEZONE_SO) ifeq ($(BUILDVER),linux24) modules: prereq $(MODULESO) wct4xxp/wct4xxp.o else modules: prereq ifeq (,$(wildcard $(KSRC)/.config)) @echo "You do not appear to have the sources for the $(KVERS) kernel installed (under $(KSRC))."; exit 1 endif $(MAKE) -C $(KSRC) SUBDIRS=$(PWD) HOTPLUG_FIRMWARE=$(HOTPLUG_FIRMWARE) 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: FORCE @ZAPTELVERSION="${ZAPTELVERSION}" build_tools/make_version_h > $@.tmp @if cmp -s $@.tmp $@ ; then echo; else \ mv $@.tmp $@ ; \ fi @rm -f $@.tmp wct4xxp/wct4xxp.o: $(MAKE) -C wct4xxp KFLAGS="$(KFLAGS) -I.." CFLAGS="$(CFLAGS) -I.." devel: tor2ee tests: patgen pattest patlooptest hdlcstress hdlctest hdlcgen hdlcverify timertest $(MAKE) -C wctc4xxp tests CFLAGS="$(CFLAGS) -I.." $(MODULESO): zaptel.h tor2.o: tor2-hw.h tor2fw.h zaptel-base.o: digits.h arith.h sec.h sec-2.h mec.h mec2.h mec3.h mg2ec.h kb1ec.h zconfig.h version.h tones.h torisa.o: torisa.h wcusb.o: wcusb.h wcfxsusb.o: wcfxsusb.h wctdm.o: wctdm.h wctdm24xxp.o: wctdm.h pciradio.o: radfw.h ztdummy.o: ztdummy.h zaptel.o: zaptel-base.o $(ZAPTEL_HPEC) $(LD) -r -o $@ $< $(ZAPTEL_HPEC) $(filter-out zaptel.o,$(MODULESO)) zaptel-base.o: %.o: %.c $(CC) $(KFLAGS) -o $@ -c $< tor2ee.o: tor2-hw.h tor2ee: tor2ee.o $(CC) $(CFLAGS) -o $@ $^ -lpci zonedata.lo: zonedata.c $(CC) -c $(LCFLAGS) -o $@ $^ tonezone.lo: tonezone.c $(CC) -c $(LCFLAGS) -o $@ $^ torisatool: torisatool.o $(CC) -o $@ $^ tones.h: gendigits ./gendigits > $@ tor2fw.h: makefw tormenta2.rbt ./makefw tormenta2.rbt tor2fw > tor2fw.h radfw.h: makefw pciradio.rbt ./makefw pciradio.rbt radfw > radfw.h gendigits: gendigits.o $(CC) -o $@ $^ -lm prereq: tones.h tor2fw.h radfw.h version.h zttool.o: zttool.c zaptel.h ztprovision.o: ztprovision.c zaptel.h ztmonitor.o: ztmonitor.c zaptel.h ztspeed.o: ztspeed.c $(CC) -o $@ -c $^ zttool: zttool.o $(CC) -o $@ $^ -lnewt ztmonitor: ztmonitor.o $(CC) -o $@ $^ ztspeed: ztspeed.o $(CC) -o $@ $^ sethdlc-new: sethdlc-new.o $(CC) -o $@ $^ sethdlc-new.o: sethdlc-new.c $(CC) -o $@ -c $(CFLAGS) -I$(KINCLUDES) $^ libtonezone.a: $(TZOBJS) ar rcs libtonezone.a $^ $(LIBTONEZONE_SO): $(TZOBJS) $(CC) -shared -Wl,-soname,$(LIBTONEZONE_SO).$(LIBTONEZONE_SO_MAJOR_VER).$(LIBTONEZONE_SO_MINOR_VER) -lm -o $@ $^ ztcfg.c: ztcfg.h ztcfg-shared: ztcfg.o $(LIBTONEZONE_SO) $(CC) -o $@ $^ -lm ztcfg: ztcfg.o libtonezone.a $(CC) -o $@ $^ -lm ztcfg-dude: ztcfg-dude.o mknotch.o complex.o $(LIBTONEZONE_SO) $(CC) -o $@ $^ -lm -lstdc++ mknotch.o: mknotch.cc $(CC) -o $@ -c $^ complex.o: complex.cc $(CC) -o $@ -c $^ usbfxstest.o: usbfxstest.c $(CC) -o $@ -g -c $^ usbfxstest: usbfxstest.o $(CC) -o $@ $^ -lzap fxstest: fxstest.o $(LIBTONEZONE_SO) $(CC) -o $@ $^ -lm fxotune: fxotune.o $(CC) -o $@ $^ -lm fxsdump: fxsdump.o $(CC) -o $@ $^ -lm stackcheck: checkstack all ./checkstack *.ko */*.ko README.html: README asciidoc -n -a toc $< ztdiag: ztdiag.o $(CC) -o $@ $^ devices: ifndef DYNFS mkdir -p $(DESTDIR)/dev/zap rm -f $(DESTDIR)/dev/zap/ctl rm -f $(DESTDIR)/dev/zap/channel rm -f $(DESTDIR)/dev/zap/pseudo rm -f $(DESTDIR)/dev/zap/timer rm -f $(DESTDIR)/dev/zap/253 rm -f $(DESTDIR)/dev/zap/252 rm -f $(DESTDIR)/dev/zap/251 rm -f $(DESTDIR)/dev/zap/250 mknod $(DESTDIR)/dev/zap/ctl c 196 0 mknod $(DESTDIR)/dev/zap/timer c 196 253 mknod $(DESTDIR)/dev/zap/channel c 196 254 mknod $(DESTDIR)/dev/zap/pseudo c 196 255 N=1; \ while [ $$N -lt 250 ]; do \ rm -f $(DESTDIR)/dev/zap/$$N; \ mknod $(DESTDIR)/dev/zap/$$N c 196 $$N; \ N=$$[$$N+1]; \ done else # DYNFS ifdef UDEVRULES install -d $(DESTDIR)/etc/udev/rules.d build_tools/genudevrules > $(DESTDIR)/etc/udev/rules.d/zaptel.rules else # !UDEVRULES @echo "**** Dynamic filesystem detected -- not creating device nodes" endif endif b410p: @wget -V >/dev/null || (echo "You need wget in order to install the drivers" ; false) [ -f misdn-b410p.tar.gz ] || wget ftp://ftp.digium.com/pub/zaptel/b410p/misdn-b410p.tar.gz tar -zxf misdn-b410p.tar.gz $(MAKE) -C misdn install [ -f mISDNuser.tar.gz ] || wget ftp://ftp.digium.com/pub/zaptel/b410p/mISDNuser.tar.gz tar -zxf mISDNuser.tar.gz $(MAKE) -C mISDNuser install install: install-modules install-programs @echo "###################################################" @echo "###" @echo "### Zaptel installed successfully." @echo "### If you have not done so before, install init scripts with:" @echo "###" @echo "### make config" @echo "###" @echo "###################################################" # Specific to a kernel version: install-modules: modules ifeq ($(BUILDVER),linux26) for x in $(MODULESKO); do \ rm -f $(DESTDIR)/lib/modules/$(KVERS)/extra/$$x ; \ done $(KMAKE_INST) else install -d $(DESTDIR)$(MODS_DIR) install -m 644 $(MODULESO) wct4xxp/wct4xxp.o $(DESTDIR)$(MODS_DIR) endif ifeq (,$(wildcard wcfxsusb.o)) rm -f $(DESTDIR)$(MODS_DIR)/wcfxsusb.o endif rm -f $(DESTDIR)$(MODS_DIR)/wcfxs.o [ `id -u` = 0 ] && /sbin/depmod -a $(KVERS) || : # All the userspace components. Common to all the system: install-programs: programs devices firmware install -D -m 755 ztcfg $(DESTDIR)$(SBINDIR)/ztcfg ifneq (,$(wildcard sethdlc-new)) install -D -m 755 sethdlc-new $(DESTDIR)$(SBINDIR)/sethdlc else ifneq (,$(wildcard sethdlc)) install -D -m 755 sethdlc $(DESTDIR)$(SBINDIR)/sethdlc endif endif ifneq (,$(wildcard zttool)) install -D -m 755 zttool $(DESTDIR)$(SBINDIR)/zttool endif install -d $(DESTDIR)$(MANDIR) install -m 644 $(MAN_PAGES) $(DESTDIR)$(MANDIR) install -D -m 755 $(LIBTONEZONE_SO) $(DESTDIR)$(LIBDIR)/$(LIBTONEZONE_SO).$(LIBTONEZONE_SO_MAJOR_VER).$(LIBTONEZONE_SO_MINOR_VER) [ `id -u` = 0 ] && /sbin/ldconfig || : rm -f $(DESTDIR)$(LIBDIR)/$(LIBTONEZONE_SO) ln -sf $(LIBTONEZONE_SO).$(LIBTONEZONE_SO_MAJOR_VER).$(LIBTONEZONE_SO_MINOR_VER) \ $(DESTDIR)$(LIBDIR)/$(LIBTONEZONE_SO).$(LIBTONEZONE_SO_MAJOR_VER) ln -sf $(LIBTONEZONE_SO).$(LIBTONEZONE_SO_MAJOR_VER).$(LIBTONEZONE_SO_MINOR_VER) \ $(DESTDIR)$(LIBDIR)/$(LIBTONEZONE_SO) ifneq (,$(SELINUX_ENABLED)) /sbin/restorecon -v $(DESTDIR)$(LIBDIR)/$(LIBTONEZONE_SO) endif install -d $(DESTDIR)$(INCLUDE_DIR)/linux install -m 644 zaptel.h torisa.h $(DESTDIR)$(INCLUDE_DIR)/linux/ install -m 644 tonezone.h $(DESTDIR)$(INCLUDE_DIR) ifeq (,$(wildcard $(DESTDIR)$(CONFIG_FILE))) install -D -m 644 zaptel.conf.sample $(DESTDIR)$(CONFIG_FILE) endif build_tools/genmodconf $(BUILDVER) "$(DESTDIR)" "$(filter-out zaptel ztdummy zttranscode wctc4xxp ztdynamic xpp_usb,$(MODULES)) $(MODULE_ALIASES)" ifeq (,$(DESTDIR)) @if [ -d /etc/modutils ]; then \ /sbin/update-modules ; \ fi endif install-udev: devices # FIRMWARE_DIR also implies HOTPLUG_FIRMWARE, unless set manually. firmware: ifneq (,$(FIRMWARE_DIR)) install -d $(DESTDIR)$(FIRMWARE_DIR) install -m 644 wct4xxp/*.ima wctc4xxp/*.bin $(DESTDIR)$(FIRMWARE_DIR) @echo "Installed firmware" else @echo "Not installing firmware because we are not using hotplug firmware" endif config: ifneq (,$(COPY_INITD)) $(COPY_INITD) endif ifneq (,$(COPY_RCCONF)) $(COPY_RCCONF) endif ifneq (,$(COPY_NETSCR)) $(COPY_NETSCR) endif ifneq (,$(ADD_INITD)) $(ADD_INITD) endif @echo "Zaptel has been configured." @echo "" ifneq (,$(COPY_RCCONF)) @echo "If you have any zaptel hardware it is now recommended to " @echo "edit $(RCCONF_TARGET) and set there an optimal value for " @echo "the variable MODULES ." @echo "" endif @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: rm -f torisatool makefw tor2fw.h radfw.h rm -f $(BINS) rm -f patgen pattest patlooptest hdlcstress hdlctest hdlcgen hdlcverify timertest rm -f *.o ztcfg tzdriver sethdlc sethdlc-new rm -f $(TZOBJS) $(LIBTONEZONE_SO) *.lo $(MAKE) -C $(KSRC) SUBDIRS=$(PWD) clean $(MAKE) -C wct4xxp clean $(MAKE) -C wctc4xxp clean rm -rf .tmp_versions rm -f gendigits tones.h rm -f libtonezone* rm -f tor2ee rm -f fxotune rm -f core rm -f ztcfg-shared fxstest rm -rf misdn* rm -rf mISDNuser* .EXPORT_ALL_VARIABLES: FORCE: endif