summaryrefslogtreecommitdiff
path: root/Makefile
blob: b5ed3af3abfeef7dc39a0dbc7507bb80429ccca3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
#
# Makefile for Zaptel driver modules and utilities
#
# Copyright (C) 2001-2006 Digium, Inc.
#
#

.EXPORT_ALL_VARIABLES:

HOSTCC=gcc
ifeq ($(PWD),)
PWD=$(shell pwd)
endif
ifeq ($(DEB_HOST_GNU_TYPE),)
UNAME_M:=$(shell uname -m)
else
UNAME_M:=$(DEB_HOST_GNU_TYPE)
endif
# 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
KVERS_MAJ:=$(shell echo $(KVERS) | cut -d. -f1-2)
KINCLUDES:=$(KSRC)/include

CFLAGS+=-I. -Iinclude -O4 -g -Wall -DBUILDING_TONEZONE #-DTONEZONE_DRIVER
ifneq (,$(findstring ppc,$(UNAME_M)))
CFLAGS_PPC:=-fsigned-char
endif
ifneq (,$(findstring x86_64,$(UNAME_M)))
CFLAGS_X86-64:=-m64
endif
CFLAGS+=$(CFLAGS_PPC) $(CFLAGS_X86-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
ifneq (,$(wildcard $(KINCLUDES)/linux/modversions.h))
  KFLAGS+=-DMODVERSIONS -include $(KINCLUDES)/linux/modversions.h
endif
ifneq (,$(findstring ppc,$(UNAME_M)))
KFLAGS_PPC:=-msoft-float -fsigned-char
endif
KFLAGS+=$(KFLAGS_PPC)
ifeq ($(KVERS_MAJ),2.4)
  ifneq (,$(findstring x86_64,$(UNAME_M)))
    KFLAGS+=-mcmodel=kernel
  endif
endif

#
# Features are now configured in zconfig.h
#

KFLAGS+=-DSTANDALONE_ZAPATA
CFLAGS+=-DSTANDALONE_ZAPATA
KMAKE  = $(MAKE) -C $(KSRC) SUBDIRS=$(PWD)
KMAKE_INST = $(KMAKE) \
  INSTALL_MOD_PATH=$(INSTALL_PREFIX) INSTALL_MOD_DIR=misc modules_install

ROOT_PREFIX=
INSTALL_PREFIX=$(DESTDIR)

CONFIG_FILE=$(INSTALL_PREFIX)/etc/zaptel.conf
CFLAGS+=-DZAPTEL_CONFIG=\"$(CONFIG_FILE)\"

ifeq ($(KVERS_MAJ),2.4)
  BUILDVER:=linux24
else
  BUILDVER:=linux26
endif

# This is not related to the version that we build. Rather, to the 
# version that we runs. If we build for 2.4 using 2.4 headers on a 2.6
# system with udev mounted on /dev , no point in installing files to /dev
# because they'll be wiped at next reboot.
DYNFS:=$(shell ps ax | grep -v grep | grep -qw 'devfsd\|udevd' && echo "yes")

# Check for udev rules directories
ifneq (,$(wildcard $(ROOT_PREFIX)/etc/udev/rules.d))
  UDEVRULES=yes
endif

CHKCONFIG:=$(shell sh -c 'type -p chkconfig' 2> /dev/null)
ifndef CHKCONFIG
CHKCONFIG:=:
endif

ifneq ($(wildcard .version),)
  ZAPTELVERSION:=$(shell cat .version)
endif

ifneq ($(wildcard .svn),)
  ZAPTELVERSION=SVN-$(shell build_tools/make_svn_branch_name)
endif

TZOBJS:=zonedata.lo tonezone.lo
LIBTONEZONE_SO:=libtonezone.so
LIBTONEZONE_SO_MAJOR_VER:=1
LIBTONEZONE_SO_MINOR_VER:=0

MODULES:=zaptel tor2 torisa wcusb wcfxo wctdm wctdm24xxp \
	 ztdynamic ztd-eth wct1xxp wct4xxp wcte11xp pciradio \
         ztd-loc zttranscode
#MODULES+=wcfxsusb
# build ztdummy by default for 2.6 kernels
ifeq ($(BUILDVER),linux26)
MODULES+=ztdummy
endif

MODULESO:=$(MODULES:%=%.o)
MODULESKO:=$(MODULES:%=%.ko)
ifeq ($(BUILDVER),linux26)
MODULES_BUILD:=$(MODULESKO)
else
MODULES_BUILD:=$(MODULESO)
endif

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

MOD_DESTDIR:=zaptel

EXTRA_CFLAGS:=-I$(PWD)/include  -I$(PWD)/include/oct6100api
obj-m:=$(MODULESO)
wct4xxp-objs:=wct4xxp_base.o vpm450m.o

# Also build xpp in the subdirectory xpp/ . But only for >=2.6.10 and only 
# for i386. On other archs the module will probably build but panic.
# This line is only meaningful when this Makefile is used as kconfig for 
# 2.6 build

ifneq (,$(shell [ 0$(SUBLEVEL) -ge 10 ] && [ "$(ARCH)" = 'i386' ] && echo 1))
obj-m+=xpp/
endif

ifneq (,$(wildcard /usr/include/newt.h))
ZTTOOL:=zttool
endif
BINS:=ztcfg ztmonitor ztspeed $(ZTTOOL) zttest fxotune
UTILS:=tor2ee ztspeed zttool ztmonitor sethdlc-new \
  usbfxstest fxstest fxotune fxsdump ztdiag
UTILSO:=$(UTILS:%=%.o)

all: modules $(LIBTONEZONE_SO)

programs: $(BINS)

modules: $(BUILDVER)

linux24: prereq vpm450m_fw.h $(MODULESO) $(BINS)

linux26: prereq vpm450m_fw.h $(BINS)
	@if [ -z "$(KSRC)" -o ! -d "$(KSRC)" ]; then echo "You do not appear to have the sources for the $(KVERS) kernel installed."; exit 1 ; fi
	$(KMAKE) modules

xpp: linux26

#ifneq ($(TOPDIR),)
#include $(TOPDIR)/Rules.make
#endif

version.h: FORCE
	@ZAPTELVERSION="${ZAPTELVERSION}" build_tools/make_version_h > $@.tmp
	@if cmp -s $@.tmp $@ ; then :; else \
		mv $@.tmp $@ ; \
	fi
	@rm -f $@.tmp

devel: tor2ee 

tests: patgen pattest patlooptest hdlcstress hdlctest hdlcgen hdlcverify timertest

tor2.o: tor2-hw.h tor2fw.h

zaptel.o: digits.h arith.h sec.h mec.h sec-2.h mec2.h mec3.h zconfig.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

$(filter-out wct4xxp.o,$(MODULESO)) wct4xxp_base.o: %.o: %.c zaptel.h
	$(CC) $(KFLAGS) -o $@ -c $<

vpm450m.o: vpm450m.c zaptel.h
	$(CC) $(KFLAGS) -I$(PWD)/include  -I$(PWD)/include/oct6100api -o $@ -c $<

wct4xxp.o: wct4xxp_base.o vpm450m.o
	$(LD) -r -o $@ wct4xxp_base.o vpm450m.o

tor2ee.o: tor2-hw.h

tor2ee: LDFLAGS+=-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: tormenta2.rbt makefw 
	./makefw $< tor2fw > $@

radfw.h: pciradio.rbt makefw
	./makefw $< radfw > $@

makefw: CFLAGS=

gendigits: LDFLAGS+=-lm
gendigits: CFLAGS=

fw2h: CFLAGS=

vpm450m_fw.h: OCT6114-128D.ima fw2h
	./fw2h $< $@

zaptel.c: tones.h 

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: CFLAGS=
ztspeed.o: CFLAGS=
zttool: LDFLAGS+=-lnewt
sethdlc-new.o: 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

data:
	$(MAKE) -C datamods datamods

ztcfg: ztcfg.o libtonezone.a
	$(CC) -o $@ $^ -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: LDFLAGS+=-lzap
fxstest: $(LIBTONEZONE_SO)
fxstest: LDFLAGS+=-lm
fxotune: LDFLAGS+=-lm
fxsdump: LDFLAGS+=-lm

stackcheck: checkstack $(BUILDVER)
	./checkstack *.o

b410p:
	@wget -V >/dev/null || (echo "You need wget in order to install the drivers" ; false)
	[ -f misdn-b410p.tar.bz ] || 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

$(UTILS): %: %.o
	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)

