You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.9 KiB

golang_version := 1.12.7
golang_tarball := go$(golang_version).src.tar.gz
golang_tarball_path := src/$(golang_tarball)
golang_bin_tarball := go$(golang_version).linux-amd64.tar.gz
golang_bin_tarball_path := src/$(golang_bin_tarball)
build_dir := build/$(arch)
golang_bin_dir := $(build_dir)/go
golang_src_dir := $(build_dir)/go/src
golang_src_build_dir := $(build_dir)/target/src
prefix := $(arch)-linux-musl-
bin := $(build_dir)/target/bin/go
ifeq ($(arch), mipsel)
prefix := mipsel-linux-musln32-
go_arch := mipsle
else ifeq ($(arch), aarch64)
go_arch := arm64
else ifeq ($(arch), x86_64)
go_arch := amd64
endif
cc := $(prefix)gcc
cxx := $(prefix)g++
strip := $(prefix)strip
$(golang_bin_tarball_path):
wget https://dl.google.com/go/$(golang_bin_tarball) -O $(golang_bin_tarball_path)
$(golang_bin_dir): $(golang_bin_tarball_path)
mkdir -p $(build_dir)
cd $(build_dir) && tar xvf ../../$(golang_bin_tarball_path)
cd $(build_dir)/go && patch -p1 < ../../../set-external-linker.patch
touch $(golang_bin_dir)
$(golang_src_build_dir): $(golang_src_dir)
mkdir -p $(build_dir)/target
cp -r $(golang_src_dir) $(golang_src_build_dir)
$(bin): $(golang_bin_dir) $(golang_src_build_dir)
cd $(golang_src_build_dir) && \
GOROOT_BOOTSTRAP=`realpath ../../go` \
GOROOT_FINAL=/golang \
GOOS=linux \
GOARCH=$(go_arch) \
CC_FOR_TARGET=$(cc) \
CXX_FOR_TARGET=$(cxx) \
CC=x86_64-linux-musl-gcc \
CXX=x86_64-linux-musl-g++ \
LD=x86_64-linux-musl-ld \
GO_LDFLAGS="-buildmode=pie" \
CGO_ENABLED=1 \
./make.bash
# if [ "$(arch)" != "x86_64" ]; then \
# mv $(build_dir)/target/bin/*_*/* $(build_dir)/target/bin; \
# rm -rf $(build_dir)/target/bin/*_*; \
# rm -rf $(build_dir)/target/pkg/linux_amd64; \
# rm -rf $(build_dir)/target/pkg/tool/linux_amd64; \
# fi
# rm -rf $(build_dir)/target/pkg/obj
# rm -rf $(build_dir)/target/pkg/bootstrap
.PHONY: all clean
all: $(bin)
clean:
rm -rf build/$(arch)