summaryrefslogtreecommitdiff
path: root/src/lib/ector/gl/shader/gen_shaders.sh
blob: c0192c3a01b05223e65b8632f0cb71fcbeb7ca10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh

# This script will generate a C file containing all the shaders used by Evas

DIR=`dirname $0`

OUTPUT="$DIR/ector_gl_shaders.x"

# Skip generation if there is no diff (or no git)
if ! git rev-parse 2>> /dev/null >> /dev/null ; then exit 0 ; fi
if git diff --quiet --exit-code -- "$DIR"
then
  touch "$OUTPUT"
  exit 0
fi

exec 1<&-
exec 1>"$OUTPUT"

# Write header
printf "/* DO NOT MODIFY THIS FILE AS IT IS AUTO-GENERATED */\n"
printf "/* IF IT IS CHANGED PLEASE COMMIT THE CHANGES */\n\n"

for SHD in fragment vertex ; do
  m4 "$DIR/include.glsl" "$DIR/$SHD.glsl" > "$SHD.tmp"

  OIFS="$IFS"
  IFS=`printf '\n+'`
  IFS=${IFS%+}
  printf "static const char "$SHD"_glsl[] ="
  for LINE in `cat "$SHD.tmp"` ; do
      printf "\n   \"$LINE\\\n\""
  done
  printf ";\n\n"
  IFS="$OIFS"

  rm "$SHD.tmp"
done