1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-22 05:40:11 +01:00
gocsaf/Makefile
Bernhard Reiter 65605b2928
Improve Makefile
* Change mechanics to use a variable to indicate if a tag build is
   wanted. Add ability to specify tag explictely.
 * Use variables to have only one build recipe.
 * Place binaries in target specific bin- directories.
 * Do not return to main branch as it may not be the original branch we
   were on. Turn this into a warning.
2022-02-08 17:31:49 +01:00

49 lines
1.3 KiB
Makefile

# Makefile to build csaf_distribution components
SHELL = /bin/bash
BUILD = go build
MKDIR = mkdir -p
.PHONY: build build_linux build_win tag_checked_out mostlyclean
all:
@echo choose a target from: build build_linux build_win mostlyclean
@echo prepend \`make BUILDTAG=1\` to checkout the highest git tag before building
@echo or set BUILDTAG to a specific tag
# Build all binaries
build: build_linux build_win
# if BUILDTAG == 1 set it to the highest git tag
ifeq ($(strip $(BUILDTAG)),1)
override BUILDTAG = $(shell git tag --sort=-version:refname | head -n 1)
endif
ifdef BUILDTAG
# add the git tag checkout to the requirements of our build targets
build_linux build_win: tag_checked_out
endif
tag_checked_out:
$(if $(strip $(BUILDTAG)),,$(error no git tag found))
git checkout -q tags/${BUILDTAG}
@echo Don\'t forget that we are in checked out tag $(BUILDTAG) now.
# Build binaries and place them under bin-$(GOOS)-$(GOARCH)
# Using 'Target-specific Variable Values' to specify the build target system
GOARCH = amd64
build_linux: GOOS = linux
build_win: GOOS = windows
build_linux build_win:
$(eval BINDIR = bin-$(GOOS)-$(GOARCH)/ )
$(MKDIR) $(BINDIR)
env GOARCH=$(GOARCH) GOOS=$(GOOS) $(BUILD) -o $(BINDIR) -v ./cmd/...
# Remove bin-*-* directories
mostlyclean:
rm -rf ./bin-*-*
@echo Files in \`go env GOCACHE\` remain.