#!/bin/bash -ux
cd "$(dirname "$0")"

base=../src/
gles=$(ls -1 yml/*-1.1.yml | tr '\n' ',' | sed -e 's/,$//')
gles2=$(ls -1 yml/*-2.0.yml | tr '\n' ',' | sed -e 's/,$//')

./gen.py "$gles" --ifndef USE_ES2 gleswrap.c.j2 gleswrap.c gles.h > "$base/gl/wrap/gles.c" &
./gen.py "$gles" --ifndef USE_ES2 glwrap.h.j2 gleswrap.h ../gl.h > "$base/gl/wrap/gles.h" &
./gen.py "$gles" --ifndef USE_ES2 glxfuncs.j2 glxfuncs.inc ../gl/gl.h > "$base/glx/glesfuncs.inc" &

./gen.py "$gles2" --ifdef USE_ES2 gleswrap.c.j2 gles2wrap.c gles2.h > "$base/gl/wrap/gles2.c" &
./gen.py "$gles2" --ifdef USE_ES2 glwrap.h.j2 gles2wrap.h ../gl.h > "$base/gl/wrap/gles2.h" &
./gen.py "$gles2" --ifdef USE_ES2 glxfuncs.j2 gles2funcs.inc ../gl/gl.h > "$base/glx/gles2funcs.inc" &

# ./gen.py "yml/egl.yml" eglwrap.c.j2 eglwrap.c "<GLES/egl.h>" > "$base/gl/wrap/egl.c" &

cats="VERSION_1_0,VERSION_1_1,VERSION_1_2,VERSION_1_3,VERSION_1_4,VERSION_1_5,glx"
proxy='yml/opengl.yml,yml/my_glx.yml,yml/glxext.yml,yml/alsa.yml'
./gen.py --deep --cats "$cats" "$proxy" proxy.h.j2 proxy.h "<GL/gl.h>" "<GL/glx.h>" "<stdlib.h>" "<alsa/asoundlib.h>" "../gl/defines.h" "../config.h" "config.h" > "$base/proxy/proxy.h" &
./gen.py --deep --cats "$cats" "$proxy" client.c.j2 client.c "../proxy.h" > "$base/proxy/client/src/client.c" &
./gen.py --deep --cats "$cats" "$proxy" host.c.j2 host.c "../proxy.h" > "$base/proxy/host/host.c" &
wait
