summaryrefslogtreecommitdiff
path: root/rules/jflex/Makefile
blob: 4db4db268f36186736e137ae50e26e6055f718a5 (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
DESTDIR ?=
MAVEN_LOCAL_REPO ?= ~/.m2
VIMDIR ?= /usr/share/vim/syntax
EMACSDIR ?= /usr/share/emacs/site-lisp

ANT = ant
EXISTS = test -e
FAIL = exit 1
FIND = find
INSTALL = install
RM = rm -f
SED = sed
TOUCH = touch
XMLSTARLET = xml
JLEX = jlex
JAVA_CUP = java-cup

artifactIds := jflex jflex-parent
version     := $(shell $(XMLSTARLET) sel -T -t -c /_:project/_:version -n parent.xml)
groupId     := $(shell $(XMLSTARLET) sel -T -t -c /_:project/_:groupId -n parent.xml)

jarfind = $(firstword $(foreach path,$(subst :, ,$(CLASSPATH)),$(if $(findstring $1,$(path)),$(path))))
junit_jar := $(call jarfind,junit)
jflex_jar := $(call jarfind,jflex)
export CLASSPATH :=

antflags = -Dversion='$(version)'
antflags += -Dsed.exe='$(SED)'
antflags += -Djlex.exe='$(JLEX)'
antflags += -Dcup.exe='$(JAVA_CUP)'
antflags += -Dbootstrap.jflex.jar='$(jflex_jar)'
antflags += -Djunit.jar='$(junit_jar)'

all: PHONY build

build: $(shell $(FIND) src/main) $(wildcard jflex2jlex.*) build.xml
	$(ANT) $(antflags) build || { $(RM) -r $@; $(FAIL); }
	$(TOUCH) $@

install-base = $(DESTDIR)$(MAVEN_LOCAL_REPO)/$(subst .,/,$(groupId))/$(artifactId)/$(version)/$(artifactId)-$(version)

install-jflex = $(foreach artifactId,jflex,$(install-base).pom $(install-base).jar)
install-jflex-parent = $(foreach artifactId,jflex-parent,$(install-base).pom)
install: PHONY $(install-jflex) $(install-jflex-parent) $(DESTDIR)$(VIMDIR)/jflex.vim $(DESTDIR)$(EMACSDIR)/jflex-mode.el

$(filter %.jar,$(install-jflex)): build/jflex-$(version).jar
	$(INSTALL) -Dm644 $< $@
$(filter %.pom,$(install-jflex)): pom.xml
	$(INSTALL) -Dm644 $< $@
$(install-jflex-parent): parent.xml
	$(INSTALL) -Dm644 $< $@
$(DESTDIR)$(VIMDIR)/jflex.vim: lib/jflex.vim
	$(INSTALL) -Dm644 $< $@
$(DESTDIR)$(EMACSDIR)/jflex-mode.el: lib/jflex-mode.el
	$(INSTALL) -Dm644 $< $@

build/jflex-$(version).jar: build
	$(EXISTS) $@
	$(TOUCH) $@

clean: PHONY
	$(RM) -r build

.PHONY: PHONY
.DELETE_ON_ERROR: