<commit_before>VERSION?=$(shell git describe --tags --dirty | sed 's/^v//')
GO_BUILD=CGO_ENABLED=0 go build -i --ldflags="-w"

rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) \
    $(filter $(subst *,%,$2),$d))

LINTERS=\
	gofmt \
	golint \
	vet \
	misspell \
	ineffassign \
	deadcode

all: ci

ci: $(LINTERS) cover build

.PHONY: all ci

# ################################################
# Bootstrapping for base golang package deps
# ################################################

CMD_PKGS=\
	github.com/golang/lint/golint \
	honnef.co/go/simple/cmd/gosimple \
	github.com/client9/misspell/cmd/misspell \
	github.com/gordonklaus/ineffassign \
	github.com/tsenart/deadcode \
	github.com/alecthomas/gometalinter \
	github.com/go-swagger/go-swagger/cmd/swagger

define VENDOR_BIN_TMPL
vendor/bin/$(notdir $(1)): vendor
	go build -o $$@ ./vendor/$(1)
VENDOR_BINS += vendor/bin/$(notdir $(1))
endef

$(foreach cmd_pkg,$(CMD_PKGS),$(eval $(call VENDOR_BIN_TMPL,$(cmd_pkg))))
$(patsubst %,%-bin,$(filter-out gofmt vet,$(LINTERS))): %-bin: vendor/bin/%
gofmt-bin vet-bin:

bootstrap:
	glide -v || curl http://glide.sh/get | sh

vendor: glide.lock
	glide install

.PHONY: bootstrap $(CMD_PKGS)

# ################################################
# Test and linting
# ###############################################

test: vendor
	@CGO_ENABLED=0 go test -v $$(glide nv)

COVER_TEST_PKGS:=$(shell find . -type f -name '*_test.go' | grep -v vendor | grep -v generated | rev | cut -d "/" -f 2- | rev | sort -u)
$(COVER_TEST_PKGS:=-cover): %-cover: all-cover.txt
	@CGO_ENABLED=0 go test -coverprofile=$@.out -covermode=atomic ./$*
	@if [ -f $@.out ]; then \
	    grep -v "mode: atomic" < $@.out >> all-cover.txt; \
	    rm $@.out; \
	fi

all-cover.txt:
	echo "mode: atomic" > all-cover.txt

cover: vendor all-cover.txt $(COVER_TEST_PKGS:=-cover)

$(LINTERS): %: vendor/bin/gometalinter %-bin vendor
	PATH=`pwd`/vendor/bin:$$PATH gometalinter --tests --disable-all --vendor \
	    --deadline=5m -s data $$(glide nv | grep -v generated) --enable $@


.PHONY: cover $(LINTERS) $(COVER_TEST_PKGS:=-cover)

# ################################################
# Building Swagger Clients
# ###############################################

generated/%/client: specs/%.yaml vendor/bin/swagger
	vendor/bin/swagger generate client -f $< -t generated/$*
	touch generated/$*/client
	touch generated/$*/models