$(UTILSO): %.o: %.c
	$(CC) $(CFLAGS) -o $@ -c $<

devices:
ifndef 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/transcode c 196 250
	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 # DYNFS
  ifdef UDEVRULES
	build_tools/genudevrules > $(INSTALL_PREFIX)/etc/udev/rules.d/zaptel.rules
  else # !UDEVRULES
	@echo "**** Dynamic filesystem detected -- not creating device nodes"
  endif
endif

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; \
	elif [ -f sethdlc ]; then \
		install -D -m 755 sethdlc $(INSTALL_PREFIX)/sbin/sethdlc ; \
	fi
	if [ -f zttool ]; then install -D -m 755 zttool $(INSTALL_PREFIX)/sbin/zttool; fi
ifeq ($(BUILDVER),linux26)
	for x in $(MODULESKO); do \
		rm -f $(INSTALL_PREFIX)/lib/modules/$(KVERS)/extra/$$x ; \
	done; \
	$(KMAKE_INST); \
	if [ -f datamods/syncppp.ko ]; then \
		$(MAKE) -C datamods install; \
	else \
		rm -f $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/{hdlc_*,syncppp}.ko; \
	fi
else
	for x in $(MODULESO); do \
		install -D -m 644 $$x $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/$$x ; \
	done
endif
	if ! [ -f wcfxsusb.o ]; then \
		rm -f $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/wcfxsusb.o; \
	fi; \
	rm -f $(INSTALL_PREFIX)/lib/modules/$(KVERS)/misc/wcfxs.o
	install -D -m 755 $(LIBTONEZONE_SO) $(INSTALL_PREFIX)/usr/lib/$(LIBTONEZONE_SO).$(LIBTONEZONE_SO_MAJOR_VER).$(LIBTONEZONE_SO_MINOR_VER)
	[ `id -u` = 0 ] && /sbin/ldconfig || :
	rm -f $(INSTALL_PREFIX)/usr/lib/$(LIBTONEZONE_SO)
	ln -sf $(LIBTONEZONE_SO).$(LIBTONEZONE_SO_MAJOR_VER).$(LIBTONEZONE_SO_MINOR_VER) \
		$(INSTALL_PREFIX)/usr/lib/$(LIBTONEZONE_SO).$(LIBTONEZONE_SO_MAJOR_VER)
	ln -sf $(LIBTONEZONE_SO).$(LIBTONEZONE_SO_MAJOR_VER).$(LIBTONEZONE_SO_MINOR_VER) \
		$(INSTALL_PREFIX)/usr/lib/$(LIBTONEZONE_SO)
	if [ -x /usr/sbin/sestatus ] && (/usr/sbin/sestatus | grep "SELinux status:" | grep -q "enabled") ; then restorecon -v $(INSTALL_PREFIX)/usr/lib/$(LIBTONEZONE_SO); fi
	install -D -m 644 zaptel.h $(INSTALL_PREFIX)/usr/include/zaptel.h
	install -D -m 644 torisa.h $(INSTALL_PREFIX)/usr/include/torisa.h
	rm -f $(INSTALL_PREFIX)/usr/include/linux/zaptel.h
	rm -f $(INSTALL_PREFIX)/usr/include/linux/torisa.h
	install -D -m 644 tonezone.h $(INSTALL_PREFIX)/usr/include/tonezone.h
	install -m 644 doc/ztcfg.8 $(INSTALL_PREFIX)/usr/share/man/man8
	install -m 644 doc/zttool.8 $(INSTALL_PREFIX)/usr/share/man/man8
	[ `id -u` = 0 ] && /sbin/depmod -a $(KVERS) || :
	[ -f $(CONFIG_FILE) ] || install -D -m 644 zaptel.conf.sample $(CONFIG_FILE)
	build_tools/genmodconf $(BUILDVER) "$(ROOT_PREFIX)" "$(filter-out zaptel,$(MODULES))"
	@if [ -d /etc/modutils ]; then \
		/sbin/update-modules ; \
	fi

