# Luis Figueiredo (luisf@casemyway.com)
# 

GOPATH=$(CURDIR)/deps:$(CURDIR)
DIST=./DIST
BUILDENV=CGO_ENABLED=0
GETENV=


# Source in packages names
# What packages to build

# CLI Packages
CLI=flowserver/cmd/flowserver
BIN=$(addprefix $(DIST)/, $(notdir $(CLI)))

# Windows build
ifeq ($(GOOS),windows)
	ENV+=CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ CGO_ENABLED=1 GOOS=$(GOOS) GOARCH=$(GOARCH)
	BIN:=$(addsuffix .exe, $(BIN))
endif

.PHONY: all deps clean dist-clean $(BIN)

all: $(BIN) deps
	@$(ENV) echo -e "\e[32;01mBuilt for OS: `go env GOOS`, ARCH: `go env GOARCH`\e[0m"
	
$(BIN): deps
	$(BUILDENV) GOPATH="$(GOPATH)" go build -o $@ $(CLI)

# generate
generate:
	GOPATH="$(GOPATH)" go generate ./src/...

test:
	$(ENV) go test ./src/...

#$(BIN): $(addprefix src/,$(SOURCE))
#	echo $<

deps:
	$(GETENV) GOPATH="$(GOPATH)" go get -v ./src/... # everything from source
	# test package 
	$(GETENV) GOPATH="$(GOPATH)" go get -v -t ./src/...

clean:
	rm -rf $(DIST)

dist-clean: clean
	rm -rf bin
	rm -rf pkg
	rm -rf deps

$(DIST):
	mkdir -p $(DIST)


