Browse Source

Split makefiles

master
Dashie der otter 2 years ago
parent
commit
6f72fdea82
Signed by: Dashie <dashie@sigpipe.me> GPG Key ID: C2D57B325840B755
4 changed files with 154 additions and 39 deletions
  1. 48
    39
      Makefile
  2. 86
    0
      common.mk
  3. 10
    0
      lutractl/Makefile
  4. 10
    0
      lutrainit/Makefile

+ 48
- 39
Makefile View File

@@ -1,61 +1,69 @@
LDFLAGS += -X "main.LutraBuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')"
LDFLAGS += -X "main.LutraBuildGitHash=$(shell git rev-parse HEAD)"
.PHONY: build

OS := $(shell uname)
build: build-lutrainit build-lutractl
build-lutrainit:
$(MAKE) -C lutrainit build

TAGS=
GOVET=go tool vet -composites=false -methods=false -structtags=false
build-lutractl:
$(MAKE) -C lutractl build

.PHONY: build clean
build-race: build-race-lutrainit build-race-lutractl
build-race-lutrainit:
$(MAKE) -C lutrainit build-race

all: build
build-race-lutractl:
$(MAKE) -C lutractl build-race

check: test
vet: vet-lutrainit vet-lutractl
vet-lutrainit:
$(MAKE) -C lutrainit vet

govet:
$(GOVET) */*.go
vet-lutractl:
$(MAKE) -C lutractl vet

init:
@echo "Building init"
cd lutrainit && GOOS=linux GOARCH=amd64 go build -o lutrainit -ldflags '$(LDFLAGS)' -tags '$(TAGS)'
clean: clean-lutrainit clean-lutractl
clean-lutrainit:
$(MAKE) -C lutrainit clean

ctl:
@echo "Building client"
cd lutractl && GOOS=linux GOARCH=amd64 go build -o lutractl -ldflags '$(LDFLAGS)' -tags '$(TAGS)'
clean-lutractl:
$(MAKE) -C lutractl clean

init-race:
@echo "Building init"
cd lutrainit && GOOS=linux GOARCH=amd64 go build -o lutrainit -race -ldflags '$(LDFLAGS)' -tags '$(TAGS)'
test: test-lutrainit test-lutractl
test-lutrainit:
$(MAKE) -C lutrainit test

ctl-race:
@echo "Building client"
cd lutractl && GOOS=linux GOARCH=amd64 go build -o lutractl -race -ldflags '$(LDFLAGS)' -tags '$(TAGS)'
test-lutractl:
$(MAKE) -C lutractl test

build: init ctl
misspell-check: misspell-check-lutrainit misspell-check-lutractl
misspell-check-lutrainit:
$(MAKE) -C lutrainit misspell-check

build-race: init-race ctl-race
misspell-check-lutractl:
$(MAKE) -C lutractl misspell-check

build-dev: govet
go build -o lutrainit -v -tags '$(TAGS)' $$(go list ./... | grep -v /vendor/)
fmt-check: fmt-check-lutrainit fmt-check-lutractl
fmt-check-lutrainit:
$(MAKE) -C lutrainit fmt-check

build-dev-race: govet
go build -o lutrainit -v -race -tags '$(TAGS)' $$(go list ./... | grep -v /vendor/)
fmt-check-lutractl:
$(MAKE) -C lutractl fmt-check

clean:
find . -name ".DS_Store" -delete
go clean -i ./...
fmt: fmt-lutrainit fmt-lutractl
fmt-lutrainit:
$(MAKE) -C lutrainit fmt

test-init:
cd lutrainit && go test -cover -race $$(go list ./... | grep -v /vendor/)
fmt-lutractl:
$(MAKE) -C lutractl fmt

test-ctl:
cd lutractl && go test -cover -race $$(go list ./... | grep -v /vendor/)
lint: lint-lutrainit lint-lutractl
lint-lutrainit:
$(MAKE) -C lutrainit lint

test: test-init test-ctl

lint:
golint $$(go list ./... | grep -v /vendor/)
lint-lutractl:
$(MAKE) -C lutractl lint

## Other targets
install:
install -m 0755 -p lutrainit/lutrainit /lutrainit
install -m 0755 -p lutractl/lutractl /usr/bin/lutractl
@@ -77,3 +85,4 @@ docker-run: docker-build

docker-rm:
docker rm lutrainit


+ 86
- 0
common.mk View File

@@ -0,0 +1,86 @@
OS := $(shell uname)

DIST := dist

BUILD_FLAGS := -o $(EXECUTABLE) -v
NOW=$(shell date -u '+%Y%m%d%I%M%S')

TAGS =

GOVET=go vet
GOLINT=golint -set_exit_status
GO ?= go
GOFMT ?= gofmt -s


ifneq ($(DRONE_TAG),)
VERSION ?= $(subst v,,$(DRONE_TAG))
else
ifneq ($(DRONE_BRANCH),)
VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
else
VERSION ?= master
endif
endif

### Targets

.PHONY: build clean

all: build

check: test

vet:
$(GOVET) $(PACKAGES)

lint:
@hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/golang/lint/golint; \
fi
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;

build:
$(GO) build $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -tags '$(TAGS)'

build-race:
$(GO) build $(BUILD_FLAGS) -race -ldflags '$(LDFLAGS)' -tags '$(TAGS)'

clean:
$(GO) clean -i ./...
find . -name ".DS_Store" -delete

test: fmt-check
$(GO) test -cover -v$(PACKAGES)

.PHONY: misspell-check
misspell-check:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -error -i unknwon $(GOFILES)

.PHONY: misspell
misspell:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -w -i unknwon $(GOFILES)

required-gofmt-version:
@go version | grep -q '\(1.7\|1.8\|1.9\)' || { echo "We require go version 1.7, 1.8 or 1.9 to format code" >&2 && exit 1; }

.PHONY: fmt
fmt: required-gofmt-version
$(GOFMT) -w $(GOFILES)

.PHONY: fmt-check
fmt-check: required-gofmt-version
# get all go files and run go fmt on them
@diff=$$($(GOFMT) -d $(GOFILES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;


+ 10
- 0
lutractl/Makefile View File

@@ -0,0 +1,10 @@
EXECUTABLE := lutractl

LDFLAGS += -X "github.com/rhaamo/lutrainit/lutractl/setting.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')"
LDFLAGS += -X "github.com/rhaamo/lutrainit/lutractl/setting.BuildGitHash=$(shell git rev-parse HEAD)"

GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)

include ../common.mk


+ 10
- 0
lutrainit/Makefile View File

@@ -0,0 +1,10 @@
EXECUTABLE := lutrainit

LDFLAGS += -X "github.com/rhaamo/lutrainit/lutrainit/setting.BuildTime=$(shell date -u '+%Y-%m-%d %I:%M:%S %Z')"
LDFLAGS += -X "github.com/rhaamo/lutrainit/lutrainit/setting.BuildGitHash=$(shell git rev-parse HEAD)"

GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)

include ../common.mk


Loading…
Cancel
Save