Nigel Tao | 4c1826a | 2018-08-05 21:55:50 +1000 | [diff] [blame] | 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 | # ---------------- |
| 17 | |
| 18 | # See build-all.sh for commentary. |
| 19 | |
Nigel Tao | 04c91f1 | 2018-12-22 15:29:00 +1100 | [diff] [blame] | 20 | if [ ! -e release/c/wuffs-unsupported-snapshot.c ]; then |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 21 | echo "$0 should be run from the Wuffs root directory." |
| 22 | exit 1 |
| 23 | fi |
| 24 | |
Nigel Tao | b2d598a | 2018-12-26 12:38:15 +1100 | [diff] [blame] | 25 | CC=${CC:-gcc} |
| 26 | CXX=${CXX:-g++} |
| 27 | |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 28 | mkdir -p gen/bin |
| 29 | |
| 30 | sources=$@ |
| 31 | if [ $# -eq 0 ]; then |
| 32 | sources=example/* |
| 33 | fi |
| 34 | |
| 35 | for f in $sources; do |
| 36 | f=${f%/} |
| 37 | f=${f##*/} |
| 38 | if [ -z $f ]; then |
| 39 | continue |
| 40 | fi |
| 41 | |
Nigel Tao | 1b07349 | 2020-02-16 22:11:36 +1100 | [diff] [blame] | 42 | if [ $f = imageviewer ]; then |
Nigel Tao | 8f1fe43 | 2020-01-15 14:22:48 +1100 | [diff] [blame] | 43 | # example/imageviewer is unusual in that needs additional libraries. |
| 44 | echo "Building gen/bin/example-$f" |
| 45 | $CC -O3 example/$f/*.c -lxcb -lxcb-image -o gen/bin/example-$f |
Nigel Tao | cf8884d | 2020-08-05 11:55:01 +1000 | [diff] [blame] | 46 | elif [ $f = "toy-genlib" ]; then |
| 47 | # example/toy-genlib is unusual in that it uses separately compiled |
| 48 | # libraries (built by "wuffs genlib", e.g. by running build-all.sh) instead |
| 49 | # of directly #include'ing Wuffs' .c files. |
Nigel Tao | b2d598a | 2018-12-26 12:38:15 +1100 | [diff] [blame] | 50 | if [ -e gen/lib/c/$CC-static/libwuffs.a ]; then |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 51 | echo "Building gen/bin/example-$f" |
Nigel Tao | b2d598a | 2018-12-26 12:38:15 +1100 | [diff] [blame] | 52 | $CC -O3 -static -I.. example/$f/*.c gen/lib/c/$CC-static/libwuffs.a -o gen/bin/example-$f |
Nigel Tao | fce7937 | 2018-08-05 22:36:37 +1000 | [diff] [blame] | 53 | else |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 54 | echo "Skipping gen/bin/example-$f; run \"wuffs genlib\" first" |
Nigel Tao | fce7937 | 2018-08-05 22:36:37 +1000 | [diff] [blame] | 55 | fi |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 56 | elif [ -e example/$f/*.c ]; then |
| 57 | echo "Building gen/bin/example-$f" |
Nigel Tao | 1b07349 | 2020-02-16 22:11:36 +1100 | [diff] [blame] | 58 | $CC -O3 example/$f/*.c -o gen/bin/example-$f |
| 59 | elif [ -e example/$f/*.cc ]; then |
| 60 | echo "Building gen/bin/example-$f" |
| 61 | $CXX -O3 example/$f/*.cc -o gen/bin/example-$f |
Nigel Tao | 4c1826a | 2018-08-05 21:55:50 +1000 | [diff] [blame] | 62 | fi |
| 63 | done |