Home | History | Annotate | Download | only in build
      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 WTK_HOME=${WTK_HOME:-/usr/local/java/wtk}
     11 
     12 if [ -z $PROGUARD_HOME ]; then
     13   PROGUARD_HOME=$(which "$0")
     14   PROGUARD_HOME=$(dirname "$0")/..
     15 fi
     16 
     17 cd "$PROGUARD_HOME"
     18 
     19 SRC=src
     20 CLASSES=classes
     21 LIB=lib
     22 
     23 PROGUARD=proguard/ProGuard
     24 PROGUARD_GUI=proguard/gui/ProGuardGUI
     25 RETRACE=proguard/retrace/ReTrace
     26 ANT_TASK=proguard/ant/ProGuardTask
     27 WTK_PLUGIN=proguard/wtk/ProGuardObfuscator
     28 
     29 ANT_JAR=$ANT_HOME/lib/ant.jar
     30 WTK_JAR=$WTK_HOME/wtklib/kenv.zip
     31 
     32 PROGUARD_JAR=$LIB/proguard.jar
     33 PROGUARD_GUI_JAR=$LIB/proguardgui.jar
     34 RETRACE_JAR=$LIB/retrace.jar
     35 
     36 #
     37 # Function definitions.
     38 #
     39 
     40 function compile {
     41   # Compile java source files.
     42   echo "Compiling ${1//\//.} ..."
     43   javac -nowarn -Xlint:none -sourcepath "$SRC" -d "$CLASSES" \
     44     "$SRC/$1.java" 2>&1 \
     45   | sed -e 's|^|  |'
     46 
     47   # Copy resource files.
     48   (cd "$SRC"; find $(dirname $1) -maxdepth 1 \
     49      \( -name \*.properties -o -name \*.png -o -name \*.gif -o -name \*.pro \) \
     50      -exec cp --parents {} "../$CLASSES" \; )
     51 }
     52 
     53 function createjar {
     54   echo "Creating $2..."
     55   jar -cfm "$2" "$SRC/$(dirname $1)/MANIFEST.MF" -C "$CLASSES" $(dirname $1)
     56 }
     57 
     58 function updatejar {
     59   echo "Updating $PROGUARD_JAR..."
     60   jar -uf "$PROGUARD_JAR" -C "$CLASSES" $(dirname $1)
     61 }
     62 
     63 #
     64 # Main script body.
     65 #
     66 
     67 mkdir -p "$CLASSES"
     68 
     69 compile   $PROGUARD
     70 createjar $PROGUARD "$PROGUARD_JAR"
     71 
     72 compile   $PROGUARD_GUI
     73 createjar $PROGUARD_GUI "$PROGUARD_GUI_JAR"
     74 
     75 compile   $RETRACE
     76 createjar $RETRACE "$RETRACE_JAR"
     77 
     78 if [ -f "$ANT_JAR" ]; then
     79   export CLASSPATH=$ANT_JAR
     80   compile   $ANT_TASK
     81   updatejar $ANT_TASK
     82 else
     83   echo "Please make sure the environment variable ANT_HOME is set correctly,"
     84   echo "if you want to compile the optional ProGuard Ant task."
     85 fi
     86 
     87 if [ -f "$WTK_JAR" ]; then
     88   export CLASSPATH=$WTK_JAR
     89   compile   $WTK_PLUGIN
     90   updatejar $WTK_PLUGIN
     91 else
     92   echo "Please make sure the environment variable WTK_HOME is set correctly,"
     93   echo "if you want to compile the optional ProGuard WTK plugin."
     94 fi
     95