summaryrefslogtreecommitdiff
path: root/devel/go/MAKEPKG
blob: 8df72c0d9527d9e0c0290be3404b24c55e4a0051 (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
#!/bin/mkpkg
# description: The Go programming language compiler and tools
# url: https://go.dev/

# Note: Bootstrap binary (glibc-linked) is used only during build.
# The final toolchain is pure Go — static binaries, no libc dependency.
# linux/amd64 only — no cross-compilation support.

name=go
version=1.27.1
release=1
_bootver=1.26.6
depends=()
makedeps=()
source=(
    https://dl.google.com/go/go$version.src.tar.gz
    https://dl.google.com/go/go$_bootver.linux-amd64.tar.gz
)
renames=(
    $name-$version.src.tar.gz
    $name-boot-$_bootver.tar.gz
)
sha256sums=(
    "4e408abae126d916b6164627193f2c54f0e3ca1312d693b86db45f862ab238b1"
    "708effb774be8237570d0add163225abbdfaf4fca28b2611df167beba4feef89"
)

extract() {
    tar -xf $PKGMK_SOURCE_DIR/$name-$version.src.tar.gz -C $SRC
    mkdir -p $SRC/go-boot
    tar -xf $PKGMK_SOURCE_DIR/$name-boot-$_bootver.tar.gz -C $SRC/go-boot --strip-components=1
}

build() {
    export GOROOT_BOOTSTRAP=$SRC/go-boot
    export GOROOT_FINAL=/usr/lib/go
    export GOROOT=$SRC/go
    export GOBIN=$GOROOT/bin
    export GOPATH=$SRC/.go

    export CGO_ENABLED=0
    export GOOS=linux
    export GOARCH=amd64

    cd $SRC/go/src
    bash make.bash -v

    # Install GOROOT
    install -d $PKG/usr/lib/go

    # Binaries
    install -d $PKG/usr/lib/go/bin
    install -m755 $SRC/go/bin/go    $PKG/usr/lib/go/bin/
    install -m755 $SRC/go/bin/gofmt $PKG/usr/lib/go/bin/

    # Symlinks
    install -d $PKG/usr/bin
    ln -s /usr/lib/go/bin/go    $PKG/usr/bin/go
    ln -s /usr/lib/go/bin/gofmt $PKG/usr/bin/gofmt

    # VERSION file — Go needs this to know its own version
    cp $SRC/go/VERSION $PKG/usr/lib/go/

    # go.env
    install -m644 $SRC/go/go.env $PKG/usr/lib/go/

    # Toolchain binaries (compiler, linker, assembler, etc.)
    install -d $PKG/usr/lib/go/pkg/tool/linux_amd64
    cp -a $SRC/go/pkg/tool/linux_amd64/* $PKG/usr/lib/go/pkg/tool/linux_amd64/
    rm -f $PKG/usr/lib/go/pkg/tool/linux_amd64/api

    # Include headers (amd64 only)
    install -d $PKG/usr/lib/go/pkg/include
    install -m644 $SRC/go/pkg/include/asm_amd64.h  $PKG/usr/lib/go/pkg/include/
    install -m644 $SRC/go/pkg/include/funcdata.h    $PKG/usr/lib/go/pkg/include/
    install -m644 $SRC/go/pkg/include/textflag.h    $PKG/usr/lib/go/pkg/include/

    # Standard library source (required — Go compiles stdlib on demand)
    cp -a $SRC/go/src $PKG/usr/lib/go/

    # Timezone data (needed at runtime)
    install -d $PKG/usr/lib/go/lib/time
    cp $SRC/go/lib/time/zoneinfo.zip $PKG/usr/lib/go/lib/time/

    # --- Strip down for pkgtools ---

    # Remove src/cmd/ — precompiled tools are in pkg/tool/linux_amd64/
    rm -rf $PKG/usr/lib/go/src/cmd

    # Remove all test files
    find $PKG/usr/lib/go/src -name '*_test.go' -delete
    find $PKG/usr/lib/go/src -type d -name 'testdata' -exec rm -rf {} + 2>/dev/null || true

    # Remove non-linux OS source files
    find $PKG/usr/lib/go/src \( \
        -name '*_windows.*' -o \
        -name '*_darwin.*' -o \
        -name '*_freebsd.*' -o \
        -name '*_openbsd.*' -o \
        -name '*_netbsd.*' -o \
        -name '*_plan9.*' -o \
        -name '*_aix.*' -o \
        -name '*_solaris.*' -o \
        -name '*_illumos.*' -o \
        -name '*_dragonfly.*' -o \
        -name '*_hurd.*' -o \
        -name '*_js.*' -o \
        -name '*_wasip1.*' -o \
        -name '*_wasip2.*' -o \
        -name '*_ios.*' -o \
        -name '*_android.*' -o \
        -name '*_zos.*' \
    \) -delete

    # Remove non-amd64 arch source files
    find $PKG/usr/lib/go/src \( \
        -name '*_arm.*' -o \
        -name '*_arm64.*' -o \
        -name '*_mips.*' -o \
        -name '*_mips64.*' -o \
        -name '*_mips64x.*' -o \
        -name '*_mipsx.*' -o \
        -name '*_ppc64.*' -o \
        -name '*_ppc64x.*' -o \
        -name '*_ppc64le.*' -o \
        -name '*_riscv64.*' -o \
        -name '*_s390x.*' -o \
        -name '*_wasm.*' -o \
        -name '*_386.*' -o \
        -name '*_loong64.*' \
    \) -delete

    # Remove Solaris-only vendored package
    rm -rf $PKG/usr/lib/go/src/vendor/golang.org/x/net/lif

    # Remove Windows/Plan9 build scripts (keep bash — needed at runtime)
    find $PKG/usr/lib/go/src -maxdepth 1 \( -name '*.bat' -o -name '*.rc' \) -delete

    # Remove empty directories
    find $PKG/usr/lib/go/src -type d -empty -delete 2>/dev/null || true
}

signify() {
    untrusted comment: public key
    RWTZ9IduCSQ/mL8337TEUinPwT92xFEUpD92hkS7IxcOnzTt9QdpohT3
}

# vim: filetype=sh