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 | eb67034 | 2021-10-07 14:59:13 +1100 | [diff] [blame] | 20 | if [ ! -e wuffs-root-directory.txt ]; 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++} |
Nigel Tao | 774340a | 2021-10-04 09:47:07 +1100 | [diff] [blame] | 27 | LDFLAGS=${LDFLAGS:-} |
Nigel Tao | b2d598a | 2018-12-26 12:38:15 +1100 | [diff] [blame] | 28 | |
Nigel Tao | ea4c85b | 2021-10-04 23:37:37 +1100 | [diff] [blame] | 29 | # The "-fdata-sections -ffunction-sections -Wl,--gc-sections" produces smaller |
| 30 | # binaries. See commit 41fce8a8 "Strip examples of unused data and functions". |
Nigel Tao | c27250f | 2022-10-28 17:14:32 +1100 | [diff] [blame] | 31 | CFLAGS=${CFLAGS:--O3 -fdata-sections -ffunction-sections -Wall -Wl,--gc-sections} |
| 32 | CXXFLAGS=${CXXFLAGS:--O3 -fdata-sections -ffunction-sections -Wall -Wl,--gc-sections} |
Nigel Tao | ea4c85b | 2021-10-04 23:37:37 +1100 | [diff] [blame] | 33 | |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 34 | mkdir -p gen/bin |
| 35 | |
| 36 | sources=$@ |
| 37 | if [ $# -eq 0 ]; then |
| 38 | sources=example/* |
| 39 | fi |
| 40 | |
| 41 | for f in $sources; do |
| 42 | f=${f%/} |
| 43 | f=${f##*/} |
| 44 | if [ -z $f ]; then |
| 45 | continue |
| 46 | fi |
| 47 | |
Nigel Tao | 1b07349 | 2020-02-16 22:11:36 +1100 | [diff] [blame] | 48 | if [ $f = imageviewer ]; then |
Nigel Tao | 8f1fe43 | 2020-01-15 14:22:48 +1100 | [diff] [blame] | 49 | # example/imageviewer is unusual in that needs additional libraries. |
Nigel Tao | 774340a | 2021-10-04 09:47:07 +1100 | [diff] [blame] | 50 | echo "Building (C++) gen/bin/example-$f" |
| 51 | $CXX $CXXFLAGS example/$f/*.cc \ |
| 52 | $LDFLAGS -lxcb -lxcb-image -lxcb-render -lxcb-render-util \ |
Nigel Tao | 68acf24 | 2021-10-03 13:59:09 +1100 | [diff] [blame] | 53 | -o gen/bin/example-$f |
Nigel Tao | 10850c1 | 2021-04-01 00:14:10 +1100 | [diff] [blame] | 54 | elif [ $f = "sdl-imageviewer" ]; then |
| 55 | # example/sdl-imageviewer is unusual in that needs additional libraries. |
Nigel Tao | 774340a | 2021-10-04 09:47:07 +1100 | [diff] [blame] | 56 | echo "Building (C++) gen/bin/example-$f" |
| 57 | $CXX $CXXFLAGS example/$f/*.cc \ |
| 58 | $LDFLAGS -lSDL2 -lSDL2_image \ |
Nigel Tao | 68acf24 | 2021-10-03 13:59:09 +1100 | [diff] [blame] | 59 | -o gen/bin/example-$f |
Nigel Tao | cf8884d | 2020-08-05 11:55:01 +1000 | [diff] [blame] | 60 | elif [ $f = "toy-genlib" ]; then |
| 61 | # example/toy-genlib is unusual in that it uses separately compiled |
| 62 | # libraries (built by "wuffs genlib", e.g. by running build-all.sh) instead |
| 63 | # of directly #include'ing Wuffs' .c files. |
Nigel Tao | b2d598a | 2018-12-26 12:38:15 +1100 | [diff] [blame] | 64 | if [ -e gen/lib/c/$CC-static/libwuffs.a ]; then |
Nigel Tao | 774340a | 2021-10-04 09:47:07 +1100 | [diff] [blame] | 65 | echo "Building (C) gen/bin/example-$f" |
| 66 | $CC $CFLAGS -static -I.. example/$f/*.c gen/lib/c/$CC-static/libwuffs.a \ |
| 67 | $LDFLAGS -o gen/bin/example-$f |
Nigel Tao | fce7937 | 2018-08-05 22:36:37 +1000 | [diff] [blame] | 68 | else |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 69 | echo "Skipping gen/bin/example-$f; run \"wuffs genlib\" first" |
Nigel Tao | fce7937 | 2018-08-05 22:36:37 +1000 | [diff] [blame] | 70 | fi |
Nigel Tao | 10ae704 | 2018-08-18 12:13:36 +1000 | [diff] [blame] | 71 | elif [ -e example/$f/*.c ]; then |
Nigel Tao | 774340a | 2021-10-04 09:47:07 +1100 | [diff] [blame] | 72 | echo "Building (C) gen/bin/example-$f" |
| 73 | $CC $CFLAGS example/$f/*.c $LDFLAGS -o gen/bin/example-$f |
Nigel Tao | 5396dbd | 2020-08-29 22:02:35 +1000 | [diff] [blame] | 74 | elif [ $f = "jsonfindptrs" ]; then |
Nigel Tao | 774340a | 2021-10-04 09:47:07 +1100 | [diff] [blame] | 75 | echo "Building (C++) gen/bin/example-$f" |
| 76 | $CXX $CXXFLAGS -std=c++17 example/$f/*.cc $LDFLAGS -o gen/bin/example-$f |
Nigel Tao | 1b07349 | 2020-02-16 22:11:36 +1100 | [diff] [blame] | 77 | elif [ -e example/$f/*.cc ]; then |
Nigel Tao | 774340a | 2021-10-04 09:47:07 +1100 | [diff] [blame] | 78 | echo "Building (C++) gen/bin/example-$f" |
| 79 | $CXX $CXXFLAGS example/$f/*.cc $LDFLAGS -o gen/bin/example-$f |
Nigel Tao | 4c1826a | 2018-08-05 21:55:50 +1000 | [diff] [blame] | 80 | fi |
| 81 | done |