eia-api-go/Makefile

38 lines
1.0 KiB
Makefile
Raw Normal View History

2024-11-16 19:02:46 +00:00
# Variables
CLIENT_PKG := ./cmd/eia-client
2024-11-26 15:54:55 +00:00
CLIENT_GEN_FILE := ./api/eiaapi.gen.go
GO_FORMATTER := gofumpt
IS_GNU_SED := $(shell sed --version >/dev/null 2>&1 && echo true || echo false)
2024-11-15 21:30:45 +00:00
2024-11-16 19:02:46 +00:00
.PHONY: all generate build install clean
2024-11-15 21:30:45 +00:00
2024-11-16 19:02:46 +00:00
# Default target
all: generate build
2024-11-15 21:30:45 +00:00
2024-11-16 19:02:46 +00:00
# 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
2024-11-26 15:54:55 +00:00
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
2024-11-26 15:54:55 +00:00
# Pretty it up
$(GO_FORMATTER) -w $(CLIENT_GEN_FILE)
2024-11-15 21:30:45 +00:00
2024-11-16 19:02:46 +00:00
# Build the client command binary
build: generate
go build -o bin/eia-client $(CLIENT_PKG)
2024-11-15 21:30:45 +00:00
2024-11-16 19:02:46 +00:00
# Install the client command binary
install: generate
2024-11-26 15:54:55 +00:00
go install -v $(CLIENT_PKG)
2024-11-15 21:30:45 +00:00
2024-11-16 19:02:46 +00:00
# Clean up generated files and build artifacts
2024-11-15 21:30:45 +00:00
clean:
2024-11-16 19:02:46 +00:00
rm -rf bin/eia-client