build-example.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash -eu
  2. # Copyright 2018 The Wuffs Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # https://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # ----------------
  16. # See build-all.sh for commentary.
  17. if [ ! -e release/c/wuffs-unsupported-snapshot.c ]; then
  18. echo "$0 should be run from the Wuffs root directory."
  19. exit 1
  20. fi
  21. CC=${CC:-gcc}
  22. CXX=${CXX:-g++}
  23. mkdir -p gen/bin
  24. sources=$@
  25. if [ $# -eq 0 ]; then
  26. sources=example/*
  27. fi
  28. for f in $sources; do
  29. f=${f%/}
  30. f=${f##*/}
  31. if [ -z $f ]; then
  32. continue
  33. fi
  34. if [ $f = crc32 ]; then
  35. echo "Building gen/bin/example-$f"
  36. # example/crc32 is unusual in that it's C++, not C.
  37. $CXX -O3 example/$f/*.cc -o gen/bin/example-$f
  38. elif [ $f = library ]; then
  39. # example/library is unusual in that it uses separately compiled libraries
  40. # (built by "wuffs genlib", e.g. by running build-all.sh) instead of
  41. # directly #include'ing Wuffs' .c files.
  42. if [ -e gen/lib/c/$CC-static/libwuffs.a ]; then
  43. echo "Building gen/bin/example-$f"
  44. $CC -O3 -static -I.. example/$f/*.c gen/lib/c/$CC-static/libwuffs.a -o gen/bin/example-$f
  45. else
  46. echo "Skipping gen/bin/example-$f; run \"wuffs genlib\" first"
  47. fi
  48. elif [ -e example/$f/*.c ]; then
  49. echo "Building gen/bin/example-$f"
  50. $CC -O3 example/$f/*.c -o gen/bin/example-$f
  51. fi
  52. done