1# GNU/Linux makefile for ProGuard.
2
3ANT_HOME    = /usr/local/java/ant
4GRADLE_HOME = /usr/local/java/gradle
5WTK_HOME    = /usr/local/java/wtk
6
7PROGUARD_HOME := $(subst ./..,..,$(subst /build/..,/,$(dir $(MAKEFILE_LIST))..))
8SRC     = $(PROGUARD_HOME)/src
9CLASSES = $(PROGUARD_HOME)/classes
10LIB     = $(PROGUARD_HOME)/lib
11
12ANT_JAR     = $(ANT_HOME)/lib/ant.jar
13GRADLE_JARS = $(GRADLE_HOME)/lib/plugins/gradle-plugins-2.1.jar \
14              $(GRADLE_HOME)/lib/gradle-base-services-2.1.jar \
15              $(GRADLE_HOME)/lib/gradle-base-services-groovy-2.1.jar \
16              $(GRADLE_HOME)/lib/gradle-core-2.1.jar \
17              $(GRADLE_HOME)/lib/groovy-all-2.3.6.jar
18WTK_JAR     = $(WTK_HOME)/wtklib/kenv.zip
19
20NOTHING:=
21SPACE:=$(NOTHING) $(NOTHING)
22CLASSPATH = $(ANT_JAR):$(subst $(SPACE),:,$(GRADLE_JARS)):$(WTK_JAR)
23
24PROGUARD     = proguard/ProGuard
25PROGUARD_GUI = proguard/gui/ProGuardGUI
26RETRACE      = proguard/retrace/ReTrace
27ANT_TASK     = proguard/ant/ProGuardTask
28GRADLE_TASK  = proguard/gradle/ProGuardTask
29WTK_PLUGIN   = proguard/wtk/ProGuardObfuscator
30
31TARGETS = $(PROGUARD) $(PROGUARD_GUI) $(RETRACE) $(ANT_TASK) $(GRADLE_TASK) $(WTK_PLUGIN)
32
33JAVAC_OPTIONS = -nowarn -Xlint:none -classpath $(CLASSPATH) -sourcepath $(SRC) -d $(CLASSES)
34
35# Command sequence definitions for creating jars.
36
37define createjar
38  jar -cfm $(LIB)/$@.jar $(SRC)/$(dir $<)MANIFEST.MF \
39    -C $(CLASSES) $(dir $<)
40endef
41
42define updatejar
43  jar -uf $(LIB)/proguard.jar \
44    -C $(CLASSES) $(dir $<)
45endef
46
47# The various targets.
48
49all:     basic options
50basic:   proguard proguardgui retrace
51options: anttask gradletask wtkplugin
52
53proguard: $(PROGUARD)
54	$(createjar)
55
56proguardgui: proguard
57proguardgui: $(PROGUARD_GUI)
58	$(createjar)
59
60retrace: $(RETRACE)
61	$(createjar)
62
63anttask: $(ANT_JAR)
64anttask: $(PROGUARD)
65anttask: $(ANT_TASK)
66	$(updatejar)
67
68gradletask: $(GRADLE_JARS)
69gradletask: $(PROGUARD)
70gradletask: $(GRADLE_TASK)
71	$(updatejar)
72
73wtkplugin: $(WTK_JAR)
74wtkplugin: $(PROGUARD)
75wtkplugin: $(WTK_PLUGIN)
76	$(updatejar)
77
78clean:
79	-rm -fr $(CLASSES) $(LIB)
80
81
82define RESOURCES
83  $(shell find $(SRC)/$(dir $(1)) -maxdepth 1 \( -name \*.properties -o -name \*.png -o -name \*.gif -o -name \*.pro \) -printf $(CLASSES)/$(dir $(1))%P\\n)
84endef
85
86define TARGETRULE
87  $(1): $(CLASSES) $(CLASSES)/$(1).class $(call RESOURCES,$(1)) $(LIB)
88endef
89
90$(foreach TARGET,$(TARGETS),$(eval $(call TARGETRULE,$(TARGET))))
91
92$(CLASSES) $(LIB):
93	-mkdir -p $@
94
95$(CLASSES)/%.class: $(SRC)/%.java
96	javac $(JAVAC_OPTIONS) $^
97
98$(CLASSES)/%.properties $(CLASSES)/%.png $(CLASSES)/%.gif $(CLASSES)/%.pro:
99	cp $(subst $(CLASSES),$(SRC),$@) $@
100
101%.jar %.zip:
102	echo "Please make sure the path to $@ is set"
103	echo "correctly in this $(strip $(MAKEFILE_LIST))."
104	echo "Alternatively, if you don't need the corresponding option,"
105	echo "you can run `make' with the option -k."
106	find $@
107
108.PHONY: all basic options proguard proguardgui retrace anttask wtkplugin clean $(TARGETS) $(OPTIONAL_TARGETS)
109