summaryrefslogtreecommitdiff
path: root/Makefile
blob: 98e5a7a0c3206477e3b46b50f121f27d3c0fa8c7 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
top := $(shell pwd)

all: package

# configuration ################################################################

packages := $(filter-out _%,$(shell sed "s/[\# ].*//" conf/sources.mk))
include conf/sources.mk
include conf/dependencies.mk
export MAVEN_LOCAL_REPO := $(shell cat conf/maven.local.repo.txt)
export JAR_DIR := $(shell cat conf/jardir.txt)

# download #####################################################################

download: PHONY $(foreach package,$(packages),build/download/$(shell utils/spec2file '$($(package))'))

build/download/git/%: .tokens/network
	if [ -d '$@' ]; then \
		cd '$@' && git fetch --all -p; \
	else \
		mkdir -p '$(@D)' && git clone --mirror '$(shell utils/file2url 'git/$*')' '$@'; \
	fi
	touch '$@'
build/download/svn/%: .tokens/network
	if ! [ -d '$(shell utils/file2base 'svn/$*')' ]; then \
		rm -rf '$@' && \
		mkdir -p build/download/svn && \
		svn checkout --depth=empty \
			               '$(shell utils/file2url  'svn/$*')' \
			build/download/'$(shell utils/file2base 'svn/$*')' && \
		cd build/download/'$(shell utils/file2base 'svn/$*')'; \
	else \
		cd build/download/'$(shell utils/file2base 'svn/$*')' && \
		svn update; \
	fi && \
	svn update --parents '$(shell utils/file2extra 'svn/$*')'
	touch '$@'
build/download/tar/%: .tokens/network
	mkdir -p '$(@D)'
	wget -c -O '$@' '$(shell utils/file2url 'tar/$*')'
	touch '$@'

# extract ######################################################################

extract: PHONY $(foreach package,$(packages),build/extract/$(shell utils/spec2file '$($(package))'))

# This is a little gross because to get the dependencies right for
# `git` and `tar`, we need to do a bit more complex processing of
# `%`/`$*`.  We could do that with `.SECONDEXPANSION:`, but that is a
# whole can of worms.  Instead, we use a foreach loop to loop over all
# possibilities.  `svn` doesn't have this issue, because, unlike `git`
# and `tar`, it's `extra` component is present in `build/download`.

build/extract/git/%: # magic for loop
	gitref='$(shell utils/file2extra 'git/$*'|cut -d/ -f1)' && \
	gitdir=build/extract/'$(shell utils/file2base 'git/$*')'/$${gitref} && \
	rm -rf "$$gitdir" && \
	{ \
		mkdir -p "$$(dirname "$$gitdir")" && \
		git clone build/download/'$(shell utils/file2base 'git/$*')' "$$gitdir" && \
		( cd "$$gitdir" && git checkout "$$gitref" ); \
	} || rm -rf "$$gitdir"
	touch '$@'

build/extract/svn/%: build/download/svn/%
	rm -rf '$@'
	mkdir -p '$(@D)'
	cp -a '$<' '$@'

build/extract/tar/%: # magic for loop
	rm -rf '$@'
	mkdir -p '$@'
	cd '$@' && bsdtar --strip-components 1 -xf '$(top)/$<'
	cd '$@' && git init && git add . && git commit -q -m 'extracted $(shell utils/file2url 'tar/$*')' # XXX


$(foreach package,$(packages),$(if $(filter-out svn|%,$($(package))),$(eval \
    build/extract/$(shell utils/spec2file '$($(package))'): \
        build/download/$(shell utils/file2base "$$(utils/spec2file '$($(package))')") \
)))

# place (patch) ################################################################

place: PHONY $(addprefix,build/compile/,$(packages))

compile_patch =$(filter     $(patsubst patches/%/,%,$(wildcard patches/*/)),$(packages))
compile_direct=$(filter-out $(patsubst patches/%/,%,$(wildcard patches/*/)),$(packages))

$(addprefix build/compile/,$(compile_patch)): build/compile/%:
	rm -rf '$@'
	mkdir -p '$(@D)'
	cp -a '$<' '$@'
	cd '$@' && \
	for patch in '$(top)/patches/$*'/*; do \
		patch -f -Np1 -i $$patch || { rm -rf '$@'; exit 1; }; \
	done
$(addprefix build/compile/,$(compile_direct)): build/compile/%:
	rm -rf '$@'
	mkdir -p '$(@D)'
	cp -a '$<' '$@'
$(foreach package,$(packages),$(eval \
    build/compile/$(package): \
        build/extract/$(shell utils/spec2file '$($(package))') \
))

# package ######################################################################

package: PHONY $(addprefix build/packages/,$(packages))

package_specific=$(filter     $(patsubst makefiles/%.mk,%,$(wildcard makefiles/*.mk)),$(packages))
package_generic =$(filter-out $(patsubst makefiles/%.mk,%,$(wildcard makefiles/*.mk)),$(packages))

dirs2jars = $(if $1,$(shell find $1 -name '*.jar'))
deps2jars = $(filter %.jar,$1) $(call dirs2jars,$(filter build/packages/%,$1))
deps2classpath = $(shell echo $(abspath $(call deps2jars,$1)) | tr ' ' :)

$(addprefix build/packages/,$(package_specific)): \
build/packages/%: RECURSIVE build/compile/% makefiles/%.mk
	$(MAKE) -C build/compile/$* -f '$(top)/makefiles/$*.mk' install
		DESTDIR='$(top)/$@' \
		CLASSPATH='$(call deps2classpath,$^)'
	mkdir -p build/packages/dest && lndir -silent '$(top)/$@' build/packages/dest


$(addprefix build/packages/,$(package_generic)): \
build/packages/%: RECURSIVE build/compile/% makefiles/mvn-simple.mk
	$(MAKE) -C build/compile/$* -f '$(top)/makefiles/mvn-simple.mk' install \
		DESTDIR='$(top)/$@' \
		CLASSPATH='$(call deps2classpath,$^)'
	mkdir -p build/packages/dest && lndir -silent '$(top)/$@' build/packages/dest

# dependencies #################################################################

# boilerplate ##################################################################

clean: PHONY
	rm -rf build/compile build/packages
distclean: PHONY
	rm -rf .tokens build
.tokens/%:
	mkdir -p '$(@D)' && touch '$@'

.PHONY: RECURSIVE PHONY