Merge pull request #71 from henrydcase/dev/package_prep_makefile

Makefile improvement
This commit is contained in:
Henry Case 2018-03-13 05:28:31 +00:00 committed by GitHub
commit 03db2e7d58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 21 deletions

View File

@ -1,27 +1,58 @@
# Constants
MK_FILE_PATH = $(lastword $(MAKEFILE_LIST))
PRJ_DIR = $(abspath $(dir $(MK_FILE_PATH))/..)
DEV_DIR = $(PRJ_DIR)/_dev
# Results will be produced in this directory (can be provided by a caller)
BUILD_DIR ?= $(PRJ_DIR)/_dev/GOROOT
# Compiler
GO ?= go GO ?= go
GOENV := $(shell $(GO) env GOHOSTOS)_$(shell $(GO) env GOHOSTARCH)
GOROOTINFO := $(shell $(GO) version | cut -d' ' -f 3)_$(GOENV)
.PHONY: GOROOT # Build environment
GOROOT: GOROOT/$(GOENV)/.ok_$(GOROOTINFO) OS ?= $(shell $(GO) env GOHOSTOS)
@rm -f GOROOT/$(GOENV)/pkg/*/crypto/tls.a ARCH ?= $(shell $(GO) env GOHOSTARCH)
OS_ARCH := $(OS)_$(ARCH)
VER_OS_ARCH := $(shell $(GO) version | cut -d' ' -f 3)_$(OS)_$(ARCH)
GOROOT_ENV := $(shell $(GO) env GOROOT)
GOROOT_LOCAL = $(BUILD_DIR)/$(OS_ARCH)
# Flag indicates wheter invoke "go install -race std". Supported only on amd64 with CGO enabled
INSTALL_RACE:= $(words $(filter $(ARCH)_$(shell go env CGO_ENABLED), amd64_1))
GOROOT/$(GOENV)/.ok_$(GOROOTINFO): # TODO: I'm not sure why we would remove it at the end
$(eval GOROOT := $(CURDIR)/GOROOT/$(GOENV)) # but I comment this code as tls.a is exactly what
rm -rf "$(GOROOT)" # I try to build here
mkdir -p "$(GOROOT)/pkg" #GOROOT: GOROOT/$(OS_ARCH)/.ok_$(VER_OS_ARCH)
cp -r "$(shell $(GO) env GOROOT)/src" "$(GOROOT)/src" # rm -f GOROOT/$(OS_ARCH)/pkg/*/crypto/tls.a
cp -r "$(shell $(GO) env GOROOT)/pkg/include" "$(GOROOT)/pkg/include"
cp -r "$(shell $(GO) env GOROOT)/pkg/tool" "$(GOROOT)/pkg/tool" $(BUILD_DIR)/$(OS_ARCH)/.ok_$(VER_OS_ARCH): clean
rm -r "$(GOROOT)/src/crypto/tls"
ln -s ../../../../.. "$(GOROOT)/src/crypto/tls" # Create clean directory structure
for p in $(wildcard $(CURDIR)/patches/*); do patch -d "$(GOROOT)" -p1 < "$$p"; done mkdir -p "$(GOROOT_LOCAL)/pkg"
GOROOT="$(GOROOT)" $(GO) install -v std
ifeq ($(shell go env CGO_ENABLED),1) # Copy src/tools from system GOROOT
GOROOT="$(GOROOT)" $(GO) install -race -v std cp -r $(GOROOT_ENV)/src $(GOROOT_LOCAL)/src
cp -r $(GOROOT_ENV)/pkg/include $(GOROOT_LOCAL)/pkg/include
cp -r $(GOROOT_ENV)/pkg/tool $(GOROOT_LOCAL)/pkg/tool
# Swap TLS implementation
rm -r $(GOROOT_LOCAL)/src/crypto/tls/*
rsync -a $(PRJ_DIR)/ $(GOROOT_LOCAL)/src/crypto/tls/ --exclude=$(lastword $(subst /, ,$(DEV_DIR)))
# Apply additional patches
for p in $(wildcard $(DEV_DIR)/patches/*); do patch -d "$(GOROOT_LOCAL)" -p1 < "$$p"; done
# Create go package
GOARCH=$(ARCH) GOROOT="$(GOROOT_LOCAL)" $(GO) install -v std
ifeq ($(INSTALL_RACE),1)
GOARCH=$(ARCH) GOROOT="$(GOROOT_LOCAL)" $(GO) install -race -v std
endif endif
@touch "$@" @touch "$@"
.PHONY: clean
clean: clean:
rm -rf GOROOT go rm -rf $(BUILD_DIR)/$(OS_ARCH)
clean-all:
rm -rf $(BUILD_DIR)
# PHONY targets
.PHONY: $(BUILD_DIR) clean

View File

@ -5,6 +5,7 @@ RUN apk add --update \
make \ make \
bash \ bash \
patch \ patch \
rsync \
&& rm -rf /var/cache/apk/* && rm -rf /var/cache/apk/*
ENV CGO_ENABLED=0 ENV CGO_ENABLED=0

View File

@ -4,7 +4,7 @@ set -e
BASEDIR=$(cd "$(dirname "$0")" && pwd) BASEDIR=$(cd "$(dirname "$0")" && pwd)
GOENV="$(go env GOHOSTOS)_$(go env GOHOSTARCH)" GOENV="$(go env GOHOSTOS)_$(go env GOHOSTARCH)"
make --quiet -C "$BASEDIR" GOROOT >&2 BUILD_DIR=${BASEDIR}/GOROOT make -f $BASEDIR/Makefile >&2
export GOROOT="$BASEDIR/GOROOT/$GOENV" export GOROOT="$BASEDIR/GOROOT/$GOENV"
exec go "$@" exec go "$@"