Makefile: added check for usb.ids
[oweals/hwdata.git] / Makefile
1 NAME=hwdata
2 VERSION=$(shell awk '/Version:/ { print $$2 }' hwdata.spec)
3 RELEASE=$(shell rpm -q --define 'dist %{nil}' --specfile --qf "%{release}\n" hwdata.spec | head -n 1)
4 ifeq ($(shell git rev-parse --abbrev-ref HEAD | sed -n 's/^\([^0-9-]\+\).*/\L\1/p'), rhel)
5     # add revision to tag name for rhel branches
6     TAGNAME := $(NAME)-$(VERSION)-$(RELEASE)
7 else
8     TAGNAME := $(NAME)-$(VERSION)
9 endif
10 SOURCEDIR := $(shell pwd)
11 ARCHIVE := $(TAGNAME).tar.bz2
12 HWDBNUMINCR := 2
13
14 CVSROOT = $(shell cat CVS/Root 2>/dev/null || :)
15
16 CVSTAG = $(NAME)-r$(subst .,-,$(VERSION))
17
18 FILES := pci.ids usb.ids oui.txt iab.txt pnp.ids
19 HWDBGENERATED := 20-OUI.hwdb 20-pci-classes.hwdb 20-pci-vendor-model.hwdb \
20     20-usb-classes.hwdb 20-usb-vendor-model.hwdb
21 HWDBUPSTREAM := 20-bluetooth-vendor-product.hwdb 60-keyboard.hwdb # 20-acpi-vendor.hwdb
22 HWDBFILES := $(HWDBGENERATED) $(HWDBUPSTREAM)
23
24 .PHONY: all install tag force-tag check commit create-archive archive srpm-x \
25     clean clog new-pci-ids new-usb-ids new-oui new-iab new-pnp-ids new-hwdb-files pnp.ids
26
27 include Makefile.inc
28
29 all:
30
31 Makefile.inc: configure
32         ./configure
33         @echo "$@ generated. Run the make again."
34         @exit 1
35
36 install: Makefile.inc
37         mkdir -p -m 755 $(DESTDIR)$(datadir)/$(NAME)
38         for foo in $(FILES) ; do \
39                 install -m 644 $$foo $(DESTDIR)$(datadir)/$(NAME) ;\
40         done
41         mkdir -p -m 755 $(DESTDIR)$(libdir)/udev/hwdb.d/
42         perl ./ids-update.pl
43         for foo in $(HWDBFILES) ; do \
44                 num=`echo $$foo | sed 's,^\(.*/\|\)\([0-9]\+\)-[^/]\+,\2,'`; \
45                 destname=`printf "%02d" $$((num + $(HWDBNUMINCR)))`-`basename $$foo | sed "s/^[0-9]\+-//"`; \
46                 install -m 644 $$foo $(DESTDIR)$(libdir)/udev/hwdb.d/$$destname; \
47         done
48         mkdir -p -m 755 $(DESTDIR)$(libdir)/modprobe.d
49         install -m 644 -T blacklist.conf $(DESTDIR)$(libdir)/modprobe.d/dist-blacklist.conf
50
51 commit:
52         git commit -a ||:
53
54 tag:
55         @git tag -s -m "Tag as $(TAGNAME)" $(TAGNAME)
56         @echo "Tagged as $(TAGNAME)"
57
58 force-tag:
59         @git tag -s -f $(TAGNAME)
60         @echo "Tag forced as $(TAGNAME)"
61
62 changelog:
63         @rm -f ChangeLog
64         @(GIT_DIR=.git git log > .changelog.tmp && mv .changelog.tmp ChangeLog || rm -f .changelog.tmp) || (touch ChangeLog; echo 'git directory not found: installing possibly empty changelog.' >&2)
65
66 check:
67         @[ -x /sbin/lspci ] && /sbin/lspci -i pci.ids > /dev/null || { echo "FAILURE: /sbin/lspci -i pci.ids"; exit 1; } && echo "OK: /sbin/lspci -i pci.ids"
68         @./check-pci-ids.py || { echo "FAILURE: ./check-pci-ids.py"; exit 1; } && echo "OK: ./check-pci-ids.py"
69         @if [[ -e /run/docker.sock ]]; then \
70             tmpdir=`mktemp -d`; \
71             echo "Listing usb devices:"; \
72             docker run -t --privileged --rm=true \
73                 -v `pwd`/usb.ids:/usr/share/hwdata/usb.ids:ro \
74                 -v "$$tmpdir:/mnt/out" \
75                 miminar/hwdata-check /bin/bash -c 'lsusb 2>/mnt/out/err.out'; \
76             if [[ `cat $$tmpdir/err.out | wc -l` -gt 0 ]]; then \
77                 echo "ERRORS:"; nl $$tmpdir/err.out; rm -rf $$tmpdir; exit 1; \
78             fi; \
79             rm -rf $$tmpdir; \
80         fi
81         @echo -n "CHECK date of pci.ids: "; grep "Date:" pci.ids | cut -d ' ' -f 5
82         @echo -n "CHECK date of usb.ids: "; grep "Date:" usb.ids | cut -d ' ' -f 6
83
84 create-archive:
85         @rm -rf $(TAGNAME) $(TAGNAME).tar*  2>/dev/null
86         @make changelog
87         @git archive --format=tar --prefix=$(TAGNAME)/ HEAD > $(TAGNAME).tar
88         @mkdir $(TAGNAME)
89         @cp ChangeLog $(TAGNAME)/
90         @tar --append -f $(TAGNAME).tar $(TAGNAME)
91         @bzip2 -f $(TAGNAME).tar
92         @rm -rf $(TAGNAME)
93         @echo ""
94         @echo "The final archive is in $(TAGNAME).tar.bz2"
95
96 archive: check clean commit tag create-archive
97
98 upload:
99         @scp $(TAGNAME).tar.bz2 fedorahosted.org:$(NAME)
100
101 dummy:
102
103 srpm-x: create-archive
104         @echo Creating $(NAME) src.rpm
105         @rpmbuild --nodeps -bs --define "_sourcedir $(SOURCEDIR)" --define "_srcrpmdir $(SOURCEDIR)" $(NAME).spec
106         @echo SRPM is: $(NAME)-$(VERSION)-$(RELEASE).src.rpm
107
108 clean:
109         @rm -f $(NAME)-*.gz $(NAME)-*.src.rpm new-pnp.xlsx pnp.ids.txt
110
111 clog: hwdata.spec
112         @sed -n '/^%changelog/,/^$$/{/^%/d;/^$$/d;s/%%/%/g;p}' $< | tee $@
113
114 download: new-usb-ids new-pci-ids new-oui new-iab new-pnp-ids new-hwdb-files
115
116 new-usb-ids:
117         @echo $@
118         @curl -O http://www.linux-usb.org/usb.ids
119
120 new-pci-ids:
121         @echo $@
122         @curl -O http://pciids.sourceforge.net/pci.ids
123
124 new-oui:
125         @echo $@
126         @curl -O http://standards-oui.ieee.org/oui.txt
127
128 new-iab:
129         @echo $@
130         @curl -O http://standards.ieee.org/develop/regauth/iab/iab.txt
131
132 new-pnp-ids: pnp.ids
133
134 pnp.ids: pnp.ids.txt pnp.ids.patch
135         patch -o $@ <pnp.ids.patch
136
137 pnp.ids.txt: new-pnp.xlsx
138         @unoconv --stdout -f csv $? | \
139             tr ' ' ' ' | \
140             sed -n \
141                 -e 's/^\s*"\s*\(.*\)\s*"/\1/' \
142                 -e 's/\s\{2,\}/ /g' \
143                 -e 's/\s*(used as 2nd pnpid)\s*//' \
144                 -e 's:^\(.*\)\s*,\s*\([a-zA-Z@]\{3\}\)\s*,\s*\([0-9]\+/[0-9]\+/[0-9]\+\):\2\t\1:p' | \
145             sed 's/\s*$$//' | sort -u >$@
146
147 new-pnp.xlsx:
148         @echo $@
149         @curl -O $@ \
150             http://download.microsoft.com/download/7/E/7/7E7662CF-CBEA-470B-A97E-CE7CE0D98DC2/ISA_PNPID_List.xlsx
151
152 new-hwdb-files:
153         @for file in $(HWDBUPSTREAM); do \
154             echo $$file; \
155             curl -O http://cgit.freedesktop.org/systemd/systemd/plain/hwdb/$$; \
156         done