summaryrefslogtreecommitdiff
path: root/rules/janino/Makefile
blob: 042e6f307b1c7b3b0c06853f966020e12a247793 (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
DESTDIR ?=
MAVEN_LOCAL_REPO ?= ~/.m2

ANT = ant
EXISTS = test -e
FAIL = exit 1
FIND = find
INSTALL = install
MKDIRS = mkdir -p
RM = rm -f
SED = sed
TOUCH = touch
XMLSTARLET = xml

pom_get = $(shell $(XMLSTARLET) sel -T -t $(foreach xpath,$1, -v '$(subst /,/_:,$(xpath))' -n) janino-dist/poms/$(artifactId).pom)

version     := $(shell $(SED) -n 's/^version\s*=\s*//p' janino-dist/build.properties)
artifactIds := $(patsubst janino-dist/poms/%.pom,%,$(wildcard janino-dist/poms/*.pom))
groupId      = $(firstword $(call pom_get,/project/groupId /project/parent/groupId))

findjar = $(firstword $(foreach path,$(subst :, ,$(CLASSPATH)),$(if $(findstring $1,$(path)),$(path))) /notfound.jar)
ant_jar = $(call findjar,ant)

all: PHONY $(foreach a,$(artifactIds),janino-dist/build/$a.jar .poms/$a-$(version).jar)

ignore = .poms build mirror
janino-dist/build: $(shell $(FIND) . -mindepth 1 $(foreach d,$(ignore),-name $d -prune -o) -name '* *' -prune -o -print)
	$(SED) -ri 's|^(ant\.jar\s*=).*|\1 $(ant_jar)|' janino-dist/build.properties && \
	cd janino-dist && $(ANT) || { $(RM) -r $@; $(FAIL); }
	$(TOUCH) $@
janino-dist/build/%.jar: janino-dist/build
	$(EXISTS) $@ || { $(RM) -r $<; $(FAIL); }
	$(TOUCH) $@

.poms/%-$(version).pom: janino-dist/poms/%.pom
	$(MKDIRS) $(@D)
	$(SED) 's|@VERSION@|$(version)|' < $< > $@

install-base = $(DESTDIR)$(MAVEN_LOCAL_REPO)/$(subst .,/,$(groupId))/$(artifactId)/$(version)/$(artifactId)-$(version)
install-jars = $(foreach artifactId,$(filter-out %-parent,$(artifactIds)),$(install-base).jar)
install-poms = $(foreach artifactId,                      $(artifactIds) ,$(install-base).pom)
install-targets = $(install-jars) $(install-poms)
install: PHONY $(install-targets)

$(foreach artifactId,$(artifactIds),                                                            \
  $(eval $(install-base).jar: janino-dist/build/$(artifactId).jar ; $$(INSTALL) -Dm644 $$< $$@) \
  $(eval $(install-base).pom: .poms/$(artifactId)-$(version).pom  ; $$(INSTALL) -Dm644 $$< $$@) )

clean: PHONY
	$(RM) -r .poms janino-dist/build

.PHONY: PHONY
.DELETE_ON_ERROR:
.SECONDARY: