summaryrefslogtreecommitdiff
path: root/build.mk
blob: 45b5fea03e3ec10fce20e88320666dd30d735ff2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Rules to fetch, build and install external source packages.
#
# TODO:
# - rules for pre-req dependencies
# - rules to run tests before installing
# - build and run in chroot
# - detect inflate command
#
# Done:
# - rules to apply patches
# 

arc ?= $(notdir $(url)) 
configure_cmd ?= ./configure
build_cmd ?= make -j8
install_cmd ?= sudo make install
uninstall_cmd ?= sudo make uninstall

ifeq ($(suffix $(arc)), .gz)
	inflate_cmd ?= gzip -cd
else ifeq ($(suffix $(arc)), .xz)
	inflate_cmd ?= xz -cd
else ifeq ($(suffix $(arc)), .bz2)
	inflate_cmd ?= bzip2 -cd
endif

ifdef git_url
	fetch_cmd = git clone --depth=1 $(git_url)
	extract_cmd = :
	dir ?= $(notdir $(git_url))
else
	fetch_cmd = curl -L $(url) -o $(arc)
	extract_cmd = $(inflate_cmd) < $(arc) | tar xf -
	dir ?= $(basename $(basename $(arc)))
endif

clean:
	rm -rf .install .build .patched .configure .extract .fetch $(dir)

debug:
	@echo arc = $(arc)
	@echo dir = $(dir)

genpatch:
	find $(dir) -name *.orig | while read -r f; do diff -u $$f $${f%.orig}; done > $(dir).patch || true

uninstall: .install
	cd $(dir) && $(uninstall_cmd)
	rm .install

install: .install
build: .build
configure: .configure
patch: .patched
extract: .extract
fetch: .fetch

.install: .build
	cd $(dir) && $(install_cmd)
	@touch $@

.build: .configure
	cd $(dir) && $(build_cmd)
	@touch $@

.configure: .patched
	cd $(dir) && $(configure_cmd) $(configure_flags)
	@touch $@

.patched: .extract
	for f in $$(ls *.patch); do (cd $(dir) && patch -p1 < ../$$f) || break; done
	@touch $@

.extract: .fetch
	$(extract_cmd)
	@touch $@

.fetch:
	$(fetch_cmd)
	@touch $@