Merge pull request #3 from coreydaley/update_usb_ids_razer
[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}" hwdata.spec)
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 := v$(VERSION)
9 endif
10 SOURCEDIR := $(shell pwd)
11 ARCHIVE := $(TAGNAME).tar.bz2
12
13 CVSROOT = $(shell cat CVS/Root 2>/dev/null || :)
14
15 CVSTAG = $(NAME)-r$(subst .,-,$(VERSION))
16
17 IDFILES = pci.ids usb.ids oui.txt iab.txt pnp.ids
18
19 # usb.ids is not in UTF-8
20 UTF_IDFILES = pci.ids oui.txt iab.txt pnp.ids
21
22 .PHONY: all install tag force-tag check commit create-archive archive srpm-x \
23     clean clog download
24
25 include Makefile.inc
26
27 all:
28
29 Makefile.inc: configure
30         ./configure
31         @echo "$@ generated. Run the make again."
32         @exit 1
33
34 install: Makefile.inc
35         mkdir -p -m 755 $(DESTDIR)$(datadir)/$(NAME)
36         for foo in $(IDFILES) ; do \
37                 install -m 644 $$foo $(DESTDIR)$(datadir)/$(NAME) ;\
38         done
39         mkdir -p -m 755 $(DESTDIR)$(libdir)/modprobe.d
40         install -m 644 -T blacklist.conf $(DESTDIR)$(libdir)/modprobe.d/dist-blacklist.conf
41
42 commit:
43         git commit -vas ||:
44
45 tag:
46         @git tag -s -m "Tag as $(TAGNAME)" $(TAGNAME)
47         @echo "Tagged as $(TAGNAME)"
48
49 force-tag:
50         @git tag -s -f -m "Tag as $(TAGNAME)" $(TAGNAME)
51         @echo "Tag forced as $(TAGNAME)"
52
53 changelog:
54         @rm -f ChangeLog
55         @(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)
56
57 check:
58         @[ -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"
59         @./check-pci-ids.py || { echo "FAILURE: ./check-pci-ids.py"; exit 1; } && echo "OK: ./check-pci-ids.py"
60         @./check-usb-ids.sh
61         @for file in $(UTF_IDFILES); do \
62             text=`LANG=C file $$file`; \
63             expected="$$file: UTF-8 Unicode text"; \
64             if [[ "$$text" != "$$expected" ]]; then \
65                 printf "Expected: %s\n Got instead: %s\n" "$$expected" "$$text" >&2; \
66                 exit 1; \
67             fi; \
68             echo "OK: $$text"; \
69         done
70         @echo -n "CHECK date of pci.ids: "; grep "Date:" pci.ids | cut -d ' ' -f 5
71         @echo -n "CHECK date of usb.ids: "; grep "Date:" usb.ids | cut -d ' ' -f 6
72
73 create-archive:
74         @rm -rf $(TAGNAME) $(TAGNAME).tar*  2>/dev/null
75         @make changelog
76         @git archive --format=tar --prefix=$(TAGNAME)/ HEAD > $(TAGNAME).tar
77         @mkdir $(TAGNAME)
78         @cp ChangeLog $(TAGNAME)/
79         @tar --append -f $(TAGNAME).tar $(TAGNAME)
80         @bzip2 -f $(TAGNAME).tar
81         @rm -rf $(TAGNAME)
82         @echo ""
83         @echo "The final archive is in $(ARCHIVE)"
84
85 archive: check clean commit tag
86
87 upload:
88         @scp $(ARCHIVE) fedorahosted.org:$(NAME)
89
90 srpm-x: create-archive
91         @echo Creating $(NAME) src.rpm
92         @rpmbuild --nodeps -bs --define "_sourcedir $(SOURCEDIR)" --define "_srcrpmdir $(SOURCEDIR)" $(NAME).spec
93         @echo SRPM is: $(NAME)-$(VERSION)-$(RELEASE).src.rpm
94
95 clean:
96         @rm -f $(NAME)-*.gz $(NAME)-*.src.rpm pnp.ids.xlsx \
97             *.downloaded *.utf8 *.orig
98
99 clog: hwdata.spec
100         @sed -n '/^%changelog/,/^$$/{/^%/d;/^$$/d;s/%%/%/g;p}' $< | tee $@
101
102 download: $(IDFILES)
103
104 usb.ids.downloaded:
105         @curl -o $@ http://www.linux-usb.org/usb.ids
106
107 pci.ids.downloaded:
108         @curl -o $@ https://raw.githubusercontent.com/pciutils/pciids/master/pci.ids
109
110 oui.txt.downloaded:
111         @curl -o $@ -O http://standards-oui.ieee.org/oui.txt
112
113 iab.txt.downloaded:
114         @curl -o $@ -O http://standards-oui.ieee.org/iab/iab.txt
115
116 pnp.ids.xlsx:
117         @curl -o $@ \
118             http://download.microsoft.com/download/7/E/7/7E7662CF-CBEA-470B-A97E-CE7CE0D98DC2/ISA_PNPID_List.xlsx
119
120 usb.ids: usb.ids.utf8
121         dos2unix -n $? $@
122
123 pci.ids: pci.ids.utf8
124         dos2unix -n $? $@
125
126 oui.txt: oui.txt.utf8
127         dos2unix -n $? $@
128
129 iab.txt: iab.txt.utf8
130         dos2unix -n $? $@
131
132 pnp.ids.orig: pnp.ids.xlsx
133         @unoconv --stdout -f csv $? | \
134             tr ' ' ' ' | \
135             sed -n \
136                 -e 's/^\s*"\s*\(.*\)\s*"/\1/' \
137                 -e 's/\s\{2,\}/ /g' \
138                 -e 's/\s*(used as 2nd pnpid)\s*//' \
139                 -e 's:^\(.*\)\s*,\s*\([a-zA-Z@]\{3\}\)\s*,\s*\([0-9]\+/[0-9]\+/[0-9]\+\):\2\t\1:p' | \
140             sed 's/\s*$$//' | sort -u >$@
141
142 pnp.ids: pnp.ids.orig pnp.ids.patch
143         patch -o $@ <pnp.ids.patch
144
145 %.utf8: %.downloaded
146         @text=`LANG=C file $?`
147         @encoding=`echo "$$text" | sed -n 's/.*\(iso-8859\S\*\|cp1[12]\d\+\).*/\1/Ip'`
148         @if [[ -n "$$encoding" ]]; then \
149             iconv -f "$$encoding" -t UTF-8 $?; \
150         else \
151             cat $?; \
152         fi | sed 's/\s\+$$//' >$@
153