#! /bin/sh /usr/share/dpatch/dpatch-run ## Makefile.dpatch by Kilian Krause ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: imported old Makefile changes ## DP: Currently heavily patched: http://bugs.digium.com/view.php?id=4280 @DPATCH@ diff -urNad zaptel-1.0.8/Makefile /tmp/dpep.gaGw55/zaptel-1.0.8/Makefile --- zaptel-1.0.8/Makefile 2005-06-25 14:39:49.000000000 +0300 +++ /tmp/dpep.gaGw55/zaptel-1.0.8/Makefile 2005-06-25 14:40:42.000000000 +0300 @@ -4,26 +4,43 @@ # BASEADDR=0xd0000 -# -# Okay, the people at RedHat have to break everything they can possibly even attempt to. -# So, we have to look in /usr/src/linux-2.4/include for header files given their brain dead -# crappy installation. (Mind you, I'm a RedHat user myself, so I suppose I'm just as -# stupid as they are). Everyone else who is mildly sane of course links /usr/include/linux -# to their working kernel source directory, the way God himself does, of course -# (assuming He's running Linux -- which we all know He must). -# HOSTCC=gcc -KINCLUDES=$(shell if [ -d /usr/src/linux-2.4/include ]; then echo /usr/src/linux-2.4/include ; else echo /usr/src/linux/include ; fi) +MAKE=make +# If you want to build for a kernel other than the current kernel, set KVERS +ifeq (,$(KVERS)) +KVERS:=$(shell uname -r) +endif +ifndef KSRC + KSRC_SEARCH_PATH:=/lib/modules/$(KVERS)/build /usr/src/linux-2.4 /usr/src/linux + KSRC:=$(firstword $(foreach dir,$(KSRC_SEARCH_PATH),$(wildcard $dir))) +endif +#KINCLUDES:=$(KSRC)/include + +ifeq ($(DEB_HOST_GNU_TYPE),) + UNAME_M:=$(shell uname -m) +else + UNAME_M=$(DEB_HOST_GNU_TYPE) +endif +KINCLUDES:=$(KSRC)/include + +LDFLAGS=-g -O2 CFLAGS+=-I. -O4 -g -Wall -DBUILDING_TONEZONE #-DTONEZONE_DRIVER -CFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi) -CFLAGS+=$(shell if uname -m | grep -q x86_64; then echo "-m64"; fi) +# it's a no-op elsewhere: +CFLAGS+=-fsigned-char +# really add PWD to include path. Needed for kernel 2.6 and some modules +CFLAGS+=-I$(PWD) +CFLAGS+=$(shell if echo $(UNAME_M) | grep -q x86_64; then echo "-m64"; fi) LCFLAGS=-fPIC $(CFLAGS) -DBUILDING_TONEZONE -KFLAGS+=-I/usr/src/linux-2.4/include -O6 -KFLAGS+=-DMODULE -D__KERNEL__ -DEXPORT_SYMTAB -I/usr/src/linux/drivers/net \ - -Wall -I. -Wstrict-prototypes -fomit-frame-pointer -I/usr/src/linux/drivers/net/wan -I /usr/src/linux/include -I/usr/src/linux/include/net -KFLAGS+=$(shell if [ -f $(KINCLUDES)/linux/modversions.h ] ; then echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h" ; fi) -KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi) +KFLAGS+=-I$(KSRC)/include -O2 +KFLAGS+=-DMODULE -D__KERNEL__ -DEXPORT_SYMTAB -I$(KSRC)/drivers/net \ + -Wall -I. -Wstrict-prototypes -fomit-frame-pointer \ + -I$(KSRC)/drivers/net/wan -I$(KSRC)/include -I$(KSRC)/include/net +ifneq (,$(wildcard $(KSRC)/include/linux/modversions.h)) + KFLAGS+=-DMODVERSIONS -include $(KSRC)/include/linux/modversions.h +endif +KFLAGS+=-fsigned-char +KFLAGS+=$(shell if echo $(UNAME_M) | grep -q ppc; then echo "-msoft-float"; fi) # # Features are now configured in zconfig.h # @@ -34,55 +51,94 @@ ROOT_PREFIX= INSTALL_PREFIX= +BIN_DIR:=$(INSTALL_PREFIX)/sbin +LIB_DIR:=$(INSTALL_PREFIX)/usr/lib +INC_DIR:=$(INSTALL_PREFIX)/usr/include +MOD_DIR:=$(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc CONFIG_FILE=$(INSTALL_PREFIX)/etc/zaptel.conf CFLAGS+=-DZAPTEL_CONFIG=\"$(CONFIG_FILE)\" -BUILDVER=$(shell if uname -r | grep -q ^2.6; then echo "linux26"; else echo "linux24"; fi) -MODCONF=$(shell if [ -d $(ROOT_PREFIX)/etc/modprobe.d ]; then echo "$(ROOT_PREFIX)/etc/modprobe.d/zaptel"; elif [ -d $(ROOT_PREFIX)/etc/modutils ]; then echo "$(ROOT_PREFIX)/etc/modutils/zaptel"; elif [ -f $(ROOT_PREFIX)/etc/modprobe.conf ]; then echo "$(ROOT_PREFIX)/etc/modprobe.conf"; elif [ -f $(ROOT_PREFIX)/etc/modules.conf ]; then echo "$(ROOT_PREFIX)/etc/modules.conf"; else echo $(ROOT_PREFIX)/etc/conf.modules ; fi) - -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") +ifeq (2.6,$(shell echo $(KVERS) | cut -d. -f1-2)) + BUILDVER:=linux26 +else + BUILDVER:=linux24 endif -ifeq (${BUILDVER},linux26) -#Tests for newer linux-2.6 udev support -DYNFS=$(shell ps ax | grep -v grep | grep udevd && echo "yes") + +ifeq ($(BUILDVER),linux26) + ifneq (,$(wildcard $(ROOT_PREFIX)/etc/modprobe.d)) + MODCONF:=$(ROOT_PREFIX)/etc/modprobe.d/zaptel + else + ifneq (,$(wildcard $(ROOT_PREFIX)/etc/modprobe.conf)) + MODCONF:=$(ROOT_PREFIX)/etc/modprobe.conf + endif + endif +else # BUILDVER == linux24 + ifneq (,$(wildcard $(ROOT_PREFIX)/etc/modutils)) + MODCONF:=$(ROOT_PREFIX)/etc/modutils/zaptel + else + ifneq (,$(wildcard $(ROOT_PREFIX)/etc/modules.conf)) + MODCONF:=$(ROOT_PREFIX)/etc/modules.conf + endif + endif endif -CHKCONFIG=$(shell sh -c 'type -p chkconfig' 2> /dev/null) +# this may give a warning about 'refefinition of variable CHKCONFIG' +CHKCONFIG:=$(shell sh -c 'type -p chkconfig' 2> /dev/null) ifeq ($(CHKCONFIG),) -CHKCONFIG=: +# this doesn't work. See a recent post of mine to the user's list. +# You can't override a variable. And anyway, you shouldn't run that +# at 'install' (Tzafrir) +CHKCONFIG:=: endif -TZOBJS=zonedata.lo tonezone.lo -LIBTONEZONE=libtonezone.so.1.0 -MODULES=zaptel tor2 torisa wcusb wcfxo wcfxs \ - ztdynamic ztd-eth wct1xxp wct4xxp wcte11xp # ztdummy +TZOBJS:=zonedata.lo tonezone.lo +LIBTONEZONE:=libtonezone.so.1.0 +MODULES:=zaptel tor2 torisa wcusb wcfxo wcfxs \ + ztdynamic ztd-eth wct1xxp wct4xxp wcte11xp ztdummy #MODULES+=wcfxsusb +#MODULES+=wcs3200p -MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done ) -MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done ) +MODULESO:=$(MODULES:%=%.o) +MODULESKO:=$(MODULES:%=%.ko) + +# small utilities, with one source file and simple rules: +# This should probably not be used for clean rules, as some utils are not in +# it, e.g: ztspeed +UTILS:=fxsdump fxstest genconst gendigits hdlcgen hdlcstress hdlctest \ + hdlcverify makefw patgen patlooptest pattest sethdlc sethdlc-new \ + timertest tor2ee usbfxstest wct4xxp-diag torisatool \ + ztdiag ztmonitor zttest zttool -ZTTOOL=$(shell if [ -f /usr/include/newt.h ]; then echo zttool; fi) -BINS=ztcfg torisatool makefw ztmonitor ztspeed $(ZTTOOL) zttest + +ifneq (,$(wildcard /usr/include/newt.h)) + ZTTOOL:=zttool +endif +BINS:=ztcfg torisatool ztmonitor ztspeed $(ZTTOOL) zttest +GEN_H:=tone.h tor2fw.h +# local programs. Generated at build time. Not installed +LOCAL_UTILS:=gendigits makefw +# Note: this still does not include all object files +GENERATED:=$(BINS) $(LOCAL_UTILS) $(GEN_H) $(LIBTONEZONE) $(TZOBJS) \ + $(MODULESO) $(MODULESKO) libtonezone.a #PRIMARY=wcfxsusb PRIMARY=torisa #PRIMARY=wcfxo -PWD=$(shell pwd) -KERNEL_SOURCE?=/lib/modules/`uname -r`/build +# The shell already provides this and thus make gets it for free: +#PWD:=$(shell pwd) -all: $(BUILDVER) $(LIBTONEZONE) +all: $(BUILDVER) + +modules: $(BUILDVER) linux24: $(MODULESO) $(BINS) -linux26: linux26: prereq $(BINS) - @if ! [ -d $(KERNEL_SOURCE) ]; then echo "You do not appear to have the kernel sources for your current kernel installed."; exit 1 ; fi - make -C $(KERNEL_SOURCE) SUBDIRS=$(PWD) modules + @if ! [ -d $(KSRC) ]; then echo "You do not appear to have the kernel sources for your current kernel installed."; exit 1 ; fi + $(MAKE) -C $(KSRC) SUBDIRS=$(PWD) modules -obj-m := $(MODULESO) ztdummy.o +obj-m := $(MODULESO) #ifneq ($(TOPDIR),) #include $(TOPDIR)/Rules.make @@ -94,61 +150,27 @@ tests: patgen pattest patlooptest hdlcstress hdlctest hdlcgen hdlcverify timertest -tor2.o: tor2.c tor2-hw.h tor2fw.h zaptel.h - $(HOSTCC) $(KFLAGS) -c tor2.c - -zaptel.o: zaptel.c zaptel.h digits.h arith.h sec.h mec.h sec-2.h mec2.h mec3.h zconfig.h - $(HOSTCC) $(KFLAGS) -c zaptel.c - -torisa.o: torisa.c zaptel.h torisa.h - $(HOSTCC) $(KFLAGS) -c torisa.c - -wcusb.o: wcusb.c wcusb.h zaptel.h - $(HOSTCC) $(KFLAGS) -c wcusb.c - -wcfxsusb.o: wcfxsusb.c wcfxsusb.h zaptel.h - $(HOSTCC) $(KFLAGS) -c wcfxsusb.c - -wcfxo.o: wcfxo.c zaptel.h - $(HOSTCC) $(KFLAGS) -c wcfxo.c - -wct1xxp.o:wct1xxp.c zaptel.h - $(HOSTCC) $(KFLAGS) -c wct1xxp.c - -wcte11xp.o:wcte11xp.c zaptel.h - $(HOSTCC) $(KFLAGS) -c wcte11xp.c - -wct4xxp.o:wct4xxp.c zaptel.h - $(HOSTCC) $(KFLAGS) -c wct4xxp.c +tor2.o: tor2-hw.h tor2fw.h -wcfxs.o:wcfxs.c zaptel.h - $(HOSTCC) $(KFLAGS) -c wcfxs.c +zaptel.o: digits.h arith.h sec.h mec.h sec-2.h mec2.h mec3.h zconfig.h -wcs3200p.o:wcs3200p.c zaptel.h - $(HOSTCC) $(KFLAGS) -c wcs3200p.c +torisa.o: torisa.h -ztdummy.o:ztdummy.c ztdummy.h - $(HOSTCC) $(KFLAGS) -c ztdummy.c +wcusb.o: wcusb.h -ztdynamic.o: ztdynamic.c zaptel.h - $(HOSTCC) $(KFLAGS) -c ztdynamic.c +wcfxsusb.o: wcfxsusb.h -ztd-eth.o: ztd-eth.c zaptel.h - $(HOSTCC) $(KFLAGS) -c ztd-eth.c +ztdummy.o: ztdummy.h tor2ee.o: tor2-hw.h -tor2ee: tor2ee.o - $(CC) $(CFLAGS) -o tor2ee tor2ee.o -lpci - -zonedata.lo: zonedata.c - $(CC) -c $(LCFLAGS) -o zonedata.lo zonedata.c +tor2ee: LDFLAGS+=-lpci -tonezone.lo: tonezone.c - $(CC) -c $(LCFLAGS) -o tonezone.lo tonezone.c +$(MODULESO): %.o: %.c + $(HOSTCC) -c $(KFLAGS) -o $@ $< -torisatool: torisatool.o - $(CC) -o torisatool torisatool.o +zonedata.lo tonezone.lo: %.lo: %.c + $(CC) -c $(LCFLAGS) -o $@ $< tones.h: gendigits ./gendigits @@ -156,8 +178,7 @@ tor2fw.h: makefw tormenta2.rbt ./makefw tormenta2.rbt tor2fw > tor2fw.h -gendigits: gendigits.o - $(CC) -o gendigits gendigits.o -lm +gendigits: LDFLAGS+=-lm zaptel.c: tones.h @@ -172,34 +193,20 @@ ztspeed.o: ztspeed.c $(CC) -c ztspeed.c -zttool: zttool.o - $(CC) -o zttool zttool.o -lnewt - -ztprovision: ztprovision.o - $(CC) -o ztprovision ztprovision.o -lnewt +zttool: LDFLAGS+=-lnewt -ztmonitor: ztmonitor.o - $(CC) -o ztmonitor ztmonitor.o +ztprovision: LDFLAGS+=-lnewt -ztcat: ztcat.o - $(CC) -o ztcat ztcat.o -ltonezone +ztcat: LDFLAGS+=-ltonezone ztspeed: ztspeed.o $(CC) -o ztspeed ztspeed.o -sethdlc-new: sethdlc-new.o - $(CC) -o sethdlc-new sethdlc-new.o - -sethdlc-new.o: sethdlc-new.c - $(CC) -c $(CFLAGS) -I$(KINCLUDES) sethdlc-new.c - libtonezone.a: $(TZOBJS) ar rcs libtonezone.a $(TZOBJS) $(LIBTONEZONE): $(TZOBJS) $(CC) -shared -Wl,-soname,libtonezone.so.1 -lm -o $@ $(TZOBJS) - [ `id -u` = 0 ] && /sbin/ldconfig || : - ln -sf libtonezone.so.1 libtonezone.so ztcfg.c: ztcfg.h @@ -210,31 +217,24 @@ $(CC) -o ztcfg ztcfg.o -lm -L. libtonezone.a ztcfg-dude: ztcfg-dude.o mknotch.o complex.o $(LIBTONEZONE) - $(CC) -o ztcfg ztcfg-dude.o mknotch.o complex.o -lm -L. -ltonezone - -mknotch.o: mknotch.cc - $(CC) -c mknotch.cc - -complex.o: complex.cc - $(CC) -c complex.cc + $(CC) -o $@ ztcfg-dude.o mknotch.o complex.o -lm -L. -ltonezone -usbfxstest.o: usbfxstest.c - $(CC) -g -c usbfxstest.c +mknotch.o complex.o: %.o: %.cc + $(CC) -c $< -usbfxstest: usbfxstest.o - $(CC) -o usbfxstest usbfxstest.o -lzap +usbfxstest: LDFLAGS+=-lzap -fxstest: fxstest.o - $(CC) -o fxstest fxstest.o -L. -ltonezone -lm +fxstest: LDFLAGS+=-L. -ltonezone -lm -fxsdump: fxsdump.o - $(CC) -o fxsdump fxsdump.o -lm +fxsdump: LDFLAGS+=-lm stackcheck: checkstack $(BUILDVER) ./checkstack *.o -ztdiag: ztdiag.o - $(CC) -o ztdiag ztdiag.o +$(UTILS): %: %.o + $(CC) $(LDFLAGS) -o $@ $< + +programs: $(BINS) devices: ifeq ($(DYNFS),) @@ -251,18 +251,36 @@ mknod $(INSTALL_PREFIX)/dev/zap/timer c 196 253 mknod $(INSTALL_PREFIX)/dev/zap/channel c 196 254 mknod $(INSTALL_PREFIX)/dev/zap/pseudo c 196 255 - N=1; \ - while [ $$N -lt 250 ]; do \ + for N `seq 250`; do \ rm -f $(INSTALL_PREFIX)/dev/zap/$$N; \ mknod $(INSTALL_PREFIX)/dev/zap/$$N c 196 $$N; \ - N=$$[$$N+1]; \ done else @echo "**** Dynamic filesystem detected -- not creating device nodes" @echo "**** If you are running udev, read README.udev" endif -install: all devices +# make should *fail* and not silently succeed if a program did not build +install-programs: $(BINS) $(LIBTONEZONE) libtonezone.a + install -d $(BIN_DIR) + install $(BINS) $(BIN_DIR) + install -d $(LIB_DIR) + install -m 755 $(LIBTONEZONE) libtonezone.a $(LIB_DIR) + install -d $(INC_DIR)/linux + install -m 644 tonezone.h $(INC_DIR) + install -m 644 zaptel.h torisa.h $(INC_DIR)/linux + +install-modules: install-$(BUILDVER) +install-linux24: $(MODULESO) + install -d $(MOD_DIR) + install -m 644 $(MODULESO) $(MOD_DIR) +install-linux26: $(MODULESKO) + install -d $(MOD_DIR) + install -m 644 $(MODULESKO) $(MOD_DIR) + +# I don't undestan't what the $%^$^%^ is going on here. +# So far I simply don't use it. +install: all devices install-programs install-modules install -D -m 755 ztcfg $(INSTALL_PREFIX)/sbin/ztcfg if [ -f sethdlc-new ]; then \ install -D -m 755 sethdlc-new $(INSTALL_PREFIX)/sbin/sethdlc; \ @@ -272,18 +290,18 @@ if [ -f zttool ]; then install -D -m 755 zttool $(INSTALL_PREFIX)/sbin/zttool; fi if [ -f zaptel.ko ]; then \ - for x in $(MODULESKO) ztdummy.ko; do \ - install -D -m 644 $$x $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/$$x ; \ + for x in $(MODULESKO); do \ + install -D -m 644 $$x $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/$$x ; \ done; \ if ! [ -f wcfxsusb.ko ]; then \ - rm -f $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/wcfxsusb.o; \ + rm -f $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/wcfxsusb.o; \ fi; \ else \ for x in $(MODULESO); do \ - install -D -m 644 $$x $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/$$x ; \ + install -D -m 644 $$x $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/$$x ; \ done; \ if ! [ -f wcfxsusb.o ]; then \ - rm -f $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/wcfxsusb.ko; \ + rm -f $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/wcfxsusb.ko; \ fi; \ fi @@ -329,10 +347,10 @@ config: if [ -d $(INSTALL_PREFIX)/etc/rc.d/init.d ]; then \ install -D -m 755 zaptel.init $(INSTALL_PREFIX)/etc/rc.d/init.d/zaptel; \ - chkconfig --add zaptel; \ + $(CHKCONFIG) --add zaptel; \ elif [ -d $(INSTALL_PREFIX)/etc/init.d ]; then \ install -D -m 755 zaptel.init $(INSTALL_PREFIX)/etc/init.d/zaptel; \ - chkconfig --add zaptel; \ + $(CHKCONFIG) --add zaptel; \ fi if [ ! -f /etc/sysconfig/zaptel ]; then \ install -D -m 644 zaptel.sysconfig $(INSTALL_PREFIX)/etc/sysconfig/zaptel; \ @@ -342,12 +360,7 @@ fi clean: - rm -f torisatool makefw tor2fw.h - rm -f zttool - rm -f *.o ztcfg tzdriver sethdlc sethdlc-new - rm -f $(TZOBJS) $(LIBTONEZONE) *.lo + rm -f $(GENERATED) *.o core + #rm -f $(TZOBJS) $(LIBTONEZONE) *.lo rm -f *.ko *.mod.c .*o.cmd - rm -f gendigits tones.h - rm -f libtonezone* - rm -f tor2ee - rm -f core + #rm -f libtonezone*