Skip to content

Commit

Permalink
Changes to compilation to support linux (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeschuurmans authored Mar 14, 2024
1 parent 95cb6ac commit 91ed505
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lint: gen-mock

## Go test
test: lint
CGO_ENABLED=0 go test -timeout 1m -v -covermode=atomic ./...
go test -timeout 1m -v -covermode=atomic ./...

## Generate mocks
gen-mock:
Expand All @@ -29,39 +29,37 @@ gen-mock:

## build-osx
build-osx:
ifeq ($(GO_VERSION), 0)
ifeq (${GO_VERSION}, 0)
$(error build requies go version 1.17.n or higher)
endif
go build -o flasher \
-ldflags \
"-X $(LDFLAG_LOCATION).GitCommit=$(GIT_COMMIT) \
-X $(LDFLAG_LOCATION).GitBranch=$(GIT_BRANCH) \
-X $(LDFLAG_LOCATION).GitSummary=$(GIT_SUMMARY) \
-X $(LDFLAG_LOCATION).AppVersion=$(VERSION) \
-X $(LDFLAG_LOCATION).BuildDate=$(BUILD_DATE)"

CGO_ENABLED=0 go build -o flasher \
-ldflags \
"-X ${LDFLAG_LOCATION}.GitCommit=${GIT_COMMIT} \
-X ${LDFLAG_LOCATION}.GitBranch=${GIT_BRANCH} \
-X ${LDFLAG_LOCATION}.GitSummary=${GIT_SUMMARY} \
-X ${LDFLAG_LOCATION}.AppVersion=${VERSION} \
-X ${LDFLAG_LOCATION}.BuildDate=${BUILD_DATE}"

## Build linux bin
build-linux:
ifeq ($(GO_VERSION), 0)
ifeq (${GO_VERSION}, 0)
$(error build requies go version 1.16.n or higher)
endif
GOOS=linux GOARCH=amd64 go build -o flasher \
-ldflags \
"-X $(LDFLAG_LOCATION).GitCommit=$(GIT_COMMIT) \
-X $(LDFLAG_LOCATION).GitBranch=$(GIT_BRANCH) \
-X $(LDFLAG_LOCATION).GitSummary=$(GIT_SUMMARY) \
-X $(LDFLAG_LOCATION).AppVersion=$(VERSION) \
-X $(LDFLAG_LOCATION).BuildDate=$(BUILD_DATE)"

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o flasher \
-ldflags \
"-X ${LDFLAG_LOCATION}.GitCommit=${GIT_COMMIT} \
-X ${LDFLAG_LOCATION}.GitBranch=${GIT_BRANCH} \
-X ${LDFLAG_LOCATION}.GitSummary=${GIT_SUMMARY} \
-X ${LDFLAG_LOCATION}.AppVersion=${VERSION} \
-X ${LDFLAG_LOCATION}.BuildDate=${BUILD_DATE}"

## build docker image and tag as ghcr.io/metal-toolbox/flasher:latest
build-image: build-linux
@echo ">>>> NOTE: You may want to execute 'make build-image-nocache' depending on the Docker stages changed"
docker build --rm=true -f Dockerfile -t ${DOCKER_IMAGE}:latest . \
--label org.label-schema.schema-version=1.0 \
--label org.label-schema.vcs-ref=$(GIT_COMMIT_FULL) \
--label org.label-schema.vcs-url=$(REPO)
docker build --rm=true -f Dockerfile -t ${DOCKER_IMAGE}:latest . \
--label org.label-schema.schema-version=1.0 \
--label org.label-schema.vcs-ref=${GIT_COMMIT_FULL} \
--label org.label-schema.vcs-url=${REPO}

## tag and push devel docker image to local registry
push-image-devel: build-image
Expand All @@ -73,22 +71,18 @@ push-image-devel: build-image
push-image:
docker push ${DOCKER_IMAGE}:latest


## generate statemachine graphs and docs
gen-docs:
go build -o flasher
CGO_ENABLED=0 go build -o flasher
./docs/statemachine/generate.sh



# https://gist.github.com/prwhite/8168133
# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)


TARGET_MAX_CHAR_NUM=20
## Show help
help:
Expand All @@ -102,7 +96,7 @@ help:
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
printf " ${YELLOW}%-${TARGET_MAX_CHAR_NUM}s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
{ lastLine = $$0 }' ${MAKEFILE_LIST}

0 comments on commit 91ed505

Please sign in to comment.