Files
linuxkit/alpine/base/c-compile/compile.sh
Justin Cormack d3abdc6252 Use docker run to compile C code not docker build
C version of #1006

Note that I switched all the C builds to use -O2 and that meant
that the compiler found some more warnings so I also fixed these
up. The possibly undefined ones were harmless, the aliasing one
is now more correct.

As these are small programs, the caching from `docker build` makes
no real difference, and worst case compile time is much better.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
2017-01-15 15:55:14 +00:00

57 lines
804 B
Bash
Executable File

#!/bin/sh
# This is designed to compile a single package to a single binary
# so it makes some assumptions about things to simplify config
# to output a single binary (in a tarball) just use -o file
# use --docker to output a tarball for input to docker build -
set -e
usage() {
echo "Usage: -o file"
exit 1
}
[ $# = 0 ] && usage
while [ $# -gt 0 ]
do
flag="$1"
case "$flag" in
-o)
[ $# -eq 1 ] && usage
out="$2"
mkdir -p "$(dirname $2)"
shift
;;
-l*)
LIBS="$LIBS $1"
shift
;;
*)
echo "Unknown option $1"
exit 1
esac
shift
done
[ -z "$out" ] && usage
package=$(basename "$out")
dir="/src/$package"
mkdir -p $dir
# untar input
tar xf - -C $dir
(
cd $dir
CFILES=$(find . -name '*.c')
cc -static -O2 -Wall -Werror -o ../../$out $CFILES $LIBS
)
tar cf - $out
exit 0