Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 1 | #!/bin/sh |
Petr Vorel | 24519c1 | 2018-12-18 10:31:51 +0100 | [diff] [blame] | 2 | # Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz> |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 3 | # Script for travis builds. |
| 4 | # |
| 5 | # TODO: Implement comparison of installed files. List of installed files can |
| 6 | # be used only for local builds as Travis currently doesn't support sharing |
| 7 | # file between jobs, see |
| 8 | # https://github.com/travis-ci/travis-ci/issues/6054 |
| 9 | |
| 10 | set -e |
| 11 | |
Petr Vorel | 9039d44 | 2019-04-12 01:31:15 +0200 | [diff] [blame] | 12 | CFLAGS="${CFLAGS:--Werror=implicit-function-declaration}" |
| 13 | CC="${CC:-gcc}" |
| 14 | |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 15 | DEFAULT_PREFIX="$HOME/ltp-install" |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 16 | DEFAULT_BUILD="native" |
| 17 | DEFAULT_TREE="in" |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 18 | CONFIGURE_OPTS_IN_TREE="--with-open-posix-testsuite --with-realtime-testsuite" |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 19 | # TODO: open posix testsuite is currently broken in out-tree-build. Enable it once it's fixed. |
| 20 | CONFIGURE_OPTS_OUT_TREE="--with-realtime-testsuite" |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 21 | MAKE_OPTS="-j$(getconf _NPROCESSORS_ONLN)" |
| 22 | |
| 23 | build_32() |
| 24 | { |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 25 | echo "===== 32-bit ${1}-tree build into $PREFIX =====" |
Petr Vorel | dba3b82 | 2019-08-02 15:17:50 +0200 | [diff] [blame] | 26 | CFLAGS="-m32 $CFLAGS" LDFLAGS="-m32 $LDFLAGS" |
| 27 | build $1 |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | build_native() |
| 31 | { |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 32 | echo "===== native ${1}-tree build into $PREFIX =====" |
| 33 | build $1 |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 34 | } |
| 35 | |
Petr Vorel | 29a9e7a | 2017-12-14 19:03:48 +0100 | [diff] [blame] | 36 | build_cross() |
| 37 | { |
| 38 | local host="${CC%-gcc}" |
| 39 | [ -n "$host" ] || \ |
| 40 | { echo "Missing CC variable, pass it with -c option." >&2; exit 1; } |
| 41 | |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 42 | echo "===== cross-compile ${host} ${1}-tree build into $PREFIX =====" |
| 43 | build $1 "--host=$host" CROSS_COMPILE="${host}-" |
| 44 | } |
| 45 | |
| 46 | build() |
| 47 | { |
| 48 | local tree="$1" |
| 49 | shift |
| 50 | |
| 51 | echo "=== autotools ===" |
| 52 | make autotools |
| 53 | |
| 54 | if [ "$tree" = "in" ]; then |
| 55 | build_in_tree $@ |
| 56 | else |
| 57 | build_out_tree $@ |
| 58 | fi |
Petr Vorel | 29a9e7a | 2017-12-14 19:03:48 +0100 | [diff] [blame] | 59 | } |
| 60 | |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 61 | build_out_tree() |
| 62 | { |
| 63 | local tree="$PWD" |
| 64 | local build="$tree/../ltp-build" |
| 65 | local make_opts="$MAKE_OPTS -C $build -f $tree/Makefile top_srcdir=$tree top_builddir=$build" |
| 66 | |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 67 | mkdir -p $build |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 68 | cd $build |
Petr Vorel | dba3b82 | 2019-08-02 15:17:50 +0200 | [diff] [blame] | 69 | run_configure $tree/configure $CONFIGURE_OPTS_OUT_TREE $@ |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 70 | |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 71 | echo "=== build ===" |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 72 | make $make_opts |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 73 | |
| 74 | echo "=== install ===" |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 75 | make $make_opts DESTDIR="$PREFIX" SKIP_IDCHECK=1 install |
| 76 | } |
| 77 | |
| 78 | build_in_tree() |
| 79 | { |
Petr Vorel | dba3b82 | 2019-08-02 15:17:50 +0200 | [diff] [blame] | 80 | run_configure ./configure $CONFIGURE_OPTS_IN_TREE --prefix=$PREFIX $@ |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 81 | |
| 82 | echo "=== build ===" |
| 83 | make $MAKE_OPTS |
| 84 | |
| 85 | echo "=== install ===" |
| 86 | make $MAKE_OPTS install |
| 87 | } |
| 88 | |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 89 | run_configure() |
| 90 | { |
| 91 | local configure=$1 |
| 92 | shift |
| 93 | |
Petr Vorel | dba3b82 | 2019-08-02 15:17:50 +0200 | [diff] [blame] | 94 | export CC CFLAGS LDFLAGS |
| 95 | echo "CC='$CC' CFLAGS='$CFLAGS' LDFLAGS='$LDFLAGS'" |
| 96 | |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 97 | echo "=== configure $configure $@ ===" |
| 98 | if ! $configure $@; then |
| 99 | echo "== ERROR: configure failed, config.log ==" |
| 100 | cat config.log |
| 101 | exit 1 |
| 102 | fi |
| 103 | |
| 104 | echo "== include/config.h ==" |
| 105 | cat include/config.h |
| 106 | } |
| 107 | |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 108 | usage() |
| 109 | { |
| 110 | cat << EOF |
| 111 | Usage: |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 112 | $0 [ -c CC ] [ -o TREE ] [ -p DIR ] [ -t TYPE ] |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 113 | $0 -h |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 114 | |
| 115 | Options: |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 116 | -h Print this help |
| 117 | -c CC Define compiler (\$CC variable) |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 118 | -o TREE Specify build tree, default: $DEFAULT_TREE |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 119 | -p DIR Change installation directory. For in-tree build is this value passed |
| 120 | to --prefix option of configure script. For out-of-tree build is this |
| 121 | value passed to DESTDIR variable (i.e. sysroot) of make install |
| 122 | target, which means that LTP will be actually installed into |
| 123 | DIR/PREFIX (i.e. DIR/opt/ltp). |
| 124 | Default for in-tree build: '$DEFAULT_PREFIX' |
| 125 | Default for out-of-tree build: '$DEFAULT_PREFIX/opt/ltp' |
| 126 | -t TYPE Specify build type, default: $DEFAULT_BUILD |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 127 | |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 128 | BUILD TREE: |
| 129 | in in-tree build |
| 130 | out out-of-tree build |
| 131 | |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 132 | BUILD TYPES: |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 133 | 32 32-bit in-tree build |
Petr Vorel | 29a9e7a | 2017-12-14 19:03:48 +0100 | [diff] [blame] | 134 | cross cross-compile in-tree build (requires set compiler via -c switch) |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 135 | native native in-tree build |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 136 | EOF |
| 137 | } |
| 138 | |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 139 | PREFIX="$DEFAULT_PREFIX" |
| 140 | build="$DEFAULT_BUILD" |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 141 | tree="$DEFAULT_TREE" |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 142 | |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 143 | while getopts "c:ho:p:t:" opt; do |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 144 | case "$opt" in |
| 145 | c) CC="$OPTARG";; |
| 146 | h) usage; exit 0;; |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 147 | o) case "$OPTARG" in |
| 148 | in|out) tree="$OPTARG";; |
| 149 | *) echo "Wrong build tree '$OPTARG'" >&2; usage; exit 1;; |
| 150 | esac;; |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 151 | p) PREFIX="$OPTARG";; |
| 152 | t) case "$OPTARG" in |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 153 | 32|cross|native) build="$OPTARG";; |
Petr Vorel | 73e4ec4 | 2017-12-14 17:58:56 +0100 | [diff] [blame] | 154 | *) echo "Wrong build type '$OPTARG'" >&2; usage; exit 1;; |
| 155 | esac;; |
| 156 | ?) usage; exit 1;; |
| 157 | esac |
| 158 | done |
Petr Vorel | fa5b22d | 2017-10-04 12:22:58 +0200 | [diff] [blame] | 159 | |
| 160 | cd `dirname $0` |
Petr Vorel | 24519c1 | 2018-12-18 10:31:51 +0100 | [diff] [blame] | 161 | |
| 162 | echo "=== ver_linux ===" |
| 163 | ./ver_linux |
| 164 | echo |
| 165 | |
| 166 | echo "=== compiler version ===" |
| 167 | $CC --version |
| 168 | |
Petr Vorel | 612fd8b | 2018-01-26 19:34:20 +0100 | [diff] [blame] | 169 | eval build_$build $tree |