1#!/bin/bash 2set -u 3set -e 4rm -rf out generated 5 6mkdir 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 11mkdir -p out/javax/microedition/khronos/opengles 12mkdir -p out/com/google/android/gles_jni 13mkdir -p out/android/app 14mkdir -p out/android/graphics 15mkdir -p out/android/opengl 16mkdir -p out/android/content 17mkdir -p out/android/content/pm 18mkdir -p out/android/os 19mkdir -p out/android/util 20 21echo "package android.graphics;" > out/android/graphics/Canvas.java 22echo "public interface Canvas {}" >> out/android/graphics/Canvas.java 23 24echo "package android.app; import android.content.pm.IPackageManager; public class AppGlobals { public static IPackageManager getPackageManager() { return null;} }" > out/android/app/AppGlobals.java 25# echo "package android.content; import android.content.pm.PackageManager; public interface Context { public PackageManager getPackageManager(); }" > out/android/content/Context.java 26echo "package android.content.pm; public class ApplicationInfo {public int targetSdkVersion;}" > out/android/content/pm/ApplicationInfo.java 27echo "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 28echo "package android.os; public class Build {public static class VERSION_CODES { public static final int CUPCAKE = 3;}; }" > out/android/os/Build.java 29echo "package android.os; public class RemoteException extends Exception {}" > out/android/os/RemoteException.java 30echo "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 32GLFILE=out/javax/microedition/khronos/opengles/GL.java 33cp stubs/jsr239/GLHeader.java-if $GLFILE 34 35GLGEN_FILES="CFunc.java CType.java CodeEmitter.java GenerateGL.java GenerateGLES.java GLESCodeEmitter.java JFunc.java JniCodeEmitter.java JType.java Jsr239CodeEmitter.java ParameterChecker.java" 36 37pushd src > /dev/null 38javac ${GLGEN_FILES} 39JAVAC_RESULT=$? 40if [ $JAVAC_RESULT -ne 0 ]; then 41 echo "Could not compile glgen." 42 exit $JAVAC_RESULT 43fi 44popd > /dev/null 45 46echo "Generating JSR239-like APIs" 47java -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 48JAVA_RESULT=$? 49if [ $JAVA_RESULT -ne 0 ]; then 50 echo "Could not run GenerateGL." 51 exit $JAVA_RESULT 52fi 53 54echo "Generating static OpenGLES 1.1 bindings" 55java -classpath src GenerateGLES 56JAVA_RESULT=$? 57if [ $JAVA_RESULT -ne 0 ]; then 58 echo "Could not run GenerateGLES." 59 exit $JAVA_RESULT 60fi 61 62rm src/*.class 63 64pushd out > /dev/null 65mkdir classes 66javac -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 67popd > /dev/null 68JAVA_RESULT=$? 69if [ $JAVA_RESULT -ne 0 ]; then 70 echo "Could not compile generated classes." 71 exit $JAVA_RESULT 72fi 73 74rm -rf generated 75mkdir -p generated/C 76cp out/com_google_android_gles_jni_GLImpl.cpp generated/C 77cp -r out/com generated 78cp -r out/javax generated 79 80cp out/android_opengl_*.cpp generated/C 81mkdir -p generated/android/opengl 82cp -r out/android/opengl generated/android 83 84rm -rf out 85KEEP_GENERATED=0 86SAID_PLEASE=0 87 88# compareGenerated destDir generatedDir file 89compareGenerated() { 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 104compareGenerated ../../../core/jni generated/C com_google_android_gles_jni_GLImpl.cpp 105compareGenerated ../../java/com/google/android/gles_jni generated/com/google/android/gles_jni GLImpl.java 106 107for x in GL.java GL10.java GL10Ext.java GL11.java GL11Ext.java GL11ExtensionPack.java 108do 109 compareGenerated ../../java/javax/microedition/khronos/opengles generated/javax/microedition/khronos/opengles $x 110done 111 112for x in GLES10 GLES10Ext GLES11 GLES11Ext GLES20 113do 114 compareGenerated ../../java/android/opengl generated/android/opengl ${x}.java 115 compareGenerated ../../../core/jni generated/C android_opengl_${x}.cpp 116done 117 118if [ $KEEP_GENERATED == "0" ] ; then 119 rm -rf generated 120fi 121