Issue 439: be more lax and don't look for END
[zxing.git] / javame / build.xml
index 59b542e..aefb989 100644 (file)
 <?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright 2007 ZXing authors
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
 <project name="javame" default="build">
 
   <property file="../build.properties"/>
 
+  <path id="wtk-build-path">
+    <fileset dir="${WTK-home}/lib">
+      <!-- These are used with WTK 2.5.x -->
+      <!--
+      <include name="cldcapi11.jar"/>
+      <include name="midpapi20.jar"/>
+      <include name="mmapi.jar"/>
+      <include name="jsr234.jar"/>
+      <include name="satsa-apdu.jar"/>
+      -->
+      <include name="cldc_1.1.jar"/>
+      <include name="midp_2.0.jar"/>
+      <include name="jsr135_1.2.jar"/>
+      <include name="jsr234_1.0.jar"/>
+    </fileset>
+    <pathelement location="../core/core.jar"/>
+  </path>
+  <property name="preverify-classpath" refid="wtk-build-path"/>
+
+  <path id="javame-compile-bootclasspath">
+    <fileset dir="${WTK-home}/lib">
+      <!-- These are used with WTK 2.5.x -->
+      <!--
+      <include name="cldcapi11.jar"/>
+      <include name="midpapi20.jar"/>
+      -->
+      <include name="cldc_1.1.jar"/>
+      <include name="midp_2.0.jar"/>
+    </fileset>
+  </path>
+  <property name="javame-compile-bootclasspath-path" refid="javame-compile-bootclasspath"/>
+
   <target name="init">
     <tstamp/>
+    <fail message="Please set 'WTK-home' in build.properties">
+      <condition>
+        <not>
+          <available file="${WTK-home}" type="dir"/>
+        </not>
+      </condition>
+    </fail>
+    <fail message="Please set 'proguard.jar' in build.properties">
+      <condition>
+        <not>
+          <available file="${proguard-jar}" type="file"/>
+        </not>
+      </condition>
+    </fail>
+    <fail message="Please build 'core' first">
+      <condition>
+        <not>
+          <available file="../core/core.jar" type="file"/>
+        </not>
+      </condition>
+    </fail>
   </target>
 
   <target name="build" depends="init">
     <mkdir dir="build"/>
     <javac srcdir="src"
            destdir="build"
-           source="1.4"
-           target="1.4"
-           bootclasspath="${JDK1.4-home}/jre/lib/rt.jar"
+           source="1.2"
+           target="1.2"
+           bootclasspath="${javame-compile-bootclasspath-path}"
            optimize="true"
            debug="true"
            deprecation="true"
            fork="true">
-      <classpath>
-        <pathelement location="${WTK-home}/lib/cldcapi11.jar"/>
-        <pathelement location="${WTK-home}/lib/midpapi20.jar"/>
-        <pathelement location="${WTK-home}/lib/mmapi.jar"/>
-        <pathelement location="../core/core.jar"/>
-      </classpath>
+      <classpath refid="wtk-build-path"/>
     </javac>
+    <jar jarfile="javame.jar" basedir="build"/>
 
     <unzip src="../core/core.jar" dest="build"/>
 
+    <!--
     <mkdir dir="build-j2me"/>
-    <exec executable="${WTK-home}/bin/preverify1.1">
-      <arg line="-classpath ${WTK-home}/lib/cldcapi11.jar:${WTK-home}/lib/midpapi20.jar:${WTK-home}/lib/mmapi.jar:${WTK-home}/lib/satsa-apdu.jar -d build-j2me build"/>
+    <exec executable="${WTK-home}/bin/preverify1.1" failonerror="true">
+      <arg line="-classpath '${preverify-classpath}' -d build-j2me build"/>
     </exec>
+    -->
+    <copy todir="build-j2me">
+      <fileset dir="build"/>
+    </copy>
 
     <copy todir="build-j2me">
       <fileset dir=".">
       </fileset>
     </copy>
 