install-udev: devices

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; \
	elif [ -d $(INSTALL_PREFIX)/etc/init.d ]; then \
		install -D -m 755 zaptel.init $(INSTALL_PREFIX)/etc/init.d/zaptel; \
		$(CHKCONFIG) --add zaptel; \
	fi 
	if [ -d /etc/default ] && [ ! -f /etc/default/zaptel ]; then \
			install -D -m 644 zaptel.sysconfig $(INSTALL_PREFIX)/etc/default/zaptel; \
	fi
	if [ -d /etc/sysconfig ] && [ ! -f /etc/sysconfig/zaptel ]; then \
		install -D -m 644 zaptel.sysconfig $(INSTALL_PREFIX)/etc/sysconfig/zaptel; \
	fi
	if [ -d /etc/sysconfig/network-scripts ]; then \
		install -D -m 755 ifup-hdlc $(INSTALL_PREFIX)/etc/sysconfig/network-scripts/ifup-hdlc; \
	fi

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

# 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: vpm450m_fw.h.o$(MODULES_BUILD)
	install -d $(MOD_DIR)
	install -m 644 $(MODULES_BUILD) $(MOD_DIR)

install-linux26: $(MODULESKO)
	$(KMAKE_INST)

clean:
	rm -f torisatool makefw tor2fw.h radfw.h fw2h
	rm -f $(BINS)
	rm -f *.o ztcfg tzdriver sethdlc sethdlc-new
	rm -f $(TZOBJS) $(LIBTONEZONE_SO) *.lo
ifeq ($(BUILDVER),linux26)
	$(KMAKE) clean
	$(MAKE) -C datamods clean
endif
	rm -f xpp/*.ko xpp/*.mod.c xpp/.*o.cmd
	rm -f xpp/*.o xpp/*.mod.o
	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*
	rm -f fw2h vpm450m_fw.h

FORCE: