1 #!/bin/bash 2 set -u 3 set -e 4 rm -rf out generated 5 6 mkdir out 7 8 # Create dummy Java files for Android APIs that are used by the code we generate. 9 # This allows us to test the generated code without building the rest of Android. 10 11 mkdir -p out/javax/microedition/khronos/opengles 12 mkdir -p out/com/google/android/gles_jni 13 mkdir -p out/android/app 14 mkdir -p out/android/graphics 15 mkdir -p out/android/opengl 16 mkdir -p out/android/content 17 mkdir -p out/android/content/pm 18 mkdir -p out/android/os 19 mkdir -p out/android/util 20 21 echo "package android.graphics;" > out/android/graphics/Canvas.java 22 echo "public interface Canvas {}" >> out/android/graphics/Canvas.java 23 24 echo "package android.app; import android.content.pm.IPackageManager; public class ActivityThread { public static final ActivityThread currentActivityThread() { return null; } public static final String currentPackageName(){ return null; } public static IPackageManager getPackageManager() { return null;} }" > out/android/app/ActivityThread.java 25 # echo "package android.content; import android.content.pm.PackageManager; public interface Context { public PackageManager getPackageManager(); }" > out/android/content/Context.java 26 echo "package android.content.pm; public class ApplicationInfo {public int targetSdkVersion;}" > out/android/content/pm/ApplicationInfo.java 27 echo "package android.content.pm; public interface IPackageManager {ApplicationInfo getApplicationInfo(java.lang.String packageName, int flags) throws android.os.RemoteException;}" > out/android/content/pm/IPackageManager.java 28 echo "package android.os; public class Build {public static class VERSION_CODES { public static final int CUPCAKE = 3;}; }" > out/android/os/Build.java 29 echo "package android.os; public class RemoteException extends Exception {}" > out/android/os/RemoteException.java 30 echo "package android.util; public class Log {public static void w(String a, String b) {} public static void e(String a, String b) {}}" > out/android/util/Log.java 31 32 GLFILE=out/javax/microedition/khronos/opengles/GL.java 33 cp stubs/jsr239/GLHeader.java-if $GLFILE 34 35 GLGEN_FILES="CFunc.java CType.java CodeEmitter.java GenerateGL.java GenerateGLES.java GLESCodeEmitter.java JFunc.java JniCodeEmitter.java JType.java Jsr239CodeEmitter.java ParameterChecker.java" 36 37 pushd src > /dev/null 38 javac ${GLGEN_FILES} 39 JAVAC_RESULT=$? 40 if [ $JAVAC_RESULT -ne 0 ]; then 41 echo "Could not compile glgen." 42 exit $JAVAC_RESULT 43 fi 44 popd > /dev/null 45 46 echo "Generating JSR239-like APIs" 47 java -classpath src GenerateGL -c specs/jsr239/glspec-1.0 specs/jsr239/glspec-1.0ext specs/jsr239/glspec-1.1 specs/jsr239/glspec-1.1ext specs/jsr239/glspec-1.1extpack specs/jsr239/glspec-checks 48 JAVA_RESULT=$? 49 if [ $JAVA_RESULT -ne 0 ]; then 50 echo "Could not run GenerateGL." 51 exit $JAVA_RESULT 52 fi 53 54 echo "Generating static OpenGLES 1.1 bindings" 55 java -classpath src GenerateGLES 56 JAVA_RESULT=$? 57 if [ $JAVA_RESULT -ne 0 ]; then 58 echo "Could not run GenerateGLES." 59 exit $JAVA_RESULT 60 fi 61 62 rm src/*.class 63 64 pushd out > /dev/null 65 mkdir classes 66 javac -d classes com/google/android/gles_jni/GLImpl.java javax/microedition/khronos/opengles/GL10.java javax/microedition/khronos/opengles/GL10Ext.java javax/microedition/khronos/opengles/GL11.java javax/microedition/khronos/opengles/GL11Ext.java javax/microedition/khronos/opengles/GL11ExtensionPack.java android/opengl/GLES10.java android/opengl/GLES10Ext.java android/opengl/GLES11.java android/opengl/GLES11Ext.java android/opengl/GLES20.java 67 popd > /dev/null 68 JAVA_RESULT=$? 69 if [ $JAVA_RESULT -ne 0 ]; then 70 echo "Could not compile generated classes." 71 exit $JAVA_RESULT 72 fi 73 74 rm -rf generated 75 mkdir -p generated/C 76 cp out/com_google_android_gles_jni_GLImpl.cpp generated/C 77 cp -r out/com generated 78 cp -r out/javax generated 79 80 cp out/android_opengl_*.cpp generated/C 81 mkdir -p generated/android/opengl 82 cp -r out/android/opengl generated/android 83 84 rm -rf out 85 KEEP_GENERATED=0 86 SAID_PLEASE=0 87 88 # compareGenerated destDir generatedDir file 89 compareGenerated() { 90 if cmp -s $1/$3 $2/$3 ; then 91 echo "# " $3 unchanged 92 else 93 if [ $SAID_PLEASE == "0" ] ; then 94 echo Please evaluate the following commands: 95 echo 96 SAID_PLEASE=1 97 fi 98 echo " " cp $2/$3 $1 99 echo " " git add $1/$3 100 KEEP_GENERATED=1 101 fi 102 } 103 104 compareGenerated ../../../core/jni generated/C com_google_android_gles_jni_GLImpl.cpp 105 compareGenerated ../../java/com/google/android/gles_jni generated/com/google/android/gles_jni GLImpl.java 106 107 for x in GL.java GL10.java GL10Ext.java GL11.java GL11Ext.java GL11ExtensionPack.java 108 do 109 compareGenerated ../../java/javax/microedition/khronos/opengles generated/javax/microedition/khronos/opengles $x 110 done 111 112 for x in GLES10 GLES10Ext GLES11 GLES11Ext GLES20 113 do 114 compareGenerated ../../java/android/opengl generated/android/opengl ${x}.java 115 compareGenerated ../../../core/jni generated/C android_opengl_${x}.cpp 116 done 117 118 if [ $KEEP_GENERATED == "0" ] ; then 119 rm -rf generated 120 fi 121