summaryrefslogtreecommitdiff
path: root/bootstrap/bootstrap.sh
blob: 191bebc41215ed4af8704b000f07722f7f8cba6f (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/sh


## VERSIONS ##
# TODO move to a different package

LINUX_VER=5.16.11
BINUTILS_VER=2.38
MPFR_VER=4.1.0
MPC_VER=1.2.1
GMP_VER=6.2.1
GCC_VER=11.2.0
MUSL_VER=1.2.2
FILE_VER=5.41
TCL_VER=8.6.12
M4_VER=1.4.19
EXPECT_VER=5.45.4
DEJAGNU_VER=1.6.3
NCURSES_VER=6.3
BASH_VER=5.1.16
BISON_VER=3.8.2
BZIP2_VER=1.0.8
COREUTILS_VER=9.0
DIFFUTILS_VER=3.8
GAWK_VER=5.1.1
GETTEXT_VER=0.21
GREP_VER=3.7
GZIP_VER=1.11
MAKE_VER=4.3
PATCH_VER=2.7.6
SED_VER=4.8
PERL_VER=5.34.0
TEXINFO_VER=6.8
FLEX_VER=2.6.4
PERL_CROSS_VER=1.3.6
GETTEXT_TINY_VER=0.3.2
FINDUTILS_VER=4.9.0

####

CURL_OPTS="-SsL"

WD=$(pwd)/working

TARGET=x86_64-linux-musl
ARCH=x86
CPU=x86-64

CROSS_TOOLS=/cross-tools
TOOLS=/tools

PATH=${TOOLS}/bin:${CROSS_TOOLS}/bin:/usr/bin

MAKEFLAGS="-j$(nproc)"

export CHROOT TARGET PATH WD CURL_OPTS CROSS_TOOLS TOOLS MAKEFLAGS

unset CFLAGS CXXFLAGS

die () {
    printf "${RED}$@${RESET}\n"
    exit 1
}

extract () {
    FILE=$1
    case "${FILE##*.}" in 
        "gz" )
            tar -zxf $FILE
            ;;
        "lz" )
            tar --lzip -xf "$FILE"
            ;;
        "zip" )
            unzip $FILE
            ;;
        * )
            tar -xf $FILE
            ;;
    esac
}

src () {
    cd ${WD}
    local source=$1
    local filename=$(basename $source)
    printf "${LIGHT_BLUE}Fetching $filename...${RESET}\n"

    curl ${CURL_OPTS} $source > $filename
    extract $filename
    cd ${filename%.t*}
}

ptch () {
    local source=$1
    local filename=$(basename $source)

    printf "${LIGHT_BLUE}Patching $filename...${RESET}\n"
    curl ${CURL_OPTS} $source > $filename
    patch -Np1 -i $filename
}

clean () {
    rm -rf $WD $CROSS_TOOLS $TOOLS
    mkdir -pv $WD $CROSS_TOOLS $TOOL
}

patch_gcc () {
    local PATCH_SRC="https://raw.githubusercontent.com/dslm4515/Musl-LFS/master/patches/gcc-alpine"

    ptch $PATCH_SRC/0001-posix_memalign.patch &&
    ptch $PATCH_SRC/0003-Turn-on-Wl-z-relro-z-now-by-default.patch &&
    ptch $PATCH_SRC/0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch &&
    ptch $PATCH_SRC/0006-Enable-Wformat-and-Wformat-security-by-default.patch &&
    ptch $PATCH_SRC/0007-Enable-Wtrampolines-by-default.patch &&
    ptch $PATCH_SRC/0009-Ensure-that-msgfmt-doesn-t-encounter-problems-during.patch &&
    ptch $PATCH_SRC/0010-Don-t-declare-asprintf-if-defined-as-a-macro.patch &&
    ptch $PATCH_SRC/0011-libiberty-copy-PIC-objects-during-build-process.patch &&
    ptch $PATCH_SRC/0012-libitm-disable-FORTIFY.patch &&
    ptch $PATCH_SRC/0013-libgcc_s.patch &&
    ptch $PATCH_SRC/0014-nopie.patch &&
    ptch $PATCH_SRC/0015-libffi-use-__linux__-instead-of-__gnu_linux__-for-mu.patch &&
    ptch $PATCH_SRC/0016-dlang-update-zlib-binding.patch &&
    ptch $PATCH_SRC/0017-dlang-fix-fcntl-on-mips-add-libucontext-dep.patch &&
    ptch $PATCH_SRC/0018-ada-fix-shared-linking.patch &&
    ptch $PATCH_SRC/0019-build-fix-CXXFLAGS_FOR_BUILD-passing.patch &&
    ptch $PATCH_SRC/0020-add-fortify-headers-paths.patch &&
    ptch $PATCH_SRC/0023-Pure-64-bit-MIPS.patch &&
    ptch $PATCH_SRC/0024-use-pure-64-bit-configuration-where-appropriate.patch &&
    ptch $PATCH_SRC/0025-always-build-libgcc_eh.a.patch &&
    ptch $PATCH_SRC/0027-ada-musl-support-fixes.patch &&
    ptch $PATCH_SRC/0028-gcc-go-Use-_off_t-type-instead-of-_loff_t.patch &&
    ptch $PATCH_SRC/0029-gcc-go-Don-t-include-sys-user.h.patch &&
    ptch $PATCH_SRC/0030-gcc-go-Fix-ucontext_t-on-PPC64.patch &&
    ptch $PATCH_SRC/0031-gcc-go-Fix-handling-of-signal-34-on-musl.patch &&
    ptch $PATCH_SRC/0032-gcc-go-Use-int64-type-as-offset-argument-for-mmap.patch &&
    #ptch $PATCH_SRC/0034-gcc-go-signal-34-is-special-on-musl-libc  &&
    ptch $PATCH_SRC/0035-gcc-go-Prefer-_off_t-over-_off64_t.patch &&
    ptch $PATCH_SRC/0036-gcc-go-undef-SETCONTEXT_CLOBBERS_TLS-in-proc.c.patch &&
    ptch $PATCH_SRC/0037-gcc-go-link-to-libucontext.patch &&
    ptch $PATCH_SRC/0038-gcc-go-Disable-printing-of-unaccessible-ppc64-struct.patch &&
    ptch $PATCH_SRC/0041-Use-generic-errstr.go-implementation-on-musl.patch &&
    ptch $PATCH_SRC/0042-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch &&
    ptch $PATCH_SRC/0043-configure-Add-enable-autolink-libatomic-use-in-LINK_.patch 
    #ptch $PATCH_SRC/0022-DP-Use-push-state-pop-state-for-gold-as-well-when-li.patch &&
}

package_chroot () {
    PATH=/usr/bin:/bin
    local chroot=$(pwd)/chroot
    mkdir chroot
    xi -r ${chroot} bootstrap
    cp -r ${TOOLS} ${chroot}/tools
    ln -s /tools/bin/bash ${chroot}/bin/sh
    tar -C ${chroot} -czf chroot-tools.tar.gz ./
}

[ -f /usr/lib/colors.sh ] && . /usr/lib/colors.sh

rm -rf $WD ; mkdir $WD

# TODO bad impl
if [ "$#" = "0" ]; then
    clean
    $0 stage1
    $0 stage2
else
    case "$1" in
        stage1|cross|cross_tools)
            . ./cross_tools.sh
            ;;
        stage2|tools|toolchain)
            . ./toolchain.sh
            ;;
        package)
                package_chroot
            ;;
        *)
            clean
            $0 stage1
            $0 stage2
            ;;
    esac
fi