summaryrefslogtreecommitdiff
path: root/xpp/utils/Makefile
blob: d23b50da5333c1eb48b0e16859f1f9249847d564 (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
PEDANTIC	= -ansi -pedantic -std=c99

RANLIB		= ranlib
INSTALL		= install
INSTALL_DATA	= install -m 644

TOPDIR		?= ../..

-include $(TOPDIR)/makeopts

INSTALL_DATA	= $(INSTALL) -m 644

BINDIR    = $(prefix)/sbin
DATADIR   = $(datadir)/zaptel
MANDIR    = $(mandir)/man8

# In 1.4 those are provided by autoconf through makeopts
prefix		?= /usr
datadir		?= $(prefix)/share
mandir		?= $(datadir)/man
INSTALL		?= install

INSTALL_DATA	= $(INSTALL) -m 644

BINDIR   = $(prefix)/sbin
DATADIR   = $(datadir)/zaptel
MANDIR    = $(mandir)/man8
HOTPLUG_USB_DIR = /etc/hotplug/usb
UDEV_RULES_DIR	= /etc/udev/rules.d

XPD_FIRMWARE	= $(wildcard ../firmwares/*.hex)
XPD_INIT_DATA	= $(XPD_FIRMWARE) init_fxo_modes
XPD_INIT	= $(wildcard ../init_card_?_*) ../calibrate_slics

# Variables that should be defined above, but need sane defaults:
# FIXME: Are those values really sane?
HOSTCC		?= $(CC)
CONFIG_USB	?= y
ZAPTEL_DIR	?= ../..

WCTDM=$(ZAPTEL_DIR)/wctdm.c

CFLAGS		= -g -Wall $(EXTRA_CFLAGS)

TARGETS	= init_fxo_modes print_modes adj_clock
PROG_INSTALL	= genzaptelconf adj_clock
MAN_INSTALL	= genzaptelconf.8 adj_clock.8
ifneq	(,$(filter y m,$(CONFIG_USB)))
TARGETS	+= libhexfile.a fpga_load test_parse
PROG_INSTALL	+= fpga_load
MAN_INSTALL	+= fpga_load.8
endif

all: $(TARGETS)

install: all
	$(INSTALL) -d $(DESTDIR)$(BINDIR)
	$(INSTALL) $(PROG_INSTALL) $(DESTDIR)$(BINDIR)/
	$(INSTALL) -d $(DESTDIR)$(DATADIR)
	$(INSTALL_DATA) $(XPD_INIT_DATA) $(DESTDIR)$(DATADIR)/
	$(INSTALL) $(XPD_INIT) $(DESTDIR)$(DATADIR)/
	$(INSTALL) -d $(DESTDIR)$(MANDIR)
	$(INSTALL_DATA) $(MAN_INSTALL) $(DESTDIR)$(MANDIR)/
	$(INSTALL) -d $(DESTDIR)$(HOTPLUG_USB_DIR)
	$(INSTALL_DATA) xpp_fxloader.usermap $(DESTDIR)$(HOTPLUG_USB_DIR)/
	$(INSTALL) xpp_fxloader $(DESTDIR)$(HOTPLUG_USB_DIR)/
	$(INSTALL) -d $(DESTDIR)$(UDEV_RULES_DIR)
	$(INSTALL_DATA) xpp.rules $(DESTDIR)$(UDEV_RULES_DIR)/

libhexfile.a: hexfile.o
	$(AR) cru $@ $^
	$(RANLIB) $@

fpga_load: fpga_load.o libhexfile.a
	$(CC) -L. -o $@ $@.o $(EXTRA_LIBS) -lhexfile -lusb

fpga_load.o: CFLAGS+=-D_GNU_SOURCE	# We use memrchr()

hexfile.o: hexfile.c hexfile.h
	$(CC) $(CFLAGS) $(PEDANTIC) -c $<

test_parse.o: test_parse.c hexfile.h
	$(CC) $(CFLAGS) $(PEDANTIC) -c $<

test_parse: test_parse.o libhexfile.a
	$(CC) -L. -o $@ $@.o $(EXTRA_LIBS) -lhexfile -lusb

print_modes: print_modes.c wctdm_fxomodes.h
	$(HOSTCC) -o $@ $(CFLAGS) $<

wctdm_fxomodes.h: $(WCTDM)
	perl -n -e 'print if (/^static struct fxo_mode {$$/ .. /};$$/)' $(WCTDM) >$@

init_fxo_modes: print_modes
	./$< >$@

clean:
	$(RM) *.o $(TARGETS)