-    <jar jarfile="ZXingReader.jar" basedir="build-j2me" manifest="src/com/google/zxing/client/j2me/MANIFEST.MF"/>
+    <copy file="src/com/google/zxing/client/j2me/MANIFEST.MF.template"
+          tofile="src/com/google/zxing/client/j2me/MANIFEST.MF" overwrite="true">
+      <filterset>
+        <filter token="APP_NAME" value="BarcodeReader"/>
+        <filter token="VERSION" value="${version}"/>
+      </filterset>
+    </copy>
+
+    <jar jarfile="BarcodeReader.jar" basedir="build-j2me" manifest="src/com/google/zxing/client/j2me/MANIFEST.MF"/>
+
+    <move file="BarcodeReader.jar" tofile="temp.jar"/>
+    <java jar="${proguard-jar}" fork="true" failonerror="true">
+      <jvmarg value="-Dmaximum.inlined.code.length=32"/>
+      <arg value="-injars temp.jar"/>
+      <arg value="-outjars BarcodeReader.jar"/>
+      <!-- These are used with WTK 2.5.x -->
+      <!--
+      <arg value="-libraryjars ${WTK-home}/lib/cldcapi11.jar"/>
+      <arg value="-libraryjars ${WTK-home}/lib/midpapi20.jar"/>
+      <arg value="-libraryjars ${WTK-home}/lib/mmapi.jar"/>
+      <arg value="-libraryjars ${WTK-home}/lib/jsr234.jar"/>
+      -->
+      <arg value="-libraryjars ${WTK-home}/lib/cldc_1.1.jar"/>
+      <arg value="-libraryjars ${WTK-home}/lib/midp_2.0.jar"/>
+      <arg value="-libraryjars ${WTK-home}/lib/jsr135_1.2.jar"/>
+      <arg value="-libraryjars ${WTK-home}/lib/jsr234_1.0.jar"/>
+      <arg value="-microedition"/>
+      <arg value="-keep public class com.google.zxing.client.j2me.ZXingMIDlet"/>
+      <arg value="-keep class com.google.zxing.client.j2me.AdvancedMultimediaManager"/>
+      <arg value="-keep class com.google.zxing.client.j2me.DefaultMultimediaManager"/>
+      <arg value="-keep class com.google.zxing.client.j2me.MultimediaManager"/>      
+      <arg value="-optimizationpasses 5"/>
+      <arg value="-overloadaggressively"/>
+      <arg value="-allowaccessmodification"/>
+      <arg value="-verbose"/>
+      <arg value="-dump proguard-dump.txt"/>
+    </java>
+    <delete file="temp.jar"/>
 
     <!-- get .jar size to include it in the .jad file -->
-    <exec executable="sh" outputproperty="jar-size">
-      <arg line="-c &quot;wc -c ZXingReader.jar | cut -d' ' -f1&quot;"/>
-    </exec>
-    <copy file="ZXingReader.jad.template" tofile="ZXingReader.jad">
+    <length file="BarcodeReader.jar" property="jar-size"/>
+
+    <copy file="BarcodeReader.jad.template" tofile="BarcodeReader.jad" overwrite="true">
       <filterset>
         <filter token="JAR_SIZE" value="${jar-size}"/>
+        <filter token="APP_NAME" value="BarcodeReader"/>
+        <filter token="VERSION" value="${version}"/>
       </filterset>
     </copy>
 
   </target>
 
+  <target name="dump">
+    <java jar="${proguard-jar}" fork="true">
+      <arg value="-injars BarcodeReader.jar"/>
+      <!-- These are used with WTK 2.5.x -->
+      <!--
+      <arg value="-libraryjars ${WTK-home}/lib/cldcapi11.jar"/>
+      <arg value="-libraryjars ${WTK-home}/lib/midpapi20.jar"/>
+      <arg value="-libraryjars ${WTK-home}/lib/mmapi.jar"/>
+      <arg value="-libraryjars ${WTK-home}/lib/jsr234.jar"/>
+      -->
+      <arg value="-libraryjars ${WTK-home}/lib/cldc_1.1.jar"/>
+      <arg value="-libraryjars ${WTK-home}/lib/midp_2.0.jar"/>
+      <arg value="-libraryjars ${WTK-home}/lib/jsr135_1.2.jar"/>
+      <arg value="-libraryjars ${WTK-home}/lib/jsr234_1.0.jar"/>
+      <arg value="-dontshrink"/>
+      <arg value="-dontobfuscate"/>
+      <arg value="-dontoptimize"/>
+      <arg value="-dump dump.txt"/>
+    </java>
+  </target>
+
   <target name="clean">
     <delete dir="build"/>
     <delete dir="build-j2me"/>
-    <delete file="ZXingReader.jar"/>
-    <delete file="ZXingReader.jad"/>    
+    <delete dir="." includes="*.jar"/>
+    <delete dir="." includes="*.jad"/>
+    <delete file="src/com/google/zxing/client/j2me/MANIFEST.MF"/>
+    <delete file="proguard-dump.txt"/>
   </target>
 
 </project>