[Asterisk-Dev] [PATCH] zaptel Makefile cleanup
Steven Pritchard
steve at silug.org
Mon Aug 23 00:03:04 MST 2004
The following patch cleans up a few things that should simplify
packaging zaptel significantly.
* KVERSION (which defaults to `uname -r`) can be used to compile the
kernel bits for any arbitrary kernel.
* Kernel source should be in /lib/modules/$(KVERSION)/build, so look
there first.
* Allow the user to override optimization-related compiler flags
(OPTFLAGS and KOPTFLAGS).
* Allow installation as a non-root user.
With this modified Makefile, I'm able to build everything on Fedora
Core 2 with just the kernel installed (no kernel-sourcecode package).
For the most part, the modified Makefile should build & install no
differently than before with these changes, so hopefully there's
nothing controversial here.
Steve
--
Steven Pritchard - K&S Pritchard Enterprises, Inc.
Email: steve at kspei.com http://www.kspei.com/
Phone: (618)398-7360 Mobile: (618)567-7320
Index: Makefile
===================================================================
RCS file: /usr/cvsroot/zaptel/Makefile,v
retrieving revision 1.51
diff -u -u -r1.51 Makefile
--- Makefile 24 Jul 2004 16:03:27 -0000 1.51
+++ Makefile 23 Aug 2004 06:53:49 -0000
@@ -3,26 +3,29 @@
#
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)
-CFLAGS+=-I. -O4 -g -Wall -DBUILDING_TONEZONE #-DTONEZONE_DRIVER
+KVERSION:=$(shell uname -r)
+KSRC:=$(shell if [ -d /lib/modules/$(KVERSION)/build ]; then \
+ echo /lib/modules/$(KVERSION)/build ; \
+ else echo /usr/src/linux ; fi)
+KINCLUDES:=$(KSRC)/include
+
+OPTFLAGS:=-O4 -g
+KOPTFLAGS:=-O6
+
+CFLAGS+=-I. $(OPTFLAGS) -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)
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 [ -f $(KINCLUDES)/linux/modversions.h ] && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
-KFLAGS+=$(shell if uname -m | grep -q ppc; then echo "-msoft-float -fsigned-char"; fi)
+KFLAGS+=-I$(KINCLUDES) $(KOPTFLAGS)
+KFLAGS+=-DMODULE -D__KERNEL__ -DEXPORT_SYMTAB -I$(KSRC)/drivers/net \
+ -Wall -I. -Wstrict-prototypes -fomit-frame-pointer \
+ -I$(KSRC)/drivers/net/wan -I$(KINCLUDES) -I$(KINCLUDES)/net
+KFLAGS+=$(shell [ -f $(KINCLUDES)/linux/modversions.h ] \
+ && echo "-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h")
+KFLAGS+=$(shell if uname -m | grep -q ppc; then \
+ echo "-msoft-float -fsigned-char"; fi)
#
# Features are now configured in zconfig.h
#
@@ -69,8 +72,7 @@
linux26:
linux26: prereq $(BINS)
- @if ! [ -d /usr/src/linux-2.6 ]; then echo "Link /usr/src/linux-2.6 to your kernel sources first!"; exit 1 ; fi
- make -C /usr/src/linux-2.6 SUBDIRS=$(PWD) modules
+ make -C $(KSRC) SUBDIRS=$(PWD) modules
obj-m := $(MODULESO) ztdummy.o
@@ -223,24 +225,28 @@
devices:
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/253
- rm -f $(INSTALL_PREFIX)/dev/zap/252
- rm -f $(INSTALL_PREFIX)/dev/zap/251
- rm -f $(INSTALL_PREFIX)/dev/zap/250
- mknod $(INSTALL_PREFIX)/dev/zap/ctl c 196 0
- 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 \
- rm -f $(INSTALL_PREFIX)/dev/zap/$$N; \
- mknod $(INSTALL_PREFIX)/dev/zap/$$N c 196 $$N; \
- N=$$[$$N+1]; \
- done
+ if [ `id -u` -eq 0 ]; then \
+ 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; \
+ rm -f $(INSTALL_PREFIX)/dev/zap/250; \
+ mknod $(INSTALL_PREFIX)/dev/zap/ctl c 196 0; \
+ 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 \
+ rm -f $(INSTALL_PREFIX)/dev/zap/$$N; \
+ mknod $(INSTALL_PREFIX)/dev/zap/$$N c 196 $$N; \
+ N=$$[$$N+1]; \
+ done; \
+ else \
+ echo "Not root - skipping device creation."; \
+ fi
else
@echo "**** Dynamic filesystem detected -- not creating device nodes"
@echo "**** If you are running udev, read README.udev"
@@ -255,21 +261,21 @@
install -m 755 sethdlc $(INSTALL_PREFIX)/sbin ; \
fi
if [ -f zttool ]; then install -m 755 zttool $(INSTALL_PREFIX)/sbin; fi
- mkdir -p $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc
+ mkdir -p $(INSTALL_PREFIX)/lib/modules/$(KVERSION)/misc
if [ -f zaptel.ko ]; then \
for x in $(MODULESKO) ztdummy.ko; do \
- install -m 644 $$x $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc ; \
+ install -m 644 $$x $(INSTALL_PREFIX)/lib/modules/$(KVERSION)/misc ; \
done; \
if ! [ -f wcfxsusb.ko ]; then \
- rm -f $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/wcfxsusb.o; \
+ rm -f $(INSTALL_PREFIX)/lib/modules/$(KVERSION)/misc/wcfxsusb.o; \
fi; \
else \
for x in $(MODULESO); do \
- install -m 644 $$x $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc ; \
+ install -m 644 $$x $(INSTALL_PREFIX)/lib/modules/$(KVERSION)/misc ; \
done; \
if ! [ -f wcfxsusb.o ]; then \
- rm -f $(INSTALL_PREFIX)/lib/modules/`uname -r`/misc/wcfxsusb.ko; \
+ rm -f $(INSTALL_PREFIX)/lib/modules/$(KVERSION)/misc/wcfxsusb.ko; \
fi; \
fi
@@ -281,43 +287,49 @@
install -m 644 torisa.h $(INSTALL_PREFIX)/usr/include/linux
install -m 644 tonezone.h $(INSTALL_PREFIX)/usr/include
( cd $(INSTALL_PREFIX)/usr/lib ; rm -f libtonezone.so ; ln -sf $(LIBTONEZONE) libtonezone.so )
- /sbin/ldconfig
- if [ -f $(MODCONF) ]; then mv -f $(MODCONF) $(MODCONF).bak ; fi
- cat $(MODCONF).bak | grep -v "alias char-major-250" | \
- grep -v "post-install torisa /sbin/ztcfg" | \
- grep -v "post-install wcfxsusb /sbin/ztcfg" | \
- grep -v "post-install wcfxs /sbin/ztcfg" > $(MODCONF) || true
- if ! grep "options torisa" $(MODCONF); then \
- echo "options torisa base=$(BASEADDR)" >> $(MODCONF); \
- fi
- if ! grep "alias char-major-196" $(MODCONF); then \
- echo "alias char-major-196 $(PRIMARY)" >> $(MODCONF); \
- fi
-
- for x in $(MODULES); do \
- if ! grep "post-install $$x" $(MODCONF); then \
- if ! grep "install $$x " $(MODCONF); then \
- if [ "$$x" != "zaptel" ] ; then \
- if [ -f zaptel.ko ]; then echo "install $$x /sbin/modprobe --ignore-install $$x && /sbin/ztcfg" >> $(MODCONF); \
- else echo "post-install $$x /sbin/ztcfg" >> $(MODCONF); \
+ [ `id -u` = 0 ] && /sbin/ldconfig || :
+ if [ -f $(MODCONF) ]; then \
+ mv -f $(MODCONF) $(MODCONF).bak; \
+ cat $(MODCONF).bak | grep -v "alias char-major-250" | \
+ grep -v "post-install torisa /sbin/ztcfg" | \
+ grep -v "post-install wcfxsusb /sbin/ztcfg" | \
+ grep -v "post-install wcfxs /sbin/ztcfg" > $(MODCONF) || true; \
+ if ! grep -q "options torisa" $(MODCONF); then \
+ echo "options torisa base=$(BASEADDR)" >> $(MODCONF); \
+ fi; \
+ if ! grep -q "alias char-major-196" $(MODCONF); then \
+ echo "alias char-major-196 $(PRIMARY)" >> $(MODCONF); \
+ fi; \
+ for x in $(MODULES); do \
+ if ! grep -q "post-install $$x" $(MODCONF); then \
+ if ! grep -q "install $$x " $(MODCONF); then \
+ if [ "$$x" != "zaptel" ] ; then \
+ if [ -f zaptel.ko ]; then \
+ echo "install $$x /sbin/modprobe --ignore-install $$x && /sbin/ztcfg" >> $(MODCONF); \
+ else \
+ echo "post-install $$x /sbin/ztcfg" >> $(MODCONF); \
+ fi; \
fi; \
fi; \
fi; \
- fi; \
- done
+ done; \
+ fi
if [ -d /etc/modutils ]; then \
/sbin/update-modules ; \
fi
- -/sbin/depmod -a
+ [ `id -u` = 0 ] && /sbin/depmod -a $(KVERSION) || :
[ -f $(INSTALL_PREFIX)/etc/zaptel.conf ] || install -m 644 zaptel.conf.sample $(INSTALL_PREFIX)/etc/zaptel.conf
config:
if [ -d $(INSTALL_PREFIX)/etc/rc.d/init.d ]; then \
install -m 755 zaptel.init $(INSTALL_PREFIX)/etc/rc.d/init.d/zaptel; \
- chkconfig --add zaptel; \
+ [ -x /sbin/chkconfig -a `id -u` = 0 ] && \
+ /sbin/chkconfig --add zaptel ||:; \
elif [ -d $(INSTALL_PREFIX)/etc/init.d ]; then \
install -m 755 zaptel.init $(INSTALL_PREFIX)/etc/init.d/zaptel; \
+ [ -x /sbin/chkconfig -a `id -u` = 0 ] && \
+ /sbin/chkconfig --add zaptel ||:; \
fi
if [ ! -f /etc/sysconfig/zaptel ]; then \
install -m 644 zaptel.sysconfig $(INSTALL_PREFIX)/etc/sysconfig/zaptel; \
More information about the asterisk-dev
mailing list