- Updated pci, usb, vendor ids and hwdb files
[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 := v$(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 sdio.ids
19 HWDBGENERATED := \
20     20-OUI.hwdb \
21     20-pci-classes.hwdb \
22     20-pci-vendor-model.hwdb \
23     20-sdio-classes.hwdb \
24     20-sdio-vendor-model.hwdb \
25     20-usb-classes.hwdb \
26     20-usb-vendor-model.hwdb
27 HWDBUPSTREAM := \
28     20-acpi-vendor.hwdb \
29     20-bluetooth-vendor-product.hwdb \
30     20-net-ifname.hwdb \
31     60-evdev.hwdb \
32     60-keyboard.hwdb \
33     70-mouse.hwdb \
34     70-pointingstick.hwdb
35 HWDBFILES := $(HWDBGENERATED) $(HWDBUPSTREAM)
36
37 .PHONY: all install tag force-tag check commit create-archive archive srpm-x \
38     clean clog \
39     new-pci-ids \
40     new-usb-ids \
41     new-oui \
42     new-iab \
43     new-pnp-ids \
44     new-hwdb-files \
45     new-sdio-ds \
46     pnp.ids
47
48 include Makefile.inc
49
50 all:
51
52 Makefile.inc: configure
53         ./configure
54         @echo "$@ generated. Run the make again."
55         @exit 1
56
57 install: Makefile.inc
58         mkdir -p -m 755 $(DESTDIR)$(datadir)/$(NAME)
59         for foo in $(FILES) ; do \
60                 install -m 644 $$foo $(DESTDIR)$(datadir)/$(NAME) ;\
61         done
62         mkdir -p -m 755 $(DESTDIR)$(libdir)/udev/hwdb.d/
63         perl ./ids-update.pl
64         for foo in $(HWDBFILES) ; do \
65                 num=`echo $$foo | sed 's,^\(.*/\|\)\([0-9]\+\)-[^/]\+,\2,'`; \
66                 destname=`printf "%02d" $$((num + $(HWDBNUMINCR)))`-`basename $$foo | sed "s/^[0-9]\+-//"`; \
67                 install -m 644 $$foo $(DESTDIR)$(libdir)/udev/hwdb.d/$$destname; \
68         done
69         mkdir -p -m 755 $(DESTDIR)$(libdir)/modprobe.d
70         install -m 644 -T blacklist.conf $(DESTDIR)$(libdir)/modprobe.d/dist-blacklist.conf
71
72 commit:
73         git commit -vas ||:
74
75 tag:
76         @git tag -s -m "Tag as $(TAGNAME)" $(TAGNAME)
77         @echo "Tagged as $(TAGNAME)"
78
79 force-tag:
80         @git tag -s -f -m "Tag as $(TAGNAME)" $(TAGNAME)
81         @echo "Tag forced as $(TAGNAME)"
82
83 changelog:
84         @rm -f ChangeLog
85         @(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)
86
87 check:
88         @[ -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"
89         @./check-pci-ids.py || { echo "FAILURE: ./check-pci-ids.py"; exit 1; } && echo "OK: ./check-pci-ids.py"
90         @./check-usb-ids.sh
91         @for file in $(IDFILES); do \
92             text=`LANG=C file $$file`; \
93             expected="$$file: UTF-8 Unicode text"; \
94             if [[ "$$text" != "$$expected" ]]; then \
95                 printf "Expected: %s\n Got instead: %s\n" "$$expected" "$$text" >&2; \
96                 exit 1; \
97             fi; \
98             echo "OK: $$text"; \
99         done
100         @echo -n "CHECK date of pci.ids: "; grep "Date:" pci.ids | cut -d ' ' -f 5
101         @echo -n "CHECK date of usb.ids: "; grep "Date:" usb.ids | cut -d ' ' -f 6
102
103 create-archive:
104         @rm -rf $(TAGNAME) $(TAGNAME).tar*  2>/dev/null
105         @make changelog
106         @git archive --format=tar --prefix=$(TAGNAME)/ HEAD > $(TAGNAME).tar
107         @mkdir $(TAGNAME)
108         @cp ChangeLog $(TAGNAME)/
109         @tar --append -f $(TAGNAME).tar $(TAGNAME)
110         @bzip2 -f $(TAGNAME).tar
111         @rm -rf $(TAGNAME)
112         @echo ""
113         @echo "The final archive is in $(TAGNAME).tar.bz2"
114
115 archive: check clean commit tag
116
117 upload:
118         @scp $(TAGNAME).tar.bz2 fedorahosted.org:$(NAME)
119
120 dummy:
121
122 srpm-x: create-archive
123         @echo Creating $(NAME) src.rpm
124         @rpmbuild --nodeps -bs --define "_sourcedir $(SOURCEDIR)" --define "_srcrpmdir $(SOURCEDIR)" $(NAME).spec
125         @echo SRPM is: $(NAME)-$(VERSION)-$(RELEASE).src.rpm
126
127 clean:
128         @rm -f $(NAME)-*.gz $(NAME)-*.src.rpm pnp.ids.xlsx \
129             *.downloaded *.utf8 *.orig
130
131 clog: hwdata.spec
132         @sed -n '/^%changelog/,/^$$/{/^%/d;/^$$/d;s/%%/%/g;p}' $< | tee $@
133
134 download: $(FILES) new-hwdb-files
135
136 usb.ids.downloaded:
137         @curl -o $@ http://www.linux-usb.org/usb.ids
138
139 pci.ids.downloaded:
140         @curl -o $@ https://raw.githubusercontent.com/pciutils/pciids/master/pci.ids
141
142 oui.txt.downloaded:
143         @curl -o $@ -O http://standards-oui.ieee.org/oui.txt
144
145 iab.txt.downloaded:
146         @curl -o $@ -O http://standards-oui.ieee.org/iab/iab.txt
147
148 pnp.ids.xlsx:
149         @curl -o $@ \
150             http://download.microsoft.com/download/7/E/7/7E7662CF-CBEA-470B-A97E-CE7CE0D98DC2/ISA_PNPID_List.xlsx
151
152 sdio.ids.downloaded:
153         @curl -o $@ https://raw.githubusercontent.com/systemd/systemd/master/hwdb.d/sdio.ids
154
155 usb.ids: usb.ids.utf8
156         dos2unix -n $? $@
157
158 pci.ids: pci.ids.utf8
159         dos2unix -n $? $@
160
161 oui.txt: oui.txt.utf8
162         dos2unix -n $? $@
163
164 iab.txt: iab.txt.utf8
165         dos2unix -n $? $@
166
167 sdio.ids: sdio.ids.utf8
168         dos2unix -n $? $@
169
170 pnp.ids.orig: pnp.ids.xlsx
171         @unoconv --stdout -f csv $? | \
172             tr ' ' ' ' | \
173             sed -n \
174                 -e 's/^\s*"\s*\(.*\)\s*"/\1/' \
175                 -e 's/\s\{2,\}/ /g' \
176                 -e 's/\s*(used as 2nd pnpid)\s*//' \
177                 -e 's:^\(.*\)\s*,\s*\([a-zA-Z@]\{3\}\)\s*,\s*\([0-9]\+/[0-9]\+/[0-9]\+\):\2\t\1:p' | \
178             sed 's/\s*$$//' | sort -u >$@
179
180 pnp.ids: pnp.ids.orig pnp.ids.patch
181         patch -o $@ <pnp.ids.patch
182
183 %.utf8: %.downloaded
184         @text=`LANG=C file $?`
185         @encoding=`echo "$$text" | sed -n 's/.*\(iso-8859\S\*\|cp1[12]\d\+\).*/\1/Ip'`
186         @if [[ -n "$$encoding" ]]; then \
187             iconv -f "$$encoding" -t UTF-8 $?; \
188         else \
189             cat $?; \
190         fi | sed 's/\s\+$$//' >$@
191
192 new-hwdb-files:
193         @for file in $(HWDBUPSTREAM); do \
194             echo $$file; \
195             curl -O https://raw.githubusercontent.com/systemd/systemd/master/hwdb.d/$$file; \
196         done