Debian Codegraph @

linux/build-toolchain-freebsd

raw
1 #!/bin/bash
2 #
3 # This file is part of nzbget. See <http://nzbget.net>.
4 #
5 # Copyright (C) 2015-2017 Andrey Prygunkov <[email protected]>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 # This script builds cross-compiling toolchain, which can compile NZBGet for FreeBSD.
22 # The toolchain itself runs on Linux.
23
24 # Setup strict bash error handling
25 set -o nounset
26 set -o errexit
27
28 # Uncomment next line for debuging
29 #set -x
30
31
32 TARGET="x86_64-pc-freebsd"
33
34 # FreeBSD
35 FREEBSDIMAGE_URL="https://download.freebsd.org/ftp/releases/amd64/10.1-RELEASE/base.txz"
36
37 # CLANG (must be already installed)
38 CLANG="clang-4.0"
39
40 # Libxml
41 LIBXML2_VERSION="2.9.2"
42 LIBXML2_ARCHIVE="libxml2-$LIBXML2_VERSION.tar.gz"
43 LIBXML2_URL="http://xmlsoft.org/sources/$LIBXML2_ARCHIVE"
44
45 # OpenSSL
46 OPENSSL_VERSION="1.0.2d"
47 OPENSSL_ARCHIVE="openssl-$OPENSSL_VERSION.tar.gz"
48 OPENSSL_URL="ftp://ftp.openssl.org/source/old/1.0.2/$OPENSSL_ARCHIVE"
49
50
51 ### START OF THE SCRIPT
52
53 ROOTDIR=`pwd`
54
55 rm -rf output
56 rm -rf sysroot
57
58 # Download all required tools
59 mkdir -p downloads
60 cd downloads
61 if [ ! -f base.txz ]; then
62 wget $FREEBSDIMAGE_URL
63 fi
64 if [ ! -f $LIBXML2_ARCHIVE ]; then
65 wget $LIBXML2_URL
66 fi
67 if [ ! -f $OPENSSL_ARCHIVE ]; then
68 wget $OPENSSL_URL
69 fi
70 cd ..
71
72 # Creating sysroot for FreeBSD from official FreeBSD installation image.
73 # Our sysroot contains only a small set of files needed to compile NZBGet and dependent libraries
74 mkdir -p sysroot
75 cd sysroot
76 tar xf ../downloads/base.txz \
77 ./lib \
78 ./usr/include \
79 ./usr/lib/crt1.o \
80 ./usr/lib/crtbegin.o \
81 ./usr/lib/crtbeginS.o \
82 ./usr/lib/crtbeginT.o \
83 ./usr/lib/crtend.o \
84 ./usr/lib/crtendS.o \
85 ./usr/lib/crti.o \
86 ./usr/lib/crtn.o \
87 ./usr/lib/libc++.a \
88 ./usr/lib/libc.a \
89 ./usr/lib/libcompiler_rt.a \
90 ./usr/lib/libgcc.a \
91 ./usr/lib/libgcc_eh.a \
92 ./usr/lib/libgcc_s.so \
93 ./usr/lib/libm.a \
94 ./usr/lib/libncurses.a \
95 ./usr/lib/libpthread.a \
96 ./usr/lib/libthr.a \
97 ./usr/lib/libz.a
98 # fix bad symlink
99 ln -s -f ../../lib/libgcc_s.so.1 usr/lib/libgcc_s.so
100 cd ..
101
102 mkdir -p output/build && cd output/build
103
104 # Unpack everything
105 tar xf ../../downloads/$LIBXML2_ARCHIVE
106 tar xf ../../downloads/$OPENSSL_ARCHIVE
107
108 # Build libxml2 (2 minutes)
109 cd libxml2-$LIBXML2_VERSION
110 CC="$CLANG" CFLAGS="--target=$TARGET --sysroot=$ROOTDIR/sysroot" LDFLAGS="-fuse-ld=lld -static --target=$TARGET --sysroot=$ROOTDIR/sysroot" ./configure --host=$TARGET --prefix=$ROOTDIR/output/staging/usr --disable-dependency-tracking --without-zlib --without-lzma --without-python --disable-shared
111 make -j2
112 make install
113 cd ..
114
115 # Build OpenSSL (5 minutes)
116 cd openssl-$OPENSSL_VERSION
117 CC="$CLANG --target=$TARGET --sysroot=$ROOTDIR/sysroot" LD="$CLANG -fuse-ld=lld --target=$TARGET --sysroot=$ROOTDIR/sysroot" ./Configure --prefix=$ROOTDIR/output/staging/usr no-shared no-dso no-hw no-zlib no-unit-test BSD-x86_64
118 make -j2
119 make install_sw
120 cd ..
121
122 cd ..
123
124 # Create missing package descriptions
125 echo "prefix=$ROOTDIR/output/staging/usr
126
127 Name: zlib
128 Description: zlib
129 Version: 1
130 Libs: -L\${prefix}/lib -lz
131 Cflags: -I\${prefix}/include
132 " > $ROOTDIR/output/staging/usr/lib/pkgconfig/zlib.pc
133
134 echo "prefix=$ROOTDIR/output/staging/usr
135
136 Name: ncurses
137 Description: ncurses
138 Version: 5
139 Libs: -L\${prefix}/lib -lncurses
140 Cflags: -I\${prefix}/include
141 " > $ROOTDIR/output/staging/usr/lib/pkgconfig/ncurses.pc
142
143 # Cleanup
144 rm -r staging/usr/bin
145 rm -r staging/usr/share
146 rm -r staging/usr/ssl
147