summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkpfleming <kpfleming@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2005-05-21 17:49:12 +0000
committerkpfleming <kpfleming@5390a7c7-147a-4af0-8ec9-7488f05a26cb>2005-05-21 17:49:12 +0000
commit0e3e2b49d1d23d516c4936ebcb4d2fef40a13f56 (patch)
tree30ef83fd003003eddb7a6280d0cdf9ba5b1da871
parentb984e8356c1bf7d255e47bbeb6d1faeef9e3e9b3 (diff)
major cleanup:
allow builds against any installed kernel using KVERS allow builds against any kernel sources using KSRC for 2.6 kernels, use the kernel's "module_install" script instead of doing it ourselves don't make extraneous libtonezone symlinks efficiency improvements (don't use $(shell) when not needed, and only one time when needed) use more concise rules ideas came from bug #4280, along with some of the implementation tested against make-3.80 and make-3.79.1 tested against 2.6.11.10, 2.4.30 and 2.6.8-(mumble) SUSE kernels git-svn-id: http://svn.digium.com/svn/zaptel/trunk@650 5390a7c7-147a-4af0-8ec9-7488f05a26cb
-rwxr-xr-xMakefile255
1 files changed, 131 insertions, 124 deletions
diff --git a/Makefile b/Makefile
index 2c01b79..c4bb101 100755
--- a/Makefile
+++ b/Makefile
@@ -1,29 +1,40 @@
#
-# Makefile for tormenta/carrier driver and utilities
-# $Id$
+# Makefile for Zaptel driver modules and utilities
#
-BASEADDR=0xd0000
-
+# Copyright (C) 2001-2005 Digium, Inc.
#
-# 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).
#
+BASEADDR=0xd0000
+
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)
+# 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
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)
+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)
+CFLAGS+=$(CFLAGS_PPC) $(CFLAGS_X64-64)
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$(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
+KFLAGS_PPC:=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
+KFLAGS+=$(KFLAGS_PPC)
+
#
# Features are now configured in zconfig.h
#
@@ -38,124 +49,135 @@ INSTALL_PREFIX=$(DESTDIR)
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 (2.6,$(shell echo $(KVERS) | cut -d. -f1-2))
+ BUILDVER:=linux26
+else
+ BUILDVER:=linux24
+endif
+
+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
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")
+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")
+DYNFS:=$(shell ps ax | grep -v grep | grep udevd && echo "yes")
endif
-CHKCONFIG=$(shell sh -c 'type -p chkconfig' 2> /dev/null)
-ifeq ($(CHKCONFIG),)
-CHKCONFIG=:
+CHKCONFIG:=$(shell sh -c 'type -p chkconfig' 2> /dev/null)
+ifndef CHKCONFIG
+CHKCONFIG:=:
endif
-TZOBJS=zonedata.lo tonezone.lo
-LIBTONEZONE=libtonezone.so.1.0
-MODULES=zaptel tor2 torisa wcusb wcfxo wctdm \
- ztdynamic ztd-eth wct1xxp wct4xxp wcte11xp pciradio \
- ztd-loc # ztdummy
+TZOBJS:=zonedata.lo tonezone.lo
+LIBTONEZONE:=libtonezone.so.1.0
+MODULES:=zaptel tor2 torisa wcusb wcfxo wctdm \
+ ztdynamic ztd-eth wct1xxp wct4xxp wcte11xp pciradio \
+ ztd-loc # ztdummy
#MODULES+=wcfxsusb
+# build ztdummy by default for 2.6 kernels
+ifeq (${BUILDVER},linux26)
+MODULES+=ztdummy
+endif
+MODULESO:=$(MODULES:%=%.o)
+MODULESKO:=$(MODULES:%=%.ko)
-MODULESO=$(shell for x in $(MODULES); do echo "$$x.o "; done )
-MODULESKO=$(shell for x in $(MODULES); do echo "$$x.ko "; done )
-
-ZTTOOL=$(shell if [ -f /usr/include/newt.h ]; then echo zttool; fi)
+ifneq (,$(wildcard /usr/include/newt.h))
+ZTTOOL:=zttool
+endif
BINS=ztcfg torisatool makefw ztmonitor ztspeed $(ZTTOOL) zttest fxotune
#PRIMARY=wcfxsusb
PRIMARY=torisa
#PRIMARY=wcfxo
-PWD=$(shell pwd)
-KERNEL_SOURCE?=/lib/modules/`uname -r`
+PWD:=$(shell pwd)
all: $(BUILDVER) $(LIBTONEZONE)
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)/build SUBDIRS=$(PWD) modules
+ @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) ztdummy.o
+obj-m := $(MODULESO)
#ifneq ($(TOPDIR),)
#include $(TOPDIR)/Rules.make
#endif
-MOD_DESTDIR := zaptel
+MOD_DESTDIR:=zaptel
devel: tor2ee
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
+tor2.o: tor2-hw.h tor2fw.h zaptel.h
-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
+zaptel.o: zaptel.h digits.h arith.h sec.h mec.h sec-2.h mec2.h mec3.h zconfig.h
-torisa.o: torisa.c zaptel.h torisa.h
- $(HOSTCC) $(KFLAGS) -c torisa.c
+torisa.o: zaptel.h torisa.h
-wcusb.o: wcusb.c wcusb.h zaptel.h
- $(HOSTCC) $(KFLAGS) -c wcusb.c
+wcusb.o: wcusb.h zaptel.h
-wcfxsusb.o: wcfxsusb.c wcfxsusb.h zaptel.h
- $(HOSTCC) $(KFLAGS) -c wcfxsusb.c
+wcfxsusb.o: wcfxsusb.h zaptel.h
-wcfxo.o: wcfxo.c zaptel.h
- $(HOSTCC) $(KFLAGS) -c wcfxo.c
+wcfxo.o: zaptel.h
-wct1xxp.o:wct1xxp.c zaptel.h
- $(HOSTCC) $(KFLAGS) -c wct1xxp.c
+wct1xxp.o: zaptel.h
-wcte11xp.o:wcte11xp.c zaptel.h
- $(HOSTCC) $(KFLAGS) -c wcte11xp.c
+wcte11xp.o: zaptel.h
-ztd-loc.o:ztd-loc.c zaptel.h
- $(HOSTCC) $(KFLAGS) -c ztd-loc.c
+ztd-loc.o: zaptel.h
-wct4xxp.o:wct4xxp.c zaptel.h
- $(HOSTCC) $(KFLAGS) -c wct4xxp.c
+wct4xxp.o: zaptel.h
-wctdm.o:wctdm.c zaptel.h wctdm.h
- $(HOSTCC) $(KFLAGS) -c wctdm.c
+wctdm.o: zaptel.h wctdm.h
-pciradio.o:pciradio.c zaptel.h radfw.h
- $(HOSTCC) $(KFLAGS) -c pciradio.c
+pciradio.o: zaptel.h radfw.h
-wcs3200p.o:wcs3200p.c zaptel.h
- $(HOSTCC) $(KFLAGS) -c wcs3200p.c
+wcs3200p.o: zaptel.h
-ztdummy.o:ztdummy.c ztdummy.h
- $(HOSTCC) $(KFLAGS) -c ztdummy.c
+ztdummy.o: ztdummy.h
-ztdynamic.o: ztdynamic.c zaptel.h
- $(HOSTCC) $(KFLAGS) -c ztdynamic.c
+ztdynamic.o: zaptel.h
-ztd-eth.o: ztd-eth.c zaptel.h
- $(HOSTCC) $(KFLAGS) -c ztd-eth.c
+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 tor2ee tor2ee.o -lpci
+ $(CC) $(CFLAGS) -o $@ $^ -lpci
zonedata.lo: zonedata.c
- $(CC) -c $(LCFLAGS) -o zonedata.lo zonedata.c
+ $(CC) -c $(LCFLAGS) -o $@ $^
tonezone.lo: tonezone.c
- $(CC) -c $(LCFLAGS) -o tonezone.lo tonezone.c
+ $(CC) -c $(LCFLAGS) -o $@ $^
torisatool: torisatool.o
- $(CC) -o torisatool torisatool.o
+ $(CC) -o $@ $^
tones.h: gendigits
./gendigits
@@ -167,7 +189,7 @@ radfw.h: makefw pciradio.rbt
./makefw pciradio.rbt radfw > radfw.h
gendigits: gendigits.o
- $(CC) -o gendigits gendigits.o -lm
+ $(CC) -o $@ $^ -lm
zaptel.c: tones.h
@@ -180,78 +202,69 @@ ztprovision.o: ztprovision.c zaptel.h
ztmonitor.o: ztmonitor.c zaptel.h
ztspeed.o: ztspeed.c
- $(CC) -c ztspeed.c
+ $(CC) -o $@ -c $^
zttool: zttool.o
- $(CC) -o zttool zttool.o -lnewt
-
-ztprovision: ztprovision.o
- $(CC) -o ztprovision ztprovision.o -lnewt
+ $(CC) -o $@ $^ -lnewt
ztmonitor: ztmonitor.o
- $(CC) -o ztmonitor ztmonitor.o
-
-ztcat: ztcat.o
- $(CC) -o ztcat ztcat.o -ltonezone
+ $(CC) -o $@ $^
ztspeed: ztspeed.o
- $(CC) -o ztspeed ztspeed.o
+ $(CC) -o $@ $^
sethdlc-new: sethdlc-new.o
- $(CC) -o sethdlc-new sethdlc-new.o
+ $(CC) -o $@ $^
sethdlc-new.o: sethdlc-new.c
- $(CC) -c $(CFLAGS) -I$(KINCLUDES) sethdlc-new.c
+ $(CC) -o $@ -c $(CFLAGS) -I$(KINCLUDES) $^
libtonezone.a: $(TZOBJS)
ar rcs libtonezone.a $(TZOBJS)
$(LIBTONEZONE): $(TZOBJS)
- $(CC) -shared -Wl,-soname,$(LIBTONEZONE) -lm -o $@ $(TZOBJS)
- [ `id -u` = 0 ] && /sbin/ldconfig || :
- ln -sf $(LIBTONEZONE) libtonezone.so
- ln -sf $(LIBTONEZONE) libtonezone.so.1
+ $(CC) -shared -Wl,-soname,$(LIBTONEZONE) -lm -o $@ $^
ztcfg.c: ztcfg.h
ztcfg-shared: ztcfg.o $(LIBTONEZONE)
- $(CC) -o ztcfg-shared ztcfg.o -lm -L. -ltonezone
+ $(CC) -o $@ $^ -lm
ztcfg: ztcfg.o libtonezone.a
- $(CC) -o ztcfg ztcfg.o -lm -L. libtonezone.a
+ $(CC) -o $@ $^ -lm
ztcfg-dude: ztcfg-dude.o mknotch.o complex.o $(LIBTONEZONE)
- $(CC) -o ztcfg ztcfg-dude.o mknotch.o complex.o -lm -L. -ltonezone
+ $(CC) -o $@ $^ -lm
mknotch.o: mknotch.cc
- $(CC) -c mknotch.cc
+ $(CC) -o $@ -c $^
complex.o: complex.cc
- $(CC) -c complex.cc
+ $(CC) -o $@ -c $^
usbfxstest.o: usbfxstest.c
- $(CC) -g -c usbfxstest.c
+ $(CC) -o $@ -g -c $^
usbfxstest: usbfxstest.o
- $(CC) -o usbfxstest usbfxstest.o -lzap
+ $(CC) -o $@ $^ -lzap
-fxstest: fxstest.o
- $(CC) -o fxstest fxstest.o -L. -ltonezone -lm
+fxstest: fxstest.o $(LIBTONEZONE)
+ $(CC) -o $@ $^ -lm
fxotune: fxotune.o
- $(CC) -o fxotune fxotune.o -lm
+ $(CC) -o $@ $^ -lm
fxsdump: fxsdump.o
- $(CC) -o fxsdump fxsdump.o -lm
+ $(CC) -o $@ $^ -lm
stackcheck: checkstack $(BUILDVER)
./checkstack *.o
ztdiag: ztdiag.o
- $(CC) -o ztdiag ztdiag.o
+ $(CC) -o $@ $^
devices:
-ifeq ($(DYNFS),)
+ifndef DYNFS
mkdir -p $(INSTALL_PREFIX)/dev/zap
rm -f $(INSTALL_PREFIX)/dev/zap/ctl
rm -f $(INSTALL_PREFIX)/dev/zap/channel
@@ -271,12 +284,12 @@ ifeq ($(DYNFS),)
mknod $(INSTALL_PREFIX)/dev/zap/$$N c 196 $$N; \
N=$$[$$N+1]; \
done
-else
+else # DYNFS
@echo "**** Dynamic filesystem detected -- not creating device nodes"
@echo "**** If you are running udev, read README.udev"
endif
-install: all devices
+install: all devices
install -D -m 755 ztcfg $(INSTALL_PREFIX)/sbin/ztcfg
if [ -f sethdlc-new ]; then \
install -D -m 755 sethdlc-new $(INSTALL_PREFIX)/sbin/sethdlc; \
@@ -284,32 +297,28 @@ install: all devices
install -D -m 755 sethdlc $(INSTALL_PREFIX)/sbin/sethdlc ; \
fi
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)/$(KERNEL_SOURCE)/misc/$$x ; \
- done; \
+ $(MAKE) -C $(KSRC) SUBDIRS=$(PWD) INSTALL_MOD_PATH=$(INSTALL_PREFIX) modules_install; \
if ! [ -f wcfxsusb.ko ]; then \
- rm -f $(INSTALL_PREFIX)/$(KERNEL_SOURCE)/misc/wcfxsusb.ko; \
+ rm -f $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/wcfxsusb.ko; \
fi; \
- rm -f $(INSTALL_PREFIX)/$(KERNEL_SOURCE)/misc/wcfxs.ko; \
+ rm -f $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/wcfxs.ko; \
else \
for x in $(MODULESO); do \
- install -D -m 644 $$x $(INSTALL_PREFIX)/$(KERNEL_SOURCE)/misc/$$x ; \
+ install -D -m 644 $$x $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/$$x ; \
done; \
if ! [ -f wcfxsusb.o ]; then \
- rm -f $(INSTALL_PREFIX)/$(KERNEL_SOURCE)/misc/wcfxsusb.o; \
+ rm -f $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/wcfxsusb.o; \
fi; \
- rm -f $(INSTALL_PREFIX)/$(KERNEL_SOURCE)/misc/wcfxs.o; \
+ rm -f $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/wcfxs.o; \
fi
-
install -D -m 755 $(LIBTONEZONE) $(INSTALL_PREFIX)/usr/lib/$(LIBTONEZONE)
if [ -x /usr/sbin/sestatus ] && (/usr/sbin/sestatus | grep "SELinux status:" | grep -q "enabled") ; then restorecon -v $(INSTALL_PREFIX)/usr/lib/$(LIBTONEZONE); fi
install -D -m 644 zaptel.h $(INSTALL_PREFIX)/usr/include/linux/zaptel.h
install -D -m 644 torisa.h $(INSTALL_PREFIX)/usr/include/linux/torisa.h
install -D -m 644 tonezone.h $(INSTALL_PREFIX)/usr/include/tonezone.h
- ( cd $(INSTALL_PREFIX)/usr/lib ; rm -f libtonezone.so ; ln -sf $(LIBTONEZONE) libtonezone.so )
- ( cd $(INSTALL_PREFIX)/usr/lib ; rm -f libtonezone.so.1 ; ln -sf $(LIBTONEZONE) libtonezone.so.1 )
+ rm -f $(INSTALL_PREFIX)/usr/lib/libtonezone.so
+ rm -f $(INSTALL_PREFIX)/usr/lib/libtonezone.so.1
[ `id -u` = 0 ] && /sbin/ldconfig || :
if [ -f $(MODCONF) ]; then mv -f $(MODCONF) $(MODCONF).bak ; fi
cat $(MODCONF).bak | grep -v "alias char-major-250" | \
@@ -335,8 +344,7 @@ install: all devices
done
if ! grep "alias wcfxs" $(MODCONF); then \
echo "alias wcfxs wctdm" >> $(MODCONF); \
- fi \
-
+ fi
if [ -d /etc/modutils ]; then \
/sbin/update-modules ; \
fi
@@ -385,4 +393,3 @@ clean:
rm -f tor2ee
rm -f fxotune
rm -f core
-