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                     android/opengl/GLES32.java
    112 popd > /dev/null
    113 JAVA_RESULT=$?
    114 if [ $JAVA_RESULT -ne 0 ]; then
    115     echo "Could not compile generated classes."
    116     exit $JAVA_RESULT
    117 fi
    118 
    119 rm -rf generated
    120 mkdir -p generated/C
    121 cp out/com_google_android_gles_jni_GLImpl.cpp generated/C
    122 cp -r out/com generated
    123 cp -r out/javax generated
    124 
    125 cp out/android_opengl_*.cpp generated/C
    126 mkdir -p generated/android/opengl
    127 cp -r out/android/opengl generated/android
    128 
    129 rm -rf out
    130 KEEP_GENERATED=0
    131 SAID_PLEASE=0
    132 
    133 # compareGenerated destDir generatedDir file
    134 compareGenerated() {
    135     if cmp -s $1/$3 $2/$3 ; then
    136         echo "#    " $3 unchanged
    137     else
    138         echo "#    " $3 changed
    139         if [ $SAID_PLEASE == "0" ] ; then
    140             echo Please evaluate the following commands:
    141             echo
    142             SAID_PLEASE=1
    143         fi
    144         echo "    cp $2/$3 $1"
    145         echo "    (cd $1; git add $3)"
    146         KEEP_GENERATED=1
    147     fi
    148 }
    149 
    150 compareGenerated ../../../../base/core/jni generated/C com_google_android_gles_jni_GLImpl.cpp
    151 compareGenerated ../../../../base/opengl/java/com/google/android/gles_jni generated/com/google/android/gles_jni GLImpl.java
    152 
    153 for x in GL.java GL10.java GL10Ext.java GL11.java GL11Ext.java GL11ExtensionPack.java
    154 do
    155     compareGenerated ../../../../base/opengl/java/javax/microedition/khronos/opengles generated/javax/microedition/khronos/opengles $x
    156 done
    157 
    158 for x in EGL14 EGLExt GLES10 GLES10Ext GLES11 GLES11Ext GLES20 GLES30 GLES31 GLES31Ext GLES32
    159 do
    160     compareGenerated ../../../../base/opengl/java/android/opengl generated/android/opengl ${x}.java
    161     compareGenerated ../../../../base/core/jni generated/C android_opengl_${x}.cpp
    162 done
    163 
    164 for x in EGLConfig EGLContext EGLDisplay EGLObjectHandle EGLSurface
    165 do
    166     compareGenerated ../../../../base/opengl/java/android/opengl generated/android/opengl ${x}.java
    167 done
    168 
    169 if [ $KEEP_GENERATED == "0" ] ; then
    170     rm -rf generated
    171 fi
    172