summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: a56c0e8f432ef0716b000533dd01f37a6df25648 (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
# Maintainer: Pellegrino Prevete <pellegrinoprevete@gmail.com>

# shellcheck disable=SC2034
target="mips64r5900el-ps2-elf"
_module="ee"
_platform="ps2"
_base="toolchain"
pkgname=("${target}-newlib-nano")
pkgver="v4.1.0"
pkgrel=1
pkgdesc="A C library intended for use on embedded systems (${target}, nano version)"
arch=('x86_64')
license=('BSD')
_github="https://github.com/ps2dev"
_local="ssh://git@127.0.0.1:/home/git"
url="${_github}/${_platform}${_base}-${_module}"
makedepends=("${target}-gcc")
optdepends=()
_branch="${_module}-${pkgver}"
_commit="6b90d31371ff4e0f41d64d7539038864899a6b40"
source=("${target}-newlib::git+${_github}/newlib#commit=${_commit}")
# source=("${target}-newlib::git+${_local}/${_platform}-newlib#commit=${_branch}")
sha256sums=('SKIP')

_n_cpu="$(getconf _NPROCESSORS_ONLN)"
_make_opts=(-j "${_n_cpu}")

cflags=(-static
        -Wno-implicit-function-declaration)

ldflags=(${LDFLAGS}
         -Bstatic
         -s)

# shellcheck disable=SC2154
build() {
  local _target
  CFLAGS=""
  CXXFLAGS=""
  CPPFLAGS=""
  LDFLAGS=""
  export CFLAGS
  export CXXFLAGS
  export CPPFLAGS
  export LDFLAGS

  local _cflags=(${cflags[@]})
                 # -O2
                 # -D_FORTIFY_SOURCE=0)

  local _ldflags=(${ldflags[@]})
                  # -ldl)

  local _build_opts=(${_make_opts[@]}
                     CFLAGS="${_cflags[*]}"
                     CPPFLAGS="${_cflags[*]}"
                     LDFLAGS="${_ldflags[*]}")

  cd "${srcdir}/${target}-newlib"

  for _target in "${target}"; do
    rm -rf "build-${_target}"
    mkdir -p "build-${_target}"
    cd "build-${_target}"
    local _configure_opts=(--prefix="/usr"
                           --target="${_target}"
                           --includedir="/usr/include/newlib-nano"
                           --disable-newlib-supplied-syscall
                           --enable-newlib-reent-small
                           --disable-newlib-fvwrite-in-streamio
                           --disable-newlib-fseek-optimization
                           --disable-newlib-wide-orient
                           --disable-newlib-nano-malloc
                           --disable-newlib-unbuf-stream-opt
                           --enable-lite-exit
                           --enable-newlib-global-atexit
                           --enable-newlib-nano-formatted-io
                           --disable-nls)

    # CFLAGS_FOR_TARGET="-02" \
    CFLAGS_FOR_TARGET="-DPREFER_SIZE_OVER_SPEED=1 -Os" \
    CFLAGS="${_cflags[*]}" \
    "../configure" "${_configure_opts[@]}"

    make "${_build_opts[@]}" all

    cd ..
  done
}

# shellcheck disable=SC2154
package() {
  local _target
  local _include="${pkgdir}/usr/${target}/include/newlib-nano"
  local _lib="${pkgdir}/usr/${target}/lib/newlib-nano"
  local _oldpwd
  mkdir -p "${pkgdir}/newlib-include"
  mkdir -p "${pkgdir}/newlib-lib"
  cd "${srcdir}/${target}-newlib"
  for _target in "mips64r5900el-ps2-elf"; do
    cd "build-${_target}"
    _oldpwd=$(pwd)
    make DESTDIR="${pkgdir}" ${_make_opts[@]} install-strip
    cd "${pkgdir}/usr/${_target}/lib"
    mv libc.a libc_nano.a
    mv libg.a libg_nano.a
    mv libm.a libm_nano.a
    cd "${_oldpwd}"
    mv "${pkgdir}/usr/${target}/include/"* "${pkgdir}/newlib-include"
    mkdir -p "${_include}"
    mv "${pkgdir}/newlib-include/"* "${_include}"
    mv "${pkgdir}/usr/${target}/lib/"* "${pkgdir}/newlib-lib"
    mkdir -p "${_lib}"
    mkdir -p "${pkgdir}/usr/lib/"
    mv "${pkgdir}/newlib-lib/"* "${_lib}"
     
    cd "${pkgdir}/usr/${_target}/lib"
    ln -s "/usr/${_target}/lib/newlib-nano/libc_nano.a" libc_nano.a
    ln -s "/usr/${_target}/lib/newlib-nano/libg_nano.a" libg_nano.a
    ln -s "/usr/${_target}/lib/newlib-nano/libm_nano.a" libm_nano.a
    cd ..
  done
  rm -rf "${pkgdir}/newlib-include" # "${pkgdir}/newlib-lib"
}