github.com/CycloneDX/sbom-utility@v0.16.0/Makefile (about) 1 # 2 # Licensed to the Apache Software Foundation (ASF) under one or more 3 # contributor license agreements. See the NOTICE file distributed with 4 # this work for additional information regarding copyright ownership. 5 # The ASF licenses this file to You under the Apache License, Version 2.0 6 # (the "License"); you may not use this file except in compliance with 7 # the License. You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 18 SOURCEDIR=. 19 20 SOURCES := $(shell find $(SOURCEDIR) -name '*.go') 21 BINARY?=sbom-utility 22 23 # LDFLAG values 24 VERSION?=latest 25 BUILD=`git rev-parse HEAD` 26 BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` 27 RELEASE_DIR=release 28 29 # TODO: automate other flags 30 # LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.GitCommit=${BUILD} -X main.BuildDate=${BUILD_DATE} -X main.Build=`git rev-parse HEAD` " 31 # NOTE: The `-s` (sign) flag MUST be used or the binary will will be rejected on MacOS 32 # Additionally on MacOS, the binary MUST be moved (i.e., `mv`) not copied (i.e., `cp`) 33 LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Binary=${BINARY} -s" 34 35 # Build the project 36 build: clean 37 go build ${LDFLAGS} -o ${BINARY} 38 39 # General supported environments: https://go.dev/doc/install/source#environment 40 # See latest supported combinations using: 41 # $ go install golang.org/x/tools/cmd/goimports@latest 42 # $ go tool dist list 43 # However, many combinations are not supported "in box" 44 # See this Gist for details: https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63 45 # TODO: perhaps create universal binaries for various OS 46 # TODO: See "lipo" tool for MacOS universal binary 47 release: clean config sbom 48 GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o ${RELEASE_DIR}/${BINARY}-darwin-amd64 49 GOOS=darwin GOARCH=arm64 go build ${LDFLAGS} -o ${RELEASE_DIR}/${BINARY}-darwin-arm64 50 GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o ${RELEASE_DIR}/${BINARY}-linux-amd64 51 GOOS=linux GOARCH=arm64 go build ${LDFLAGS} -o ${RELEASE_DIR}/${BINARY}-linux-arm64 52 GOOS=windows GOARCH=amd64 go build ${LDFLAGS} -o ${RELEASE_DIR}/${BINARY}-windows-amd64 53 GOOS=windows GOARCH=arm64 go build ${LDFLAGS} -o ${RELEASE_DIR}/${BINARY}-windows-arm64 54 GOOS=windows GOARCH=arm64 go build ${LDFLAGS} -o ${RELEASE_DIR}/${BINARY}-windows-arm64 55 GOOS=linux GOARCH=ppc64 go build ${LDFLAGS} -o ${RELEASE_DIR}/${BINARY}-linux-ppc64 56 GOOS=linux GOARCH=s390x go build ${LDFLAGS} -o ${RELEASE_DIR}/${BINARY}-linux-s390x 57 cp LICENSE ${RELEASE_DIR}/ 58 cp config.json ${RELEASE_DIR}/ 59 cp license.json ${RELEASE_DIR}/ 60 cp custom.json ${RELEASE_DIR}/ 61 62 sbom: 63 @echo "Creating Software-Bill-Of-Materials (CycloneDX latest JSON format)" 64 go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest 65 mkdir -p ${RELEASE_DIR} 66 cyclonedx-gomod mod -json=true -output ${RELEASE_DIR}/${BINARY}-${VERSION}.bom.json . 67 68 # Clean test cache 69 test_clean: 70 go clean -testcache 71 72 # Run all tests 73 test: test_clean 74 @echo "Testing" 75 go test ./... -v 76 77 # Run cmd tests 78 test_cmd: test_clean 79 @echo "Testing `cmd` package" 80 go test ./cmd -v --args --quiet 81 go test ./schema -v --args --quiet 82 83 test_schema: test_clean 84 @echo "Testing `schema` package" 85 go test ./schema -v --args --quiet 86 87 # Run the unit tests 88 unit_tests: test_clean 89 @echo "Testing -tags=unit" 90 go test ./... -v -tags=unit 91 92 # Run the integration tests 93 integration_tests: test_clean 94 @echo "Testing -tags=integration" 95 go test -v ./... -tags=integration 96 97 format: 98 @echo "Formatting" 99 go fmt ./... 100 101 lint: format 102 @echo "Linting" 103 golint . 104 105 # install: go install github.com/golangci/golangci-lint/cmd/golangci-lint@x.y.z 106 golangci_lint: 107 @echo "golangci-lint run" 108 golangci-lint run 109 110 install: 111 go install 112 113 # Cleans project up binaries 114 # if ${BINARY}: covers any manual `go build` executables 115 # if ${BINARY}: covers `make build` target 116 # if ${RELEASE_DIR}: covers `make release` target 117 clean: 118 @if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi 119 @if [ -d ${RELEASE_DIR} ] ; then rm -f ${RELEASE_DIR}/${BINARY}* ; rm -f ${RELEASE_DIR}/*.json ; rmdir ${RELEASE_DIR} ; fi 120 121 .PHONY: config clean build release test_clean test test_cmd unit_tests integration_tests format lint install