Separate db.txt authorship from this package, also rely on
[platform/upstream/crda.git] / Makefile
1 ifeq ($(origin $(KLIB)), undefined)
2 KLIB := /lib/modules/$(shell uname -r)
3 endif
4 KLIB_BUILD ?= $(KLIB)/build
5
6 ifneq ($(COMPAT_TREE),)
7 CFLAGS += -I$(COMPAT_TREE)/include/
8 endif
9
10 CRDA_LIB := "/usr/lib/crda/"
11
12 # Used locally to retrieve all pubkeys during build time
13 PUBKEY_DIR=pubkeys
14
15 KORG="http://www.kernel.org/pub/linux/kernel/people"
16
17 #LINVILLE_REGDB=$(KORG)/linville/regdb/latest/regulatory.bin
18 #LINVILLE_RSAPUB=$(KORG)/linville/regdb/linville.key.pub.pem
19
20 ATHEROS_REGDB_ASCII=$(KORG)/mcgrof/regdb/latest/db.txt
21 ATHEROS_REGDB_BIN=$(KORG)/mcgrof/regdb/latest/regulatory.bin
22
23 ATHEROS_RSAPUB=$(KORG)/mcgrof/regdb/atheros.key.pub.pem
24
25 # We can remove the atheros bin/ascii db once Linville has one
26 REGDB_ASCII=$(ATHEROS_REGDB_ASCII)
27 REGDB_BIN=$(ATHEROS_REGDB_BIN)
28
29 CFLAGS += -Wall -g -I$(KLIB_BUILD)/include
30 #CFLAGS += -DUSE_OPENSSL `pkg-config --cflags openssl`
31 #LDFLAGS += `pkg-config --libs openssl`
32 CFLAGS += -DUSE_GCRYPT
33 LDFLAGS += -lgcrypt
34
35 MKDIR ?= mkdir -p
36 INSTALL ?= install
37
38 ifeq ($(V),1)
39 Q=
40 NQ=@true
41 else
42 Q=@
43 NQ=@echo
44 endif
45
46 all: regulatory.bin crda intersect
47         $(Q)$(MAKE) --no-print-directory -f Makefile verify
48
49 # Add all pubkeys here
50 $(PUBKEY_DIR)/$(wildcard *.pem):
51         $(Q)wget -q -P $(PUBKEY_DIR)/ $(ATHEROS_RSAPUB)
52
53 regulatory.bin:
54         $(Q)wget -q $(REGDB_BIN)
55
56 # Authors of regulatory.bin first need a private key, which can
57 # be generated with something like this:
58 # openssl genrsa -out your.key.priv.pem 2048
59 #
60 # You'll then need to generate the public key and publish it. You
61 # can generate it as follows:
62 # openssl rsa -in your.key.priv.pem -out your.key.pub.pem -pubout -outform PEM
63 #
64 # Then with this key you can generate regulatory.bin files like this:
65 # ./utils/db2bin.py regulatory.bin db.txt your.key.priv.pem
66 #
67 # You can find the source of the regulatory.bin used at $(REGDB_ASCII)
68
69 keys-%.c: utils/key2pub.py $(PUBKEY_DIR)/$(wildcard *.pem)
70         $(NQ) '  GEN ' $@
71         $(Q)./utils/key2pub.py --$* $(PUBKEY_DIR)/*.pem > $@
72
73 %.o: %.c regdb.h
74         $(NQ) '  CC  ' $@
75         $(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
76
77 crda: keys-ssl.c keys-gcrypt.c reglib.o crda.o
78         $(NQ) '  LD  ' $@
79         $(Q)$(CC) $(CFLAGS) $(LDFLAGS) `pkg-config --libs libnl-1` -o $@ reglib.o crda.o
80
81
82 dump: keys-ssl.c keys-gcrypt.c reglib.o dump.o
83         $(NQ) '  LD  ' $@
84         $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ reglib.o dump.o
85
86 intersect: regulatory.bin keys-ssl.c keys-gcrypt.c reglib.o intersect.o
87         $(NQ) '  LD  ' $@
88         $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ reglib.o intersect.o
89
90 verify: regulatory.bin dump
91         $(NQ) '  CHK  regulatory.bin'
92         $(Q)./dump regulatory.bin >/dev/null
93
94 install: regulatory.bin crda
95         $(NQ) '  INSTALL  crda'
96         $(Q)$(MKDIR) $(DESTDIR)/sbin
97         $(Q)$(INSTALL) -m 755 -t $(DESTDIR)/sbin/ crda
98         $(NQ) '  INSTALL  regulatory.bin'
99         $(Q)$(MKDIR) $(DESTDIR)$(CRDA_LIB)
100         $(Q)$(INSTALL) -m 644 -t $(DESTDIR)$(CRDA_LIB) regulatory.bin
101         $(NQ) '  INSTALL  regulatory.rules'
102         $(Q)$(MKDIR) $(DESTDIR)/etc/udev/rules.d
103         $(Q)$(INSTALL) -m 644 -t $(DESTDIR)/etc/udev/rules.d/ regulatory.rules
104
105 clean:
106         $(Q)rm -f db.txt regulatory.bin crda dump intersect *.o *~ *.pyc keys-*.c
107         $(Q)rm -rf $(PUBKEY_DIR)
108         $(Q)if test -f key.priv.pem && diff -qNs test-key key.priv.pem >/dev/null ; then \
109                 rm -f key.priv.pem;\
110         fi