blob: b7a3a4be4db13ee462c896136fdb0696cb0f110f [file] [log] [blame]
Nigel Tao4c1826a2018-08-05 21:55:50 +10001#!/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 Tao04c91f12018-12-22 15:29:00 +110020if [ ! -e release/c/wuffs-unsupported-snapshot.c ]; then
Nigel Tao10ae7042018-08-18 12:13:36 +100021 echo "$0 should be run from the Wuffs root directory."
22 exit 1
23fi
24
Nigel Taob2d598a2018-12-26 12:38:15 +110025CC=${CC:-gcc}
26CXX=${CXX:-g++}
27
Nigel Tao10ae7042018-08-18 12:13:36 +100028mkdir -p gen/bin
29
30sources=$@
31if [ $# -eq 0 ]; then
32 sources=example/*
33fi
34
35for f in $sources; do
36 f=${f%/}
37 f=${f##*/}
38 if [ -z $f ]; then
39 continue
40 fi
41
Nigel Tao1b073492020-02-16 22:11:36 +110042 if [ $f = imageviewer ]; then
Nigel Tao8f1fe432020-01-15 14:22:48 +110043 # 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 Tao10ae7042018-08-18 12:13:36 +100046 elif [ $f = library ]; then
Nigel Tao4c1826a2018-08-05 21:55:50 +100047 # example/library is unusual in that it uses separately compiled libraries
Nigel Taofce79372018-08-05 22:36:37 +100048 # (built by "wuffs genlib", e.g. by running build-all.sh) instead of
49 # directly #include'ing Wuffs' .c files.
Nigel Taob2d598a2018-12-26 12:38:15 +110050 if [ -e gen/lib/c/$CC-static/libwuffs.a ]; then
Nigel Tao10ae7042018-08-18 12:13:36 +100051 echo "Building gen/bin/example-$f"
Nigel Taob2d598a2018-12-26 12:38:15 +110052 $CC -O3 -static -I.. example/$f/*.c gen/lib/c/$CC-static/libwuffs.a -o gen/bin/example-$f
Nigel Taofce79372018-08-05 22:36:37 +100053 else
Nigel Tao10ae7042018-08-18 12:13:36 +100054 echo "Skipping gen/bin/example-$f; run \"wuffs genlib\" first"
Nigel Taofce79372018-08-05 22:36:37 +100055 fi
Nigel Tao10ae7042018-08-18 12:13:36 +100056 elif [ -e example/$f/*.c ]; then
57 echo "Building gen/bin/example-$f"
Nigel Tao1b073492020-02-16 22:11:36 +110058 $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 Tao4c1826a2018-08-05 21:55:50 +100062 fi
63done