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