APIS=$(patsubst specs/%.yaml,%,$(wildcard specs/*.yaml))
API_CLIENTS=$(APIS:%=generated/%/client)
generated-clients: $(API_CLIENTS)

.PHONY: generated-clients

# ################################################
# Building
# ###############################################$

PREFIX?=
SUFFIX=
ifeq ($(GOOS),windows)
    SUFFIX=.exe
endif

build: $(PREFIX)bin/manifold-cli$(SUFFIX)

MANIFOLDCLI_DEPS=\
		vendor \
		$(wildcard *.go) \
		$(call rwildcard,cmd,*.go) \
		generated-clients

$(PREFIX)bin/manifold-cli$(SUFFIX): $(MANIFOLDCLI_DEPS)
	$(GO_BUILD) -o $(PREFIX)bin/manifold-cli$(SUFFIX) ./cmd

.PHONY: build

# ################################################
# Cleaning
# ################################################

clean:
	rm -rf bin/manifold-cli
	rm -rf bin/manifold-cli.exe
	rm -rf build
	rm -rf generated<commit_msg>Introduce `make zips` for compiling binaries<commit_after>VERSION?=$(shell git describe --tags --dirty | sed 's/^v//')
GO_BUILD=CGO_ENABLED=0 go build -i --ldflags="-w"

rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) \
    $(filter $(subst *,%,$2),$d))

LINTERS=\
	gofmt \
	golint \
	vet \
	misspell \
	ineffassign \
	deadcode

all: ci

ci: $(LINTERS) cover build

.PHONY: all ci

# ################################################
# Bootstrapping for base golang package deps
# ################################################

CMD_PKGS=\
	github.com/golang/lint/golint \
	honnef.co/go/simple/cmd/gosimple \
	github.com/client9/misspell/cmd/misspell \
	github.com/gordonklaus/ineffassign \
	github.com/tsenart/deadcode \
	github.com/alecthomas/gometalinter \
	github.com/go-swagger/go-swagger/cmd/swagger

define VENDOR_BIN_TMPL
vendor/bin/$(notdir $(1)): vendor
	go build -o $$@ ./vendor/$(1)
VENDOR_BINS += vendor/bin/$(notdir $(1))
endef

$(foreach cmd_pkg,$(CMD_PKGS),$(eval $(call VENDOR_BIN_TMPL,$(cmd_pkg))))
$(patsubst %,%-bin,$(filter-out gofmt vet,$(LINTERS))): %-bin: vendor/bin/%
gofmt-bin vet-bin:

bootstrap:
	glide -v || curl http://glide.sh/get | sh

vendor: glide.lock
	glide install

.PHONY: bootstrap $(CMD_PKGS)

# ################################################
# Test and linting
# ###############################################

test: vendor
	@CGO_ENABLED=0 go test -v $$(glide nv)

COVER_TEST_PKGS:=$(shell find . -type f -name '*_test.go' | grep -v vendor | grep -v generated | rev | cut -d "/" -f 2- | rev | sort -u)
$(COVER_TEST_PKGS:=-cover): %-cover: all-cover.txt
	@CGO_ENABLED=0 go test -coverprofile=$@.out -covermode=atomic ./$*
	@if [ -f $@.out ]; then \
	    grep -v "mode: atomic" < $@.out >> all-cover.txt; \
	    rm $@.out; \
	fi

all-cover.txt:
	echo "mode: atomic" > all-cover.txt

cover: vendor all-cover.txt $(COVER_TEST_PKGS:=-cover)

$(LINTERS): %: vendor/bin/gometalinter %-bin vendor
	PATH=`pwd`/vendor/bin:$$PATH gometalinter --tests --disable-all --vendor \
	    --deadline=5m -s data $$(glide nv | grep -v generated) --enable $@


.PHONY: cover $(LINTERS) $(COVER_TEST_PKGS:=-cover)

# ################################################
# Building Swagger Clients
# ###############################################

generated/%/client: specs/%.yaml vendor/bin/swagger
	vendor/bin/swagger generate client -f $< -t generated/$*
	touch generated/$*/client
	touch generated/$*/models

APIS=$(patsubst specs/%.yaml,%,$(wildcard specs/*.yaml))
API_CLIENTS=$(APIS:%=generated/%/client)
generated-clients: $(API_CLIENTS)

.PHONY: generated-clients

# ################################################
# Building
# ###############################################$

PREFIX?=
SUFFIX=
ifeq ($(GOOS),windows)
    SUFFIX=.exe
endif

build: $(PREFIX)bin/manifold-cli$(SUFFIX)

MANIFOLDCLI_DEPS=\
		vendor \
		$(wildcard *.go) \
		$(call rwildcard,cmd,*.go) \
		generated-clients

$(PREFIX)bin/manifold-cli$(SUFFIX): $(MANIFOLDCLI_DEPS)
	$(GO_BUILD) -o $(PREFIX)bin/manifold-cli$(SUFFIX) ./cmd

.PHONY: build

#################################################
# Releasing
#################################################

NO_WINDOWS= \
	darwin_amd64 \
	linux_amd64
OS_ARCH= \
	$(NO_WINDOWS) \
	windows_amd64

os=$(word 1,$(subst _, ,$1))
arch=$(word 2,$(subst _, ,$1))

os-build/windows_amd64/bin/manifold-cli: os-build/%/bin/manifold-cli:
	PREFIX=build/$*/ GOOS=$(call os,$*) GOARCH=$(call arch,$*) make build/$*/bin/manifold-cli.exe
$(NO_WINDOWS:%=os-build/%/bin/manifold-cli): os-build/%/bin/manifold-cli:
	PREFIX=build/$*/ GOOS=$(call os,$*) GOARCH=$(call arch,$*) make build/$*/bin/manifold-cli

build/manifold-cli_$(VERSION)_windows_amd64.zip: build/manifold-cli_$(VERSION)_%.zip: os-build/%/bin/manifold-cli
	cd build/$*/bin; zip -r ../../manifold-cli_$(VERSION)_$*.zip manifold-cli.exe
$(NO_WINDOWS:%=build/manifold-cli_$(VERSION)_%.zip): build/manifold-cli_$(VERSION)_%.zip: os-build/%/bin/manifold-cli
	cd build/$*/bin; zip -r ../../manifold-cli_$(VERSION)_$*.zip manifold-cli

zips: $(OS_ARCH:%=build/manifold-cli_$(VERSION)_%.zip)

.PHONY: zips $(OS_ARCH:%=os-build/%/bin/manifold-cli)

# ################################################
# Cleaning
# ################################################

clean:
	rm -rf bin/manifold-cli
	rm -rf bin/manifold-cli.exe
	rm -rf build
	rm -rf generated
{'fraction_non_alphanumeric': 0.30473177804138657, 'fraction_numerical': 0.005008567286147357, 'mean_word_length': 4.675392670157068, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1228041', 'n_tokens_mistral': 2893, 'n_tokens_neox': 2724, 'n_words': 522}