generated from gatewayd-io/plugin-template-go
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve Makefile by combining all build targets for different platforms into a single target * Inject version into the binary on build
- Loading branch information
Showing
2 changed files
with
36 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,51 @@ | ||
PROJECT_URL=github.com/gatewayd-io/gatewayd | ||
CONFIG_PACKAGE=${PROJECT_URL}/config | ||
PLUGIN_NAME=gatewayd-plugin-js | ||
PROJECT_URL=github.com/gatewayd-io/$(PLUGIN_NAME) | ||
CONFIG_PACKAGE=${PROJECT_URL}/plugin | ||
LAST_TAGGED_COMMIT=$(shell git rev-list --tags --max-count=1) | ||
VERSION=$(shell git describe --tags ${LAST_TAGGED_COMMIT}) | ||
TIMESTAMP=$(shell date -u +"%FT%T%z") | ||
VERSION_DETAILS=${TIMESTAMP}/${LAST_TAGGED_COMMIT_SHORT} | ||
EXTRA_LDFLAGS=-X ${CONFIG_PACKAGE}.Version=${VERSION} -X ${CONFIG_PACKAGE}.VersionDetails=${VERSION_DETAILS} | ||
FILES=gatewayd-plugin-js checksum.txt gatewayd_plugin.yaml README.md LICENSE | ||
EXTRA_LDFLAGS=-X ${CONFIG_PACKAGE}.Version=$(shell echo ${VERSION} | sed 's/^v//') | ||
FILES=$(PLUGIN_NAME) checksum.txt gatewayd_plugin.yaml README.md LICENSE | ||
|
||
tidy: | ||
@go mod tidy | ||
|
||
test: | ||
@go test -v ./... | ||
build: tidy | ||
@go build -ldflags "-s -w" | ||
|
||
checksum: | ||
@sha256sum -b gatewayd-plugin-js | ||
@sha256sum -b $(PLUGIN_NAME) | ||
|
||
update-all: | ||
@go get -u ./... | ||
@go mod tidy | ||
|
||
build-dev: tidy | ||
@CGO_ENABLED=0 go build | ||
@go build | ||
|
||
test: | ||
@go test -v ./... | ||
|
||
create-build-dir: | ||
@mkdir -p dist | ||
|
||
build-linux-amd64: tidy | ||
@echo "Building gatewayd ${VERSION} for linux-amd64" | ||
@mkdir -p dist/linux-amd64 | ||
@cp README.md LICENSE gatewayd_plugin.yaml ./dist/linux-amd64/ | ||
@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o dist/linux-amd64/gatewayd-plugin-js | ||
@sha256sum dist/linux-amd64/gatewayd-plugin-js | sed 's/dist\/linux-amd64\///g' >> dist/linux-amd64/checksum.txt | ||
@tar czf dist/gatewayd-plugin-js-linux-amd64-${VERSION}.tar.gz -C ./dist/linux-amd64/ ${FILES} | ||
@sha256sum dist/gatewayd-plugin-js-linux-amd64-${VERSION}.tar.gz | sed 's/dist\///g' >> dist/checksums.txt | ||
|
||
build-linux-arm64: | ||
@echo "Building gatewayd ${VERSION} for linux-arm64" | ||
@mkdir -p dist/linux-arm64 | ||
@cp README.md LICENSE gatewayd_plugin.yaml ./dist/linux-arm64/ | ||
@GOOS=linux GOARCH=arm64 CGO_ENABLED=0 CC=aarch64-linux-gnu-gcc go build -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o dist/linux-arm64/gatewayd-plugin-js | ||
@sha256sum dist/linux-arm64/gatewayd-plugin-js | sed 's/dist\/linux-arm64\///g' >> dist/linux-arm64/checksum.txt | ||
@tar czf dist/gatewayd-plugin-js-linux-arm64-${VERSION}.tar.gz -C ./dist/linux-arm64/ ${FILES} | ||
@sha256sum dist/gatewayd-plugin-js-linux-arm64-${VERSION}.tar.gz | sed 's/dist\///g' >> dist/checksums.txt | ||
|
||
build-darwin-amd64: | ||
@echo "Building gatewayd ${VERSION} for darwin-arm64" | ||
@mkdir -p dist/darwin-amd64 | ||
@cp README.md LICENSE gatewayd_plugin.yaml ./dist/darwin-amd64/ | ||
@GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o dist/darwin-amd64/gatewayd-plugin-js | ||
@shasum -a 256 dist/darwin-amd64/gatewayd-plugin-js | sed 's/dist\/darwin-amd64\///g' >> dist/darwin-amd64/checksum.txt | ||
@tar czf dist/gatewayd-plugin-js-darwin-amd64-${VERSION}.tar.gz -C ./dist/darwin-amd64/ ${FILES} | ||
@shasum -a 256 dist/gatewayd-plugin-js-darwin-amd64-${VERSION}.tar.gz | sed 's/dist\///g' >> dist/checksums.txt | ||
|
||
build-darwin-arm64: | ||
@echo "Building gatewayd ${VERSION} for darwin-arm64" | ||
@mkdir -p dist/darwin-arm64 | ||
@cp README.md LICENSE gatewayd_plugin.yaml ./dist/darwin-arm64/ | ||
@GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o dist/darwin-arm64/gatewayd-plugin-js | ||
@shasum -a 256 dist/darwin-arm64/gatewayd-plugin-js | sed 's/dist\/darwin-arm64\///g' >> dist/darwin-arm64/checksum.txt | ||
@tar czf dist/gatewayd-plugin-js-darwin-arm64-${VERSION}.tar.gz -C ./dist/darwin-arm64/ ${FILES} | ||
@shasum -a 256 dist/gatewayd-plugin-js-darwin-arm64-${VERSION}.tar.gz | sed 's/dist\///g' >> dist/checksums.txt | ||
|
||
build-windows-amd64: | ||
@echo "Building gatewayd ${VERSION} for windows-amd64" | ||
@mkdir -p dist/windows-amd64 | ||
@cp README.md LICENSE gatewayd_plugin.yaml ./dist/windows-amd64/ | ||
@GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o dist/windows-amd64/gatewayd-plugin-js.exe | ||
@sha256sum dist/windows-amd64/gatewayd-plugin-js.exe | sed 's/dist\/windows-amd64\///g' >> dist/windows-amd64/checksum.txt | ||
@zip -r dist/gatewayd-plugin-js-windows-amd64-${VERSION}.zip -j ./dist/windows-amd64/ | ||
@sha256sum dist/gatewayd-plugin-js-windows-amd64-${VERSION}.zip | sed 's/dist\///g' >> dist/checksums.txt | ||
|
||
build-windows-arm64: | ||
@echo "Building gatewayd ${VERSION} for windows-arm64" | ||
@mkdir -p dist/windows-arm64 | ||
@cp README.md LICENSE gatewayd_plugin.yaml ./dist/windows-arm64/ | ||
@GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o dist/windows-arm64/gatewayd-plugin-js.exe | ||
@sha256sum dist/windows-arm64/gatewayd-plugin-js.exe | sed 's/dist\/windows-arm64\///g' >> dist/windows-arm64/checksum.txt | ||
@zip -r dist/gatewayd-plugin-js-windows-arm64-${VERSION}.zip -j ./dist/windows-arm64/ | ||
@sha256sum dist/gatewayd-plugin-js-windows-arm64-${VERSION}.zip | sed 's/dist\///g' >> dist/checksums.txt | ||
|
||
build-release: tidy create-build-dir build-linux-amd64 build-linux-arm64 build-darwin-amd64 build-darwin-arm64 build-windows-amd64 build-windows-arm64 | ||
build-release: tidy create-build-dir | ||
@echo "Building ${PLUGIN_NAME} ${VERSION} for release" | ||
@$(MAKE) build-platform GOOS=linux GOARCH=amd64 OUTPUT_DIR=dist/linux-amd64 | ||
@$(MAKE) build-platform GOOS=linux GOARCH=arm64 OUTPUT_DIR=dist/linux-arm64 | ||
@$(MAKE) build-platform GOOS=darwin GOARCH=amd64 OUTPUT_DIR=dist/darwin-amd64 | ||
@$(MAKE) build-platform GOOS=darwin GOARCH=arm64 OUTPUT_DIR=dist/darwin-arm64 | ||
@$(MAKE) build-platform GOOS=windows GOARCH=amd64 OUTPUT_DIR=dist/windows-amd64 | ||
@$(MAKE) build-platform GOOS=windows GOARCH=arm64 OUTPUT_DIR=dist/windows-arm64 | ||
|
||
build-platform: tidy | ||
@echo "Building ${PLUGIN_NAME} ${VERSION} for $(GOOS)-$(GOARCH)" | ||
@mkdir -p $(OUTPUT_DIR) | ||
@cp README.md LICENSE gatewayd_plugin.yaml $(OUTPUT_DIR)/ | ||
@GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -trimpath -ldflags "-s -w ${EXTRA_LDFLAGS}" -o $(OUTPUT_DIR)/$(PLUGIN_NAME) | ||
@sha256sum $(OUTPUT_DIR)/$(PLUGIN_NAME) | sed 's#$(OUTPUT_DIR)/##g' >> $(OUTPUT_DIR)/checksum.txt | ||
@if [ "$(GOOS)" = "windows" ]; then \ | ||
zip -q -r dist/$(PLUGIN_NAME)-$(GOOS)-$(GOARCH)-${VERSION}.zip -j $(OUTPUT_DIR)/; \ | ||
else \ | ||
tar czf dist/$(PLUGIN_NAME)-$(GOOS)-$(GOARCH)-${VERSION}.tar.gz -C $(OUTPUT_DIR)/ ${FILES}; \ | ||
fi | ||
@sha256sum dist/$(PLUGIN_NAME)-$(GOOS)-$(GOARCH)-${VERSION}.* | sed '#dist/##g' >> dist/checksums.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters