Home | History | Annotate | Download | only in glgen
      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/view
     16 mkdir -p out/android/opengl
     17 mkdir -p out/android/content
     18 mkdir -p out/android/content/pm
     19 mkdir -p out/android/os
     20 mkdir -p out/android/util
     21 
     22 echo "package android.graphics;" > out/android/graphics/Canvas.java
     23 echo "public interface Canvas {}" >> out/android/graphics/Canvas.java
     24 
     25 echo "package android.app; import android.content.pm.IPackageManager; public class AppGlobals { public static IPackageManager getPackageManager() { return null;} }" > out/android/app/AppGlobals.java
     26 # echo "package android.content; import android.content.pm.PackageManager; public interface Context { public PackageManager getPackageManager(); }" > out/android/content/Context.java
     27 echo "package android.content.pm; public class ApplicationInfo {public int targetSdkVersion;}" > out/android/content/pm/ApplicationInfo.java
     28 echo "package android.content.pm; public interface IPackageManager {ApplicationInfo getApplicationInfo(java.lang.String packageName, int flags, java.lang.String userId) throws android.os.RemoteException;}" > out/android/content/pm/IPackageManager.java
     29 echo "package android.os; public class Build {public static class VERSION_CODES { public static final int CUPCAKE = 3;};	}" > out/android/os/Build.java
     30 echo "package android.os; public class UserHandle {public static String myUserId() { return \"\"; } }" > out/android/os/UserHandle.java
     31 echo "package android.os; public class RemoteException extends Exception {}" > out/android/os/RemoteException.java
     32 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
     33 
     34 echo "package android.opengl; public abstract class EGLObjectHandle { public int getHandle() { return 0; } }" > out/android/opengl/EGLObjectHandle.java
     35 
     36 
     37 echo "package android.graphics;" > out/android/graphics/SurfaceTexture.java
     38 echo "public interface SurfaceTexture {}" >> out/android/graphics/SurfaceTexture.java
     39 echo "package android.view;" > out/android/view/SurfaceView.java
     40 echo "public interface SurfaceView { SurfaceHolder getHolder(); }" >> out/android/view/SurfaceView.java
     41 echo "package android.view;" > out/android/view/Surface.java
     42 echo "public interface Surface {}" >> out/android/view/Surface.java
     43 echo "package android.view;" > out/android/view/SurfaceHolder.java
     44 echo "public interface SurfaceHolder { Surface getSurface(); }" >> out/android/view/SurfaceHolder.java
     45 
     46 cp static/egl/*.java out/android/opengl/
     47 
     48 GLFILE=out/javax/microedition/khronos/opengles/GL.java
     49 cp stubs/jsr239/GLHeader.java-if $GLFILE
     50 
     51 GLGEN_FILES="CFunc.java CType.java CodeEmitter.java EGLCodeEmitter.java GenerateEGL.java GenerateGL.java GenerateGLES.java GLESCodeEmitter.java JFunc.java JniCodeEmitter.java JType.java Jsr239CodeEmitter.java ParameterChecker.java"
     52 
     53 pushd src > /dev/null
     54 javac ${GLGEN_FILES}
     55 JAVAC_RESULT=$?
     56 if [ $JAVAC_RESULT -ne 0 ]; then
     57     echo "Could not compile glgen."
     58     exit $JAVAC_RESULT
     59 fi
     60 popd > /dev/null
     61 
     62 echo "Generating JSR239-like APIs"
     63 java -classpath src GenerateGL -c specs/jsr239/glspec-1.0 \
     64                                   specs/jsr239/glspec-1.0ext \
     65                                   specs/jsr239/glspec-1.1 \
     66                                   specs/jsr239/glspec-1.1ext \
     67                                   specs/jsr239/glspec-1.1extpack \
     68                                   specs/jsr239/glspec-checks
     69 JAVA_RESULT=$?
     70 if [ $JAVA_RESULT -ne 0 ]; then
     71     echo "Could not run GenerateGL."
     72     exit $JAVA_RESULT
     73 fi
     74 
     75 echo "Generating static OpenGLES bindings"
     76 java -classpath src GenerateGLES
     77 JAVA_RESULT=$?
     78 if [ $JAVA_RESULT -ne 0 ]; then
     79     echo "Could not run GenerateGLES."
     80     exit $JAVA_RESULT
     81 fi
     82 
     83 echo "Generating static EGL bindings"
     84 java -classpath src GenerateEGL
     85 JAVA_RESULT=$?
     86 if [ $JAVA_RESULT -ne 0 ]; then
     87     echo "Could not run GenerateEGL."
     88     exit $JAVA_RESULT
     89 fi
     90 
     91 rm src/*.class
     92 
     93 pushd out > /dev/null
     94 mkdir classes
     95 javac -d classes    android/opengl/EGL14.java \
     96                     android/opengl/EGLExt.java \
     97                     com/google/android/gles_jni/GLImpl.java \
     98                     javax/microedition/khronos/opengles/GL10.java \
     99                     javax/microedition/khronos/opengles/GL10Ext.java \
    100                     javax/microedition/khronos/opengles/GL11.java \
    101                     javax/microedition/khronos/opengles/GL11Ext.java \
    102                     javax/microedition/khronos/opengles/GL11ExtensionPack.java \
    103                     android/opengl/GLES10.java \
    104                     android/opengl/GLES10Ext.java \
    105                     android/opengl/GLES11.java \
    106                     android/opengl/GLES11Ext.java \
    107                     android/opengl/GLES20.java \
    108                     android/opengl/GLES30.java \
    109                     android/opengl/GLES31.java \
    110                     android/opengl/GLES31Ext.java
    111 popd > /dev/null
    112 JAVA_RESULT=$?
    113 if [ $JAVA_RESULT -ne 0 ]; then
    114     echo "Could not compile generated classes."
    115     exit $JAVA_RESULT
    116 fi
    117 
    118 rm -rf generated
    119 mkdir -p generated/C
    120 cp out/com_google_android_gles_jni_GLImpl.cpp generated/C
    121 cp -r out/com generated
    122 cp -r out/javax generated
    123 
    124 cp out/android_opengl_*.cpp generated/C
    125 mkdir -p generated/android/opengl
    126 cp -r out/android/opengl generated/android
    127 
    128 rm -rf out
    129 KEEP_GENERATED=0
    130 SAID_PLEASE=0
    131 
    132 # compareGenerated destDir generatedDir file
    133 compareGenerated() {
    134     if cmp -s $1/$3 $2/$3 ; then
    135         echo "#    " $3 unchanged
    136     else
    137         echo "#    " $3 changed
    138         if [ $SAID_PLEASE == "0" ] ; then
    139             echo Please evaluate the following commands:
    140             echo
    141             SAID_PLEASE=1
    142         fi
    143         echo "    cp $2/$3 $1"
    144         echo "    (cd $1; git add $3)"
    145         KEEP_GENERATED=1
    146     fi
    147 }
    148 
    149 compareGenerated ../../../../base/core/jni generated/C com_google_android_gles_jni_GLImpl.cpp
    150 compareGenerated ../../../../base/opengl/java/com/google/android/gles_jni generated/com/google/android/gles_jni GLImpl.java
    151 
    152 for x in GL.java GL10.java GL10Ext.java GL11.java GL11Ext.java GL11ExtensionPack.java
    153 do
    154     compareGenerated ../../../../base/opengl/java/javax/microedition/khronos/opengles generated/javax/microedition/khronos/opengles $x
    155 done
    156 
    157 for x in EGL14 EGLExt GLES10 GLES10Ext GLES11 GLES11Ext GLES20 GLES30 GLES31 GLES31Ext
    158 do
    159     compareGenerated ../../../../base/opengl/java/android/opengl generated/android/opengl ${x}.java
    160     compareGenerated ../../../../base/core/jni generated/C android_opengl_${x}.cpp
    161 done
    162 
    163 for x in EGLConfig EGLContext EGLDisplay EGLObjectHandle EGLSurface
    164 do
    165     compareGenerated ../../../../base/opengl/java/android/opengl generated/android/opengl ${x}.java
    166 done
    167 
    168 if [ $KEEP_GENERATED == "0" ] ; then
    169     rm -rf generated
    170 fi
    171