summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 0d5ed468e16831418ff27d0f519356957f5ca40f (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
# Maintainer: Jiuyang Liu <liujiuyang1994@gmail.com>

# Follow the upstream of https://github.com/sifive/freedom-tools/blob/master/Makefile

_target=riscv-sifive-elf
pkgname=$_target-gcc-stage1
pkgver=9.1.0
pkgrel=1
pkgdesc='Cross compiler for 32-bit and 64-bit RISC-V'
arch=('x86_64')
url='https://gcc.gnu.org/'
license=('GPL' 'LGPL' 'FDL')
groups=('risc-v')
depends=("$_target-binutils" "libmpc")
options=('!emptydirs' '!strip')
makedepends=('python')
source=("https://gcc.gnu.org/pub/gcc/releases/gcc-$pkgver/gcc-$pkgver.tar.xz"
        "0001-SiFive-CLIC-patches-for-preemptible-and-stack-swappi.patch"
        "0002-Finish-CLIC-support-resolving-patch-merge-error-and-.patch"
        "0003-RISC-V-Add-short-forward-branch-optimization-for-sif.patch"
        "0004-Remove-libgloss.patch")
md5sums=('6069ae3737cf02bf2cb44a391ef0e937'
         'SKIP'
         'SKIP'
         'SKIP'
         'SKIP')

prepare() {
  # hack! - some configure tests for header files using "$CPP $CPPFLAGS"
  sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" \
    "$srcdir/gcc-$pkgver/"{libiberty,gcc}/configure

  rm -rf "$srcdir/gcc-build"
  mkdir "$srcdir/gcc-build"
  export GCC_MULTILIB="rv32e-ilp32e--c rv32em-ilp32e--c rv32eac-ilp32e-- rv32emac-ilp32e-- rv32i-ilp32--c rv32im-ilp32--c rv32iac-ilp32-- rv32imac-ilp32-- rv32imaf-ilp32f-- rv32imafc-ilp32f-rv32imafdc- rv32imafdc-ilp32d-- rv64imac-lp64-- rv64imafc-lp64f-rv64imafdc- rv64imafdc-lp64d--"
  IFS=$' '
  cd $srcdir/gcc-$pkgver/gcc/config/riscv/
  ./multilib-generator $GCC_MULTILIB > t-elf-multilib
  cd $srcdir/gcc-$pkgver
  echo "patch unmerged work from SiFive."
  patch --forward --strip=1 --input="${srcdir}/0001-SiFive-CLIC-patches-for-preemptible-and-stack-swappi.patch"
  patch --forward --strip=1 --input="${srcdir}/0002-Finish-CLIC-support-resolving-patch-merge-error-and-.patch"
  patch --forward --strip=1 --input="${srcdir}/0003-RISC-V-Add-short-forward-branch-optimization-for-sif.patch"
  patch --forward --strip=1 --input="${srcdir}/0004-Remove-libgloss.patch"
}

build() {
  cd gcc-build

  # https://github.com/sifive/freedom-tools/blob/master/Makefile#L274 include c and c++ support in stage1, I removed this.
  "$srcdir/gcc-$pkgver/configure" \
    --disable-libgomp \
    --disable-libmudflap \
    --disable-libquadmath \
    --disable-libssp \
    --disable-nls \
    --disable-shared \
    --disable-threads \
    --disable-tls \
    --enable-checking=yes \
    --enable-languages=c \
    --enable-multilib \
    --libexecdir=/usr/lib \
    --prefix=/usr \
    --target=$_target \
    --with-abi="ilp32" \
    --with-arch="rv32imac" \
    --with-bugurl='https://bugs.archlinux.org/' \
    --with-newlib \
    --with-pkgversion='Arch Repository' \
    --with-python-dir=share/gcc-riscv-sifive-elf \
    --with-sysroot=/usr/$_target \
    --with-system-zlib \
    CFLAGS="-O2" \
    CXXFLAGS="-O2" \
    CFLAGS_FOR_TARGET="-Os -mcmodel=medany" \
    CXXFLAGS_FOR_TARGET="-Os -mcmodel=medany"

  make
}

package() {
  make -C gcc-build DESTDIR="$pkgdir" install-gcc install-target-libgcc

  # Strip target binaries
  find "$pkgdir/usr/lib/gcc/$_target/" -type f \
    -and \( -name \*.a -or -name \*.o \) -exec $_target-objcopy \
    -R .comment -R .note -R .debug_info -R .debug_aranges -R .debug_pubnames \
    -R .debug_pubtypes -R .debug_abbrev -R .debug_line -R .debug_str \
    -R .debug_ranges -R .debug_loc '{}' \;

  # Strip host binaries
  find "$pkgdir/usr/bin/" "$pkgdir/usr/lib/gcc/$_target/" -type f \
    -and \( -executable \) -exec strip '{}' \;
  # Remove files that conflict with host gcc package
  rm -r "$pkgdir/usr/share/"{man/man7,info}
}