CC=go
BUILD=build -v
GCFLAGS=-gcflags '-e'
LDFLAGS=-ldflags '-s -w'
PROGRAM=gocrypt
ENV=CGO_ENABLED=0 GO111MODULE=on

all: $(PROGRAM)

release: clean gofmt test
	$(ENV) $(CC) $(BUILD) $(GCFLAGS) $(LDFLAGS)

release-vendor: clean gofmt test
	$(ENV) $(CC) $(BUILD) -mod=vendor $(GCFLAGS) $(LDFLAGS)

vendor: clean gofmt
	$(ENV) $(CC) $(BUILD) -mod=vendor $(GCFLAGS) $(LDFLAGS)

$(PROGRAM): clean gofmt
	$(ENV) $(CC) $(BUILD) $(GCFLAGS) $(LDFLAGS)

clean:
	$(CC) clean -x

gofmt:
	gofmt -w pkg/* main.go

test:
ifeq ($(shell go env GOARCH), $(shell go env GOHOSTARCH))
ifeq ($(shell go env GOOS), $(shell go env GOHOSTOS))
	$(CC) test ./...
else
	$(info skipping tests of other platforms)
endif
else
	$(info skipping tests of other platforms)
endif

.PHONY: release release-vendor vendor build clean gofmt test
