1#!/bin/bash
2#
3# GNU/Linux build script for ProGuard.
4
5#
6# Configuration.
7#
8
9ANT_HOME=${ANT_HOME:-/usr/local/java/ant}
10GRADLE_HOME=${GRADLE_HOME:-/usr/local/java/gradle}
11WTK_HOME=${WTK_HOME:-/usr/local/java/wtk}
12
13if [ -z $PROGUARD_HOME ]; then
14  PROGUARD_HOME=$(which "$0")
15  PROGUARD_HOME=$(dirname "$0")/..
16fi
17
18cd "$PROGUARD_HOME"
19
20SRC=src
21CLASSES=classes
22LIB=lib
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
31ANT_JAR=$ANT_HOME/lib/ant.jar
32GRADLE_PATH=\
33$GRADLE_HOME/lib/plugins/gradle-plugins-2.1.jar:\
34$GRADLE_HOME/lib/gradle-base-services-2.1.jar:\
35$GRADLE_HOME/lib/gradle-base-services-groovy-2.1.jar:\
36$GRADLE_HOME/lib/gradle-core-2.1.jar:\
37$GRADLE_HOME/lib/groovy-all-2.3.6.jar
38WTK_JAR=$WTK_HOME/wtklib/kenv.zip
39
40PROGUARD_JAR=$LIB/proguard.jar
41PROGUARD_GUI_JAR=$LIB/proguardgui.jar
42RETRACE_JAR=$LIB/retrace.jar
43
44#
45# Function definitions.
46#
47
48function compile {
49  # Compile java source files.
50  echo "Compiling ${1//\//.} ..."
51  javac -nowarn -Xlint:none -sourcepath "$SRC" -d "$CLASSES" \
52    "$SRC/$1.java" 2>&1 \
53  | sed -e 's|^|  |'
54
55  # Copy resource files.
56  (cd "$SRC"; find $(dirname $1) -maxdepth 1 \
57     \( -name \*.properties -o -name \*.png -o -name \*.gif -o -name \*.pro \) \
58     -exec cp --parents {} "../$CLASSES" \; )
59}
60
61function createjar {
62  echo "Creating $2..."
63  jar -cfm "$2" "$SRC/$(dirname $1)/MANIFEST.MF" -C "$CLASSES" $(dirname $1)
64}
65
66function updatejar {
67  echo "Updating $PROGUARD_JAR..."
68  jar -uf "$PROGUARD_JAR" -C "$CLASSES" $(dirname $1)
69}
70
71#
72# Main script body.
73#
74
75mkdir -p "$CLASSES"
76
77compile   $PROGUARD
78createjar $PROGUARD "$PROGUARD_JAR"
79
80compile   $PROGUARD_GUI
81createjar $PROGUARD_GUI "$PROGUARD_GUI_JAR"
82
83compile   $RETRACE
84createjar $RETRACE "$RETRACE_JAR"
85
86if [ -f "$ANT_JAR" ]; then
87  export CLASSPATH=$ANT_JAR
88  compile   $ANT_TASK
89  updatejar $ANT_TASK
90else
91  echo "Please make sure the environment variable ANT_HOME is set correctly,"
92  echo "if you want to compile the optional ProGuard Ant task."
93fi
94
95if [ -f "${GRADLE_PATH%%:*}" ]; then
96  export CLASSPATH=$GRADLE_PATH
97  compile   $GRADLE_TASK
98  updatejar $GRADLE_TASK
99else
100  echo "Please make sure the environment variable GRADLE_HOME is set correctly,"
101  echo "if you want to compile the optional ProGuard Gradle task."
102fi
103
104if [ -f "$WTK_JAR" ]; then
105  export CLASSPATH=$WTK_JAR
106  compile   $WTK_PLUGIN
107  updatejar $WTK_PLUGIN
108else
109  echo "Please make sure the environment variable WTK_HOME is set correctly,"
110  echo "if you want to compile the optional ProGuard WTK plugin."
111fi
112