aboutsummaryrefslogtreecommitdiffstats
path: root/dist/travis/build.sh
blob: 59438ff5629cfdf076e037ae6ee112a12afaf354 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#! /bin/bash

scriptdir=$(dirname $0)

. "$scriptdir/utils.sh"
disable_color

echo "$0" "$@"

# Stop in case of error
set -e

# Transform long options to short ones
for arg in "$@"; do
  shift
  case "$arg" in
      "--color"|"-color")   set -- "$@" "-c";;
      "--build"|"-build")   set -- "$@" "-b";;
      "--pkg"|"-pkg")       set -- "$@" "-p";;
      "--gpl"|"-gpl")       set -- "$@" "-g";;
      "--synth"|"-synth")   set -- "$@" "-s";;
    *) set -- "$@" "$arg"
  esac
done
# Parse args
while getopts ":b:p:cgs" opt; do
  case $opt in
    c) enable_color;;
    b) BLD=$OPTARG ;;
    p) PKG_NAME=$OPTARG;;
    g) ISGPL=true;;
    s) ISSYNTH=true;;
    \?) printf "$ANSI_RED[GHDL - build] Invalid option: -$OPTARG $ANSI_NOCOLOR\n" >&2
        exit 1 ;;
    :)  printf "$ANSI_RED[GHDL - build] Option -$OPTARG requires an argument. $ANSI_NOCOLOR\n" >&2
        exit 1 ;;
  esac
done

rm -f build_ok

#--- Env

travis_start "env.docker" "$ANSI_YELLOW[Info] Environment $ANSI_NOCOLOR"
env
travis_finish "env.docker"

#--- GPL: gpl-ize sources

if [ "$ISGPL" = "true" ]; then
    travis_start "gpl.src" "$ANSI_YELLOW[Source] create GPL sources $ANSI_NOCOLOR"
    files=`echo *`
    make -f Makefile.in srcdir=. clean-pure-gpl
    mkdir ${PKG_NAME}
    cp -pdrl $files ${PKG_NAME}
    tar -zcf "${PKG_NAME}.tar.gz" ${PKG_NAME}
    PKG_NAME="${PKG_NAME}-${BLD}"
    travis_finish "gpl.src"
fi

#--- Configure

travis_start "configure" "$ANSI_YELLOW[GHDL - build] Configure $ANSI_NOCOLOR" -notime

CDIR=$(pwd)
export prefix="$CDIR/install-$BLD"
mkdir "$prefix"
mkdir "build-$BLD"
cd "build-$BLD"

if [ "x$ISSYNTH" = "xtrue" ]; then
  CONFIG_OPTS+=" --enable-synth"
fi

case "$BLD" in
    gcc*)
        travis_start "get_gcc" "$ANSI_YELLOW[GHDL] Get gcc sources $ANSI_NOCOLOR"
        echo "https://github.com/gcc-mirror/gcc/archive/$(echo ${BLD} | sed -e 's/\./_/g')-release.tar.gz"
        mkdir gcc-srcs
        curl -L "https://github.com/gcc-mirror/gcc/archive/$(echo ${BLD} | sed -e 's/\./_/g')-release.tar.gz" | tar -xz -C gcc-srcs --strip-components=1
        cd gcc-srcs
        sed -i.bak s/ftp:/http:/g ./contrib/download_prerequisites
        ./contrib/download_prerequisites
        cd ..
        travis_finish "get_gcc"

        travis_start "configure_gcc" "$ANSI_YELLOW[GHDL] Configure gcc $ANSI_NOCOLOR"
        ../configure --with-gcc=gcc-srcs --prefix="$prefix"
        make copy-sources
        mkdir gcc-objs; cd gcc-objs
        ../gcc-srcs/configure --prefix="$prefix" --enable-languages=c,vhdl --disable-bootstrap --disable-lto --disable-multilib --disable-libssp --disable-libgomp --disable-libquadmath "`gcc -v 2>&1 | grep -o -- --enable-default-pie`"
        travis_finish "configure_gcc"
    ;;
    mcode)
        CXX=""
    ;;
    llvm)
        CXX="clang"
        CONFIG_OPTS+=" --with-llvm-config CXX=$CXX"
    ;;
    llvm-3.5)
        CXX="clang++"
        CONFIG_OPTS+=" --with-llvm-config=llvm-config-3.5 CXX=$CXX"
    ;;
    llvm-*)
        llvmver=$(echo $BLD | sed -e "s/llvm-//")
        CXX="clang++-$llvmver"
        CONFIG_OPTS+=" --with-llvm-config=llvm-config-$llvmver CXX=$CXX"
    ;;
    *)
        echo "$ANSI_RED[GHDL - build] Unknown build $BLD $ANSI_NOCOLOR"
        exit 1;;
esac

if [ ! "$(echo $BLD | grep gcc)" ]; then
    echo "../configure --prefix=$prefix $CONFIG_OPTS"
    ../configure "--prefix=$prefix" $CONFIG_OPTS
fi

travis_finish "configure" -notime

#--- make

travis_start "make" "$ANSI_YELLOW[GHDL - build] Make $ANSI_NOCOLOR"
set +e
make LIB_CFLAGS="$LIB_CFLAGS" OPT_FLAGS="$OPT_FLAGS" -j$(nproc) 2>make_err.log
tail -1000 make_err.log
set -e
travis_finish "make"

travis_start "install" "$ANSI_YELLOW[GHDL - build] Install $ANSI_NOCOLOR"
make install
cd ..
travis_finish "install"

if [ "$(echo $BLD | grep gcc)" ]; then
    travis_start "make_ghdllib" "$ANSI_YELLOW[GHDL - build] Make ghdllib $ANSI_NOCOLOR"
    make ghdllib
    travis_finish "make_ghdllib"

    travis_start "install_ghdllib" "$ANSI_YELLOW[GHDL - build] Install ghdllib $ANSI_NOCOLOR"
    make install
    cd ..
    travis_finish "install_ghdllib"
fi

#--- package

travis_start "tar.bin" "$ANSI_YELLOW[GHDL - build] Create package ${ANSI_DARKCYAN}${PKG_NAME}.tgz $ANSI_NOCOLOR"
tar -zcvf "${PKG_NAME}.tgz" -C "$prefix" .
travis_finish "tar.bin"

#--- build tools versions

{
    make --version | grep 'Make'
    gnatls --version | grep 'GNATLS'
    gcc --version | grep 'gcc'
    if [ "$CXX" != "" ]; then
        $CXX --version | grep 'clang'
    fi
} > BUILD_TOOLS

#---

echo "[SUCCESSFUL]"
touch build_ok