ebe3a3439fb4d26c67d8ef497646be92cdb6ead5
[oweals/hwdata.git] / Makefile
1 NAME=$(shell awk '/Name:/ { print $$2 }' hwdata.spec)
2 VERSION=$(shell awk '/Version:/ { print $$2 }' hwdata.spec)
3 RELEASE=$(shell rpm -q --define 'dist .el6' --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 := $(NAME)-$(VERSION)-$(RELEASE)
7 else
8     TAGNAME := $(NAME)-$(VERSION)
9 endif
10 SOURCEDIR := $(shell pwd)
11 ARCHIVE := $(TAGNAME).tar.bz2
12
13 prefix=$(DESTDIR)/usr
14 sysconfdir=$(DESTDIR)/etc
15 bindir=$(prefix)/bin
16 sbindir=$(prefix)/sbin
17 datadir=$(prefix)/share
18 mandir=$(datadir)/man
19 includedir=$(prefix)/include
20 libdir=$(prefix)/lib
21
22 CC=gcc
23 CFLAGS=$(RPM_OPT_FLAGS) -g
24
25 CVSROOT = $(shell cat CVS/Root 2>/dev/null || :)
26
27 CVSTAG = $(NAME)-r$(subst .,-,$(VERSION))
28
29 FILES = MonitorsDB pci.ids upgradelist usb.ids videodrivers oui.txt pnp.ids
30
31 .PHONY: all install tag force-tag check commit create-archive archive srpm-x clean clog new-pci-ids new-usb-ids
32
33 all: 
34
35 install:
36         mkdir -p -m 755 $(datadir)/$(NAME)
37         for foo in $(FILES) ; do \
38                 install -m 644 $$foo $(datadir)/$(NAME) ;\
39         done
40         mkdir -p -m 755 $(datadir)/$(NAME)/videoaliases
41         mkdir -p -m 755 $(sysconfdir)/modprobe.d
42         install -m 644 blacklist.conf $(sysconfdir)/modprobe.d
43
44 commit:
45         git commit -a ||:
46
47 tag:
48         @git tag -s -m "Tag as $(TAGNAME)" $(TAGNAME)
49         @echo "Tagged as $(TAGNAME)"
50
51 force-tag:
52         @git tag -s -f $(TAGNAME)
53         @echo "Tag forced as $(TAGNAME)"
54
55 changelog:
56         @rm -f ChangeLog
57         @(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)
58
59 check:
60         @[ -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"
61         @./check-pci-ids.py || { echo "FAILURE: ./check-pci-ids.py"; exit 1; } && echo "OK: ./check-pci-ids.py"
62         @if [[ -e /run/docker.sock ]]; then \
63             tmpdir=`mktemp -d`; \
64             echo "Listing usb devices:"; \
65             docker run -t --privileged --rm=true \
66                 -v `pwd`/usb.ids:/usr/share/hwdata/usb.ids:r \
67                 -v "$$tmpdir:/mnt/out" \
68                 miminar/hwdata-check /bin/bash -c 'lsusb 2>/mnt/out/err.out'; \
69             if [[ `cat $$tmpdir/err.out | wc -l` -gt 0 ]]; then \
70                 echo "ERRORS:"; nl $$tmpdir/err.out; rm -rf $$tmpdir; exit 1; \
71             fi; \
72             rm -rf $$tmpdir; \
73         fi
74         @echo -n "CHECK date of pci.ids: "; grep "Date:" pci.ids | cut -d ' ' -f 5
75         @echo -n "CHECK date of usb.ids: "; grep "Date:" usb.ids | cut -d ' ' -f 6
76         @: videodrivers is tab-separated
77         @[ `grep -vc '  ' videodrivers` -eq 0 ] || { echo "FAILURE: videodrivers not TAB separated"; exit 1; } && echo "OK: videodrivers"
78
79 create-archive:
80         @rm -rf $(TAGNAME) $(TAGNAME).tar*  2>/dev/null
81         @make changelog
82         @git archive --format=tar --prefix=$(TAGNAME)/ HEAD > $(TAGNAME).tar
83         @mkdir $(TAGNAME)
84         @cp ChangeLog $(TAGNAME)/
85         @tar --append -f $(TAGNAME).tar $(TAGNAME)
86         @bzip2 -f $(TAGNAME).tar
87         @rm -rf $(TAGNAME)
88         @echo ""
89         @echo "The final archive is in $(ARCHIVE)"
90
91 archive: check clean commit tag create-archive
92
93 upload:
94         @scp $(ARCHIVE) fedorahosted.org:$(NAME)
95
96 dummy:
97
98 srpm-x: create-archive
99         @echo Creating $(NAME) src.rpm
100         @rpmbuild --nodeps -bs --define "_sourcedir $(SOURCEDIR)" --define "_srcrpmdir $(SOURCEDIR)" $(NAME).spec
101         @echo SRPM is: $(NAME)-$(VERSION)-$(RELEASE).src.rpm
102
103 clean:
104         @rm -f $(NAME)-*.bz2 $(NAME)-*.src.rpm
105
106 clog: hwdata.spec
107         @sed -n '/^%changelog/,/^$$/{/^%/d;/^$$/d;s/%%/%/g;p}' $< | tee $@
108
109 download: new-usb-ids new-pci-ids new-oui.txt
110
111 new-usb-ids:
112         @curl -O http://www.linux-usb.org/usb.ids
113
114 new-pci-ids:
115         @curl -O http://pciids.sourceforge.net/pci.ids
116
117 new-oui.txt:
118         @curl -O http://standards-oui.ieee.org/oui.txt