| 1 |
# Install prefix |
| 2 |
PREFIX ?= /usr |
| 3 |
CRDA_PATH ?= $(PREFIX)/lib/crda |
| 4 |
CRDA_KEY_PATH ?= $(CRDA_PATH)/pubkeys |
| 5 |
FIRMWARE_PATH ?= /lib/firmware |
| 6 |
|
| 7 |
MANDIR ?= $(PREFIX)/share/man/ |
| 8 |
|
| 9 |
SHA1SUM ?= /usr/bin/sha1sum |
| 10 |
LSB_RELEASE ?= /usr/bin/lsb_release |
| 11 |
WHOAMI ?= /usr/bin/whoami |
| 12 |
|
| 13 |
# Distro name: Ubuntu, Debian, Fedora, if not present you get |
| 14 |
# "custom-distro", if your distribution does not have the LSB stuff, |
| 15 |
# then set this variable when calling make if you don't want "custom-distro" |
| 16 |
LSB_ID ?= $(shell if [ -f $(LSB_RELEASE) ]; then \ |
| 17 |
$(LSB_RELEASE) -i -s; \ |
| 18 |
else \ |
| 19 |
echo custom-distro; \ |
| 20 |
fi) |
| 21 |
|
| 22 |
DISTRO_PRIVKEY ?= ~/.wireless-regdb-$(LSB_ID).key.priv.pem |
| 23 |
DISTRO_PUBKEY ?= ~/.wireless-regdb-$(LSB_ID).key.priv.pem |
| 24 |
|
| 25 |
REGDB_AUTHOR ?= $(shell if [ -f $(DISTRO_PRIVKEY) ]; then \ |
| 26 |
echo $(LSB_ID) ; \ |
| 27 |
elif [ -f $(WHOAMI) ]; then \ |
| 28 |
$(WHOAMI); \ |
| 29 |
else \ |
| 30 |
echo custom-user; \ |
| 31 |
fi) |
| 32 |
|
| •33 |
REGDB_PRIVKEY ?= $(HOME)/.wireless-regdb-$(REGDB_AUTHOR).key.priv.pem |
| 34 |
REGDB_PUBKEY ?= $(REGDB_AUTHOR).key.pub.pem |
| 35 |
REGDB_PUBCERT ?= $(REGDB_AUTHOR).x509.pem |
| 36 |
|
| 37 |
REGDB_UPSTREAM_PUBKEY ?= wens.key.pub.pem |
| 38 |
|
| 39 |
REGDB_CHANGED = $(shell $(SHA1SUM) -c --status sha1sum.txt >/dev/null 2>&1; \ |
| 40 |
if [ $$? -ne 0 ]; then \ |
| 41 |
echo maintainer-clean $(REGDB_PUBKEY) $(REGDB_PUBCERT); \ |
| 42 |
fi) |
| 43 |
|
| 44 |
.PHONY: all clean mrproper install maintainer-clean install-distro-key |
| 45 |
|
| 46 |
all: $(REGDB_CHANGED) regulatory.bin sha1sum.txt regulatory.db.p7s |
| 47 |
|
| 48 |
clean: |
| 49 |
@rm -f *.pyc *.gz |
| 50 |
|
| 51 |
maintainer-clean: clean |
| 52 |
@rm -f regulatory.bin regulatory.db regulatory.db.p7s |
| 53 |
|
| 54 |
mrproper: clean maintainer-clean |
| 55 |
@echo Removed public key, regulatory.bin, regulatory.db* and compressed man pages |
| 56 |
@rm -f $(REGDB_PUBKEY) $(REGDB_PUBCERT) .custom |
| 57 |
|
| 58 |
regulatory.bin: db.txt $(REGDB_PRIVKEY) $(REGDB_PUBKEY) |
| 59 |
@echo Generating $@ digitally signed by $(REGDB_AUTHOR)... |
| 60 |
./db2bin.py regulatory.bin db.txt $(REGDB_PRIVKEY) |
| 61 |
|
| 62 |
regulatory.db: db.txt db2fw.py |
| 63 |
@echo "Generating $@" |
| 64 |
./db2fw.py regulatory.db db.txt |
| 65 |
|
| 66 |
regulatory.db.p7s: regulatory.db $(REGDB_PRIVKEY) $(REGDB_PUBCERT) |
| 67 |
@echo "Signing regulatory.db (by $(REGDB_AUTHOR))..." |
| 68 |
@openssl smime -sign \ |
| 69 |
-signer $(REGDB_PUBCERT) \ |
| 70 |
-inkey $(REGDB_PRIVKEY) \ |
| 71 |
-in $< -nosmimecap -binary \ |
| 72 |
-noattr \ |
| 73 |
-outform DER -out $@ |
| 74 |
|
| 75 |
sha1sum.txt: db.txt |
| 76 |
sha1sum $< > $@ |
| 77 |
|
| 78 |
$(REGDB_PUBKEY): $(REGDB_PRIVKEY) |
| 79 |
@echo "Generating public key for $(REGDB_AUTHOR)..." |
| 80 |
openssl rsa -in $(REGDB_PRIVKEY) -out $(REGDB_PUBKEY) -pubout -outform PEM |
| 81 |
|
| 82 |
$(REGDB_PUBCERT): $(REGDB_PRIVKEY) |
| 83 |
@echo "Generating certificate for $(REGDB_AUTHOR)..." |
| 84 |
./gen-pubcert.sh $(REGDB_PRIVKEY) $(REGDB_PUBCERT) $(REGDB_AUTHOR) |
| 85 |
@echo $(REGDB_PUBKEY) > .custom |
| 86 |
|
| 87 |
|
| •88 |
$(REGDB_PRIVKEY): |
| 89 |
ifeq ($(MAKECMDGOALS),$(REGDB_PRIVKEY)) |
| 90 |
@echo "Generating private key for $(REGDB_AUTHOR)..." |
| •91 |
openssl genrsa -out $(REGDB_PRIVKEY) 2048 |
| 92 |
else |
| 93 |
@echo "No private key found. To generate a private key, run:" |
| 94 |
@echo " make ~/.wireless-regdb-<author-id>.key.priv.pem" |
| 95 |
@echo "Your author-id is currently \"$(REGDB_AUTHOR)\"; set REGDB_AUTHOR to override this." |
| 96 |
@exit 1 |
| 97 |
endif |
| 98 |
|
| 99 |
ifneq ($(shell test -e $(DISTRO_PRIVKEY) && echo yes),yes) |
| 100 |
$(DISTRO_PRIVKEY): |
| 101 |
@echo "Generating private key for $(LSB_ID) packager..." |
| 102 |
openssl genrsa -out $(DISTRO_PRIVKEY) 2048 |
| 103 |
endif |
| 104 |
|
| 105 |
install-distro-key: maintainer-clean $(DISTRO_PRIVKEY) |
| 106 |
|
| 107 |
%.gz: % |
| 108 |
gzip < $< > $@ |
| 109 |
|
| 110 |
# Users should just do: |
| 111 |
# sudo make install |
| 112 |
# |
| 113 |
# Developers should do: |
| 114 |
# make maintainer-clean |
| 115 |
# make |
| 116 |
# sudo make install |
| 117 |
# |
| 118 |
# Distributions packagers should do only once: |
| 119 |
# make install-distro-key |
| 120 |
# This will create a private key for you and install it into |
| 121 |
# ~/.wireless-regdb-$(LSB_ID).key.priv.pem |
| 122 |
# To make new releaes just do: |
| 123 |
# make maintainer-clean |
| 124 |
# make |
| 125 |
# sudo make install |
| 126 |
install: regulatory.bin.5.gz regulatory.db.5.gz |
| 127 |
install -m 755 -d $(DESTDIR)/$(CRDA_PATH) |
| 128 |
install -m 755 -d $(DESTDIR)/$(CRDA_KEY_PATH) |
| 129 |
install -m 755 -d $(DESTDIR)/$(FIRMWARE_PATH) |
| 130 |
if [ -f .custom ]; then \ |
| 131 |
install -m 644 -t $(DESTDIR)/$(CRDA_KEY_PATH)/ $(shell cat .custom); \ |
| 132 |
fi |
| 133 |
install -m 644 -t $(DESTDIR)/$(CRDA_KEY_PATH)/ $(REGDB_UPSTREAM_PUBKEY) |
| 134 |
install -m 644 -t $(DESTDIR)/$(CRDA_PATH)/ regulatory.bin |
| 135 |
install -m 644 -t $(DESTDIR)/$(FIRMWARE_PATH) regulatory.db regulatory.db.p7s |
| 136 |
install -m 755 -d $(DESTDIR)/$(MANDIR)/man5/ |
| 137 |
install -m 644 -t $(DESTDIR)/$(MANDIR)/man5/ regulatory.bin.5.gz regulatory.db.5.gz |