Allow parallel fetch
[oweals/hwids.git] / Makefile
1
2 ifeq "$(V)" "0"
3   STATUS = git status -s
4   Q=@
5 else
6   STATUS = git status
7   Q=
8 endif
9
10 PKG_CONFIG ?= pkg-config
11 PYTHON ?= python3
12 GZIP ?= yes
13 NET ?= yes
14 PCI ?= yes
15 UDEV ?= no
16 USB ?= yes
17
18 COMPRESS_FILES-yes =
19 COMPRESS_FILES-$(PCI) += pci.ids.gz
20 COMPRESS_FILES-$(USB) += usb.ids.gz
21
22 DATA_FILES-yes =
23 DATA_FILES-$(GZIP) += $(COMPRESS_FILES-yes)
24 DATA_FILES-$(NET) += oui.txt iab.txt
25 DATA_FILES-$(PCI) += pci.ids
26 DATA_FILES-$(USB) += usb.ids
27
28 ALL_TARGETS-yes =
29 ALL_TARGETS-$(GZIP) += $(COMPRESS_FILES-yes)
30
31 INSTALL_TARGETS-yes = install-base
32 INSTALL_TARGETS-$(UDEV) += install-hwdb
33
34 SYSTEMD_SOURCE = https://github.com/systemd/systemd/raw/master/hwdb.d
35 UDEV_FILES = 20-acpi-vendor.hwdb 20-bluetooth-vendor-product.hwdb
36 UDEV_FILES += 20-net-ifname.hwdb 60-evdev.hwdb 60-keyboard.hwdb 60-sensor.hwdb
37 UDEV_FILES += 70-joystick.hwdb 70-mouse.hwdb 70-pointingstick.hwdb 70-touchpad.hwdb
38
39 UDEV_PATHS = $(addprefix udev/,$(UDEV_FILES))
40
41 all: $(ALL_TARGETS-yes)
42
43 .PHONY: all install install-base install-hwdb fetch tag udev-hwdb compress
44 .PHONY: pci.ids usb.ids oui.txt ma-medium.txt ma-small.txt iab.txt sdio.ids ids_parser.py
45 .PHONY: $(UDEV_PATHS)
46
47 install: $(INSTALL_TARGETS-yes)
48
49 curl-get = $(Q)curl -s -L -z $@ -o $@ -R $1
50
51 pci.ids:
52         $(call curl-get,http://pci-ids.ucw.cz/v2.2/pci.ids)
53
54 usb.ids:
55         $(call curl-get,http://www.linux-usb.org/usb.ids)
56
57 # OUI/IAB: https://regauth.standards.ieee.org/standards-ra-web/pub/view.html#registries
58 oui.txt:
59         $(call curl-get,http://standards-oui.ieee.org/oui/oui.txt)
60
61 ma-medium.txt:
62         $(call curl-get,http://standards-oui.ieee.org/oui28/mam.txt)
63
64 ma-small.txt:
65         $(call curl-get,http://standards-oui.ieee.org/oui36/oui36.txt)
66
67 iab.txt:
68         $(call curl-get,http://standards-oui.ieee.org/iab/iab.txt)
69
70 sdio.ids:
71         $(call curl-get,$(SYSTEMD_SOURCE)/sdio.ids)
72
73 ids_parser.py:
74         $(call curl-get,$(SYSTEMD_SOURCE)/ids_parser.py)
75
76 $(UDEV_PATHS):
77         $(call curl-get,$(SYSTEMD_SOURCE)/$(notdir $@))
78
79 fetch: pci.ids usb.ids oui.txt ma-medium.txt ma-small.txt iab.txt sdio.ids ids_parser.py $(UDEV_PATHS)
80         $(Q)$(STATUS)
81
82 PV ?= $(shell ( awk '$$2 == "Date:" { print $$3; nextfile }' pci.ids usb.ids; git log --format=format:%ci -1 -- oui.txt $(addprefix udev/,$(UDEV_FILES)) ids_parser.py | cut -d ' ' -f1; ) | sort | tail -n 1 | tr -d -)
83 P = hwids-$(PV)
84
85 tag:
86         git tag $(P)
87
88 udev-hwdb:
89         $(PYTHON) ids_parser.py && mv *.hwdb udev/
90
91 compress: pci.ids.gz usb.ids.gz
92
93 %.gz: %
94         gzip -c $< > $@
95
96 MISCDIR=/usr/share/misc
97 HWDBDIR=$(shell $(PKG_CONFIG) --variable=udevdir udev)/hwdb.d
98 DOCDIR=/usr/share/doc/hwids
99
100 install-base: $(DATA_FILES-yes)
101         mkdir -p $(DESTDIR)$(DOCDIR)
102         install -p -m 644 README.md $(DESTDIR)$(DOCDIR)
103 ifneq ($(strip $(DATA_FILES-yes)),)
104         mkdir -p $(DESTDIR)$(MISCDIR)
105         install -p -m 644 $(DATA_FILES-yes) $(DESTDIR)$(MISCDIR)
106 endif
107
108 install-hwdb:
109         mkdir -p $(DESTDIR)$(HWDBDIR)
110         install -p -m 644 udev/*.hwdb $(DESTDIR)$(HWDBDIR)
111         udevadm hwdb --root $(DESTDIR) --update