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/view
16mkdir -p out/android/opengl
17mkdir -p out/android/content
18mkdir -p out/android/content/pm
19mkdir -p out/android/os
20mkdir -p out/android/util
21
22echo "package android.graphics;" > out/android/graphics/Canvas.java
23echo "public interface Canvas {}" >> out/android/graphics/Canvas.java
24
25echo "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
27echo "package android.content.pm; public class ApplicationInfo {public int targetSdkVersion;}" > out/android/content/pm/ApplicationInfo.java
28echo "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
29echo "package android.os; public class Build {public static class VERSION_CODES { public static final int CUPCAKE = 3;};	}" > out/android/os/Build.java
30echo "package android.os; public class UserHandle {public static String myUserId() { return \"\"; } }" > out/android/os/UserHandle.java
31echo "package android.os; public class RemoteException extends Exception {}" > out/android/os/RemoteException.java
32echo "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
34echo "package android.opengl; public abstract class EGLObjectHandle { public int getHandle() { return 0; } }" > out/android/opengl/EGLObjectHandle.java
35
36
37echo "package android.graphics;" > out/android/graphics/SurfaceTexture.java
38echo "public interface SurfaceTexture {}" >> out/android/graphics/SurfaceTexture.java
39echo "package android.view;" > out/android/view/SurfaceView.java
40echo "public interface SurfaceView { SurfaceHolder getHolder(); }" >> out/android/view/SurfaceView.java
41echo "package android.view;" > out/android/view/Surface.java
42echo "public interface Surface {}" >> out/android/view/Surface.java
43echo "package android.view;" > out/android/view/SurfaceHolder.java
44echo "public interface SurfaceHolder { Surface getSurface(); }" >> out/android/view/SurfaceHolder.java
45
46cp static/egl/*.java out/android/opengl/
47
48GLFILE=out/javax/microedition/khronos/opengles/GL.java
49cp stubs/jsr239/GLHeader.java-if $GLFILE
50
51GLGEN_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
53pushd src > /dev/null
54javac ${GLGEN_FILES}
55JAVAC_RESULT=$?
56if [ $JAVAC_RESULT -ne 0 ]; then
57    echo "Could not compile glgen."
58    exit $JAVAC_RESULT
59fi
60popd > /dev/null
61
62echo "Generating JSR239-like APIs"
63java -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
69JAVA_RESULT=$?
70if [ $JAVA_RESULT -ne 0 ]; then
71    echo "Could not run GenerateGL."
72    exit $JAVA_RESULT
73fi
74
75echo "Generating static OpenGLES bindings"
76java -classpath src GenerateGLES
77JAVA_RESULT=$?
78if [ $JAVA_RESULT -ne 0 ]; then
79    echo "Could not run GenerateGLES."
80    exit $JAVA_RESULT
81fi
82
83echo "Generating static EGL bindings"
84java -classpath src GenerateEGL
85JAVA_RESULT=$?
86if [ $JAVA_RESULT -ne 0 ]; then
87    echo "Could not run GenerateEGL."
88    exit $JAVA_RESULT
89fi
90
91rm src/*.class
92
93pushd out > /dev/null
94mkdir classes
95javac -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
112popd > /dev/null
113JAVA_RESULT=$?
114if [ $JAVA_RESULT -ne 0 ]; then
115    echo "Could not compile generated classes."
116    exit $JAVA_RESULT
117fi
118
119rm -rf generated
120mkdir -p generated/C
121cp out/com_google_android_gles_jni_GLImpl.cpp generated/C
122cp -r out/com generated
123cp -r out/javax generated
124
125cp out/android_opengl_*.cpp generated/C
126mkdir -p generated/android/opengl
127cp -r out/android/opengl generated/android
128
129rm -rf out
130KEEP_GENERATED=0
131SAID_PLEASE=0
132
133# compareGenerated destDir generatedDir file
134compareGenerated() {
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
150compareGenerated ../../../../base/core/jni generated/C com_google_android_gles_jni_GLImpl.cpp
151compareGenerated ../../../../base/opengl/java/com/google/android/gles_jni generated/com/google/android/gles_jni GLImpl.java
152
153for x in GL.java GL10.java GL10Ext.java GL11.java GL11Ext.java GL11ExtensionPack.java
154do
155    compareGenerated ../../../../base/opengl/java/javax/microedition/khronos/opengles generated/javax/microedition/khronos/opengles $x
156done
157
158for x in EGL14 EGLExt GLES10 GLES10Ext GLES11 GLES11Ext GLES20 GLES30 GLES31 GLES31Ext GLES32
159do
160    compareGenerated ../../../../base/opengl/java/android/opengl generated/android/opengl ${x}.java
161    compareGenerated ../../../../base/core/jni generated/C android_opengl_${x}.cpp
162done
163
164for x in EGLConfig EGLContext EGLDisplay EGLObjectHandle EGLSurface
165do
166    compareGenerated ../../../../base/opengl/java/android/opengl generated/android/opengl ${x}.java
167done
168
169if [ $KEEP_GENERATED == "0" ] ; then
170    rm -rf generated
171fi
172