aboutsummaryrefslogtreecommitdiffstats
path: root/build/build.sh
blob: ad51c04af620d9fea68d858adb8c0f56942dcaf4 (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
#!/bin/bash
#
# GNU/Linux build script for ProGuard.

#
# Configuration.
#

ANT_HOME=${ANT_HOME:-/usr/local/java/ant}
GRADLE_HOME=${GRADLE_HOME:-/usr/local/java/gradle}
WTK_HOME=${WTK_HOME:-/usr/local/java/wtk}

if [ -z $PROGUARD_HOME ]; then
  PROGUARD_HOME=$(which "$0")
  PROGUARD_HOME=$(dirname "$0")/..
fi

cd "$PROGUARD_HOME"

SRC=src
CLASSES=classes
LIB=lib

PROGUARD=proguard/ProGuard
PROGUARD_GUI=proguard/gui/ProGuardGUI
RETRACE=proguard/retrace/ReTrace
ANT_TASK=proguard/ant/ProGuardTask
GRADLE_TASK=proguard/gradle/ProGuardTask
WTK_PLUGIN=proguard/wtk/ProGuardObfuscator

ANT_JAR=$ANT_HOME/lib/ant.jar
GRADLE_PATH=\
$GRADLE_HOME/lib/plugins/gradle-plugins-2.1.jar:\
$GRADLE_HOME/lib/gradle-base-services-2.1.jar:\
$GRADLE_HOME/lib/gradle-base-services-groovy-2.1.jar:\
$GRADLE_HOME/lib/gradle-core-2.1.jar:\
$GRADLE_HOME/lib/groovy-all-2.3.6.jar
WTK_JAR=$WTK_HOME/wtklib/kenv.zip

PROGUARD_JAR=$LIB/proguard.jar
PROGUARD_GUI_JAR=$LIB/proguardgui.jar
RETRACE_JAR=$LIB/retrace.jar

#
# Function definitions.
#

function compile {
  # Compile java source files.
  echo "Compiling ${1//\//.} ..."
  javac -nowarn -Xlint:none -sourcepath "$SRC" -d "$CLASSES" \
    "$SRC/$1.java" 2>&1 \
  | sed -e 's|^|  |'

  # Copy resource files.
  (cd "$SRC"; find $(dirname $1) -maxdepth 1 \
     \( -name \*.properties -o -name \*.png -o -name \*.gif -o -name \*.pro \) \
     -exec cp --parents {} "../$CLASSES" \; )
}

function createjar {
  echo "Creating $2..."
  jar -cfm "$2" "$SRC/$(dirname $1)/MANIFEST.MF" -C "$CLASSES" $(dirname $1)
}

function updatejar {
  echo "Updating $PROGUARD_JAR..."
  jar -uf "$PROGUARD_JAR" -C "$CLASSES" $(dirname $1)
}

#
# Main script body.
#

mkdir -p "$CLASSES"

compile   $PROGUARD
createjar $PROGUARD "$PROGUARD_JAR"

compile   $PROGUARD_GUI
createjar $PROGUARD_GUI "$PROGUARD_GUI_JAR"

compile   $RETRACE
createjar $RETRACE "$RETRACE_JAR"

if [ -f "$ANT_JAR" ]; then
  export CLASSPATH=$ANT_JAR
  compile   $ANT_TASK
  updatejar $ANT_TASK
else
  echo "Please make sure the environment variable ANT_HOME is set correctly,"
  echo "if you want to compile the optional ProGuard Ant task."
fi

if [ -f "${GRADLE_PATH%%:*}" ]; then
  export CLASSPATH=$GRADLE_PATH
  compile   $GRADLE_TASK
  updatejar $GRADLE_TASK
else
  echo "Please make sure the environment variable GRADLE_HOME is set correctly,"
  echo "if you want to compile the optional ProGuard Gradle task."
fi

if [ -f "$WTK_JAR" ]; then
  export CLASSPATH=$WTK_JAR
  compile   $WTK_PLUGIN
  updatejar $WTK_PLUGIN
else
  echo "Please make sure the environment variable WTK_HOME is set correctly,"
  echo "if you want to compile the optional ProGuard WTK plugin."
fi