1 #!/bin/bash 2 # 3 # GNU/Linux build script for ProGuard. 4 5 # 6 # Configuration. 7 # 8 9 ANT_HOME=${ANT_HOME:-/usr/local/java/ant} 10 GRADLE_HOME=${GRADLE_HOME:-/usr/local/java/gradle} 11 WTK_HOME=${WTK_HOME:-/usr/local/java/wtk} 12 13 if [ -z $PROGUARD_HOME ]; then 14 PROGUARD_HOME=$(which "$0") 15 PROGUARD_HOME=$(dirname "$0")/.. 16 fi 17 18 cd "$PROGUARD_HOME" 19 20 SRC=src 21 CLASSES=classes 22 LIB=lib 23 24 PROGUARD=proguard/ProGuard 25 PROGUARD_GUI=proguard/gui/ProGuardGUI 26 RETRACE=proguard/retrace/ReTrace 27 ANT_TASK=proguard/ant/ProGuardTask 28 GRADLE_TASK=proguard/gradle/ProGuardTask 29 WTK_PLUGIN=proguard/wtk/ProGuardObfuscator 30 31 ANT_JAR=$ANT_HOME/lib/ant.jar 32 GRADLE_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 38 WTK_JAR=$WTK_HOME/wtklib/kenv.zip 39 40 PROGUARD_JAR=$LIB/proguard.jar 41 PROGUARD_GUI_JAR=$LIB/proguardgui.jar 42 RETRACE_JAR=$LIB/retrace.jar 43 44 # 45 # Function definitions. 46 # 47 48 function 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 61 function createjar { 62 echo "Creating $2..." 63 jar -cfm "$2" "$SRC/$(dirname $1)/MANIFEST.MF" -C "$CLASSES" $(dirname $1) 64 } 65 66 function updatejar { 67 echo "Updating $PROGUARD_JAR..." 68 jar -uf "$PROGUARD_JAR" -C "$CLASSES" $(dirname $1) 69 } 70 71 # 72 # Main script body. 73 # 74 75 mkdir -p "$CLASSES" 76 77 compile $PROGUARD 78 createjar $PROGUARD "$PROGUARD_JAR" 79 80 compile $PROGUARD_GUI 81 createjar $PROGUARD_GUI "$PROGUARD_GUI_JAR" 82 83 compile $RETRACE 84 createjar $RETRACE "$RETRACE_JAR" 85 86 if [ -f "$ANT_JAR" ]; then 87 export CLASSPATH=$ANT_JAR 88 compile $ANT_TASK 89 updatejar $ANT_TASK 90 else 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." 93 fi 94 95 if [ -f "${GRADLE_PATH%%:*}" ]; then 96 export CLASSPATH=$GRADLE_PATH 97 compile $GRADLE_TASK 98 updatejar $GRADLE_TASK 99 else 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." 102 fi 103 104 if [ -f "$WTK_JAR" ]; then 105 export CLASSPATH=$WTK_JAR 106 compile $WTK_PLUGIN 107 updatejar $WTK_PLUGIN 108 else 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." 111 fi 112