eia-api-go/Makefile

40 lines
1.1 KiB
Makefile

# Variables
CLIENT_PKG := ./cmd/eia-client
CLIENT_GEN_FILE := ./api/eiaapi.gen.go
MAPPER_GEN_FILE := ./api/eiaapi_funcmap.gen.go
GO_FORMATTER := gofumpt
IS_GNU_SED := $(shell sed --version >/dev/null 2>&1 && echo true || echo false)
.PHONY: all generate build install clean
# Default target
all: generate build
# Generate code
generate:
go generate ./...
ifeq ($(IS_GNU_SED), true)
# Fix errors in generated code with GNU sed
sed -E -i 's/Total[[:space:]]+\*int/Total *string/g' $(CLIENT_GEN_FILE)
sed -E -i 's/Command[[:space:]]+\*\[\]string/Command *string/g' $(CLIENT_GEN_FILE)
else
# Fix errors in generated code with BSD sed
sed -E -i '' 's/Total[[:space:]]+\*int/Total *string/g' $(CLIENT_GEN_FILE)
sed -E -i '' 's/Command[[:space:]]+\*\[\]string/Command *string/g' $(CLIENT_GEN_FILE)
endif
# Pretty it up
$(GO_FORMATTER) -w $(CLIENT_GEN_FILE)
$(GO_FORMATTER) -w $(MAPPER_GEN_FILE)
# Build the client command binary
build: generate
go build -o bin/eia-client $(CLIENT_PKG)
# Install the client command binary
install: generate
go install -v $(CLIENT_PKG)
# Clean up generated files and build artifacts
clean:
rm -rf bin/eia-client