#! /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.1.0.2005080921/Makefile /tmp/dpep.v0FWQe/zaptel-1.1.0.2005080921/Makefile --- zaptel-1.1.0.2005080921/Makefile 2005-08-10 02:17:32.882392268 +0300 +++ /tmp/dpep.v0FWQe/zaptel-1.1.0.2005080921/Makefile 2005-08-10 02:18:33.090245312 +0300 @@ -16,25 +16,40 @@ 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) + KSRC:=$(firstword $(foreach dir,$(KSRC_SEARCH_PATH),$(wildcard $dir))) endif endif KINCLUDES:=$(KSRC)/include +ifeq ($(DEB_HOST_GNU_TYPE),) + UNAME_M:=$(shell uname -m) +else + UNAME_M=$(DEB_HOST_GNU_TYPE) +endif +LDFLAGS=-g -O2 CFLAGS+=-I. -O4 -g -Wall -DBUILDING_TONEZONE #-DTONEZONE_DRIVER -CFLAGS_PPC:=$(shell if uname -m | grep -q ppc; then echo "-fsigned-char"; fi) -CFLAGS_X86-64:=$(shell if uname -m | grep -q x86_64; then echo "-m64"; fi) +# TODO: -fsigned-char seems to be a required on some other (big-endian?) +# platforms, such as s390, and a NOP on basically any other platform. +ifneq (,$(findstring ppc,$(UNAME_M))) + CFLAGS_PPC:=-fsigned-char + KFLAGS_PPC:=-msoft-float -fsigned-char +endif +ifneq (,$(findstring x86_64,$(UNAME_M))) + CFLAGS_X86_64:=-m64 + ifneq (,$(findstring 2.4,$(KVERS))) + KFLAGS+=-mcmodel=kernel + endif +endif CFLAGS+=$(CFLAGS_PPC) $(CFLAGS_X64-64) 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 + -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 -KFLAGS_PPC:=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi) KFLAGS+=$(KFLAGS_PPC) -KFLAGS+=$(shell if uname -r | grep -q 2.4; then if uname -m | grep -q x86_64; then echo "-mcmodel=kernel"; fi; fi) # # Features are now configured in zconfig.h @@ -45,6 +60,11 @@ ROOT_PREFIX= INSTALL_PREFIX=$(DESTDIR) +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)\" @@ -77,19 +97,20 @@ endif endif -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 -ifeq (${BUILDVER},linux26) -#Tests for newer linux-2.6 udev support -DYNFS:=$(shell ps ax | grep -v grep | grep udevd && echo "yes") -endif +# A test for the daemon of either udev or devfs. Only used once at +# install time, so no point in := here +DYNFS=$(shell ps ax | grep -v grep | grep -q 'devfsd\|udevd' && echo "yes") -CHKCONFIG:=$(shell sh -c 'type -p chkconfig' 2> /dev/null) -ifndef CHKCONFIG -CHKCONFIG:=: -endif +# The part that uses chkconfig (the target 'config' is rather +# redhat-specific. I believe some of the pathes are even incompatible with +# SuSE, though they should work with Mandrake. +# +# Thus I don't use it for the moment for the deb. It is not usable at +# install-time anyway. +# Tzafrir. set 'CHKCONFIG=true' in the make command-line to make it do nothing. +# But then again, you probably won't run the target 'config' anyway on +# such a system. +CHKCONFIG:=chkconfig TZOBJS:=zonedata.lo tonezone.lo LIBTONEZONE_SO:=libtonezone.so @@ -99,29 +120,51 @@ ztdynamic ztd-eth wct1xxp wct4xxp wcte11xp pciradio \ ztd-loc # ztdummy #MODULES+=wcfxsusb -# build ztdummy by default for 2.6 kernels -ifeq (${BUILDVER},linux26) +# build ztdummy by default always MODULES+=ztdummy -endif + 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 + ifneq (,$(wildcard /usr/include/newt.h)) ZTTOOL:=zttool endif -BINS=ztcfg torisatool makefw ztmonitor ztspeed $(ZTTOOL) zttest fxotune + +# These utils are the targets. They are actually intended to be installed. +# makefw removed by Tzafrir. +BINS=ztcfg torisatool ztmonitor ztspeed $(ZTTOOL) zttest fxotune +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 $(MODULESO:%.o=%.mod.c) \ + $(MODULESO:%=%.cmd) + #PRIMARY=wcfxsusb PRIMARY=torisa #PRIMARY=wcfxo -PWD:=$(shell pwd) -all: $(BUILDVER) $(LIBTONEZONE_SO) manpages +all: $(BUILDVER) -linux24: $(MODULESO) $(BINS) +modules: $(BUILDVER) -linux26: prereq $(BINS) - @if ! [ -d $(KSRC) ]; then echo "You do not appear to have the sources for the $(KVERS) kernel installed."; exit 1 ; fi +linux24: $(MODULESO) + +linux26: prereq + @if ! [ -d $(KSRC) ]; then echo \ + "You do not appear to have the sources for the $(KVERS) kernel installed."; \ + exit 1 ; \ + fi $(MAKE) -C $(KSRC) SUBDIRS=$(PWD) modules obj-m := $(MODULESO) @@ -136,55 +179,25 @@ tests: patgen pattest patlooptest hdlcstress hdlctest hdlcgen hdlcverify timertest -tor2.o: tor2-hw.h tor2fw.h zaptel.h - -zaptel.o: zaptel.h digits.h arith.h sec.h mec.h sec-2.h mec2.h mec3.h zconfig.h - -torisa.o: zaptel.h torisa.h - -wcusb.o: wcusb.h zaptel.h - -wcfxsusb.o: wcfxsusb.h zaptel.h - -wcfxo.o: zaptel.h - -wct1xxp.o: zaptel.h +tor2.o: tor2-hw.h tor2fw.h -wcte11xp.o: zaptel.h +zaptel.o: digits.h arith.h sec.h mec.h sec-2.h mec2.h mec3.h zconfig.h -ztd-loc.o: zaptel.h +torisa.o: torisa.h -wct4xxp.o: zaptel.h +wcusb.o: wcusb.h -wctdm.o: zaptel.h wctdm.h +wcfxsusb.o: wcfxsusb.h -pciradio.o: zaptel.h radfw.h +wctdm.o: wctdm.h -wcs3200p.o: zaptel.h +pciradio.o: radfw.h ztdummy.o: ztdummy.h -ztdynamic.o: zaptel.h - -ztd-eth.o: zaptel.h - $(MODULESO): %.o: %.c zaptel.h $(HOSTCC) $(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 @@ -194,88 +207,77 @@ radfw.h: makefw pciradio.rbt ./makefw pciradio.rbt radfw > radfw.h -gendigits: gendigits.o - $(CC) -o $@ $^ -lm +prereq: tones.h tor2fw.h radfw.h -zaptel.c: tones.h +tor2ee.o: tor2-hw.h -prereq: tones.h tor2fw.h radfw.h +tor2ee: LDFLAGS+=-lpci -zttool.o: zttool.c zaptel.h +gendigits: LDFLAGS+=-lm -ztprovision.o: ztprovision.c zaptel.h +$(TZOBJS): %.lo:%.c + $(CC) -c $(LCFLAGS) -o $@ $^ -ztmonitor.o: ztmonitor.c zaptel.h +zaptel.c: tones.h -ztspeed.o: ztspeed.c - $(CC) -o $@ -c $^ +zttool.o: zaptel.h -zttool: zttool.o - $(CC) -o $@ $^ -lnewt +ztprovision.o: zaptel.h -ztmonitor: ztmonitor.o - $(CC) -o $@ $^ +ztmonitor.o: zaptel.h -ztspeed: ztspeed.o - $(CC) -o $@ $^ +ztcfg.c: ztcfg.h -sethdlc-new: sethdlc-new.o - $(CC) -o $@ $^ +sethdlc-new.o: CFLAGS+=-I$(KINCLUDES) -sethdlc-new.o: sethdlc-new.c - $(CC) -o $@ -c $(CFLAGS) -I$(KINCLUDES) $^ +# ztspeed should be unoptimized +ztspeed.o: CFLAGS+=-O0 + +zttool: LDFLAGS+=-lnewt + +ztspeed: CFLAGS+=-O0 libtonezone.a: $(TZOBJS) ar rcs libtonezone.a $^ $(LIBTONEZONE_SO): $(TZOBJS) - $(CC) -shared -Wl,-soname,$(LIBTONEZONE_SO).$(LIBTONEZONE_SO_MAJOR_VER) -lm -o $@ $^ - -ztcfg.c: ztcfg.h + $(CC) $(LDFLAGS) -shared -Wl,-soname,$(LIBTONEZONE_SO).$(LIBTONEZONE_SO_MAJOR_VER) -lm -o $@ $^ ztcfg-shared: ztcfg.o $(LIBTONEZONE_SO) - $(CC) -o $@ $^ -lm +ztcfg-shared: LDFLAGS+=-lm ztcfg: ztcfg.o libtonezone.a - $(CC) -o $@ $^ -lm +ztcfg: LDFLAGS+=-lm ztcfg-dude: ztcfg-dude.o mknotch.o complex.o $(LIBTONEZONE_SO) - $(CC) -o $@ $^ -lm - -mknotch.o: mknotch.cc - $(CC) -o $@ -c $^ - -complex.o: complex.cc - $(CC) -o $@ -c $^ - -usbfxstest.o: usbfxstest.c - $(CC) -o $@ -g -c $^ +ztcfg-dude: LDFLAGS+=-lm -usbfxstest: usbfxstest.o - $(CC) -o $@ $^ -lzap +usbfxstest: LDFLAGS+=-lzap fxstest: fxstest.o $(LIBTONEZONE_SO) - $(CC) -o $@ $^ -lm +fxstest: LDFLAGS+=-lm -fxotune: fxotune.o - $(CC) -o $@ $^ -lm +fxotune: LDFLAGS+=-lm -fxsdump: fxsdump.o - $(CC) -o $@ $^ -lm +fxsdump: LDFLAGS+=-lm stackcheck: checkstack $(BUILDVER) ./checkstack *.o -ztdiag: ztdiag.o - $(CC) -o $@ $^ +$(UTILS): %: %.o + $(CC) $(LDFLAGS) -o $@ $< + +# TODO: where is the simplest place to "pull" the man pages? +programs: $(BINS) manpages + devices: -ifndef DYNFS +ifeq (,$(DYNFS)) mkdir -p $(INSTALL_PREFIX)/dev/zap - rm -f $(INSTALL_PREFIX)/dev/zap/ctl - rm -f $(INSTALL_PREFIX)/dev/zap/channel - rm -f $(INSTALL_PREFIX)/dev/zap/pseudo - rm -f $(INSTALL_PREFIX)/dev/zap/timer + #rm -f $(INSTALL_PREFIX)/dev/zap/ctl + #rm -f $(INSTALL_PREFIX)/dev/zap/channel + #rm -f $(INSTALL_PREFIX)/dev/zap/pseudo + #rm -f $(INSTALL_PREFIX)/dev/zap/timer rm -f $(INSTALL_PREFIX)/dev/zap/253 rm -f $(INSTALL_PREFIX)/dev/zap/252 rm -f $(INSTALL_PREFIX)/dev/zap/251 @@ -284,11 +286,9 @@ 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 # DYNFS @echo "**** Dynamic filesystem detected -- not creating device nodes" @@ -311,7 +311,26 @@ rm -f doc/ztmonitor.8.gz docbook2man -o doc doc/ztmonitor.sgml gzip doc/ztmonitor.8 +# 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 -D -m 755 ztcfg $(INSTALL_PREFIX)/sbin/ztcfg if [ -f sethdlc-new ]; then \ @@ -415,15 +434,5 @@ fi clean: - rm -f torisatool makefw tor2fw.h radfw.h - rm -f ${BINS} - rm -f *.o ztcfg tzdriver sethdlc sethdlc-new - rm -f $(TZOBJS) $(LIBTONEZONE_SO) *.lo - rm -f *.ko *.mod.c .*o.cmd + rm -f $(GENERATED) *.o core 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