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