2021-04-10 05:58:01 +00:00
|
|
|
NAME = apiary
|
|
|
|
|
|
|
|
.DEFAULT_GOAL := all
|
|
|
|
.PHONY: all clean
|
|
|
|
|
|
|
|
INSTALL_PREFIX ?= /usr/local
|
|
|
|
|
2021-04-14 15:32:31 +00:00
|
|
|
VERSION = $(shell cat version.go |grep "var Version"| cut -d "=" -f2| tr -d "\" ")
|
2021-04-10 05:58:01 +00:00
|
|
|
ARCH = $(shell go env | grep GOHOSTARCH | cut -d"=" -f2 | tr -d "\"")
|
|
|
|
OS = $(shell go env | grep GOHOSTOS | cut -d"=" -f2 | tr -d "\"")
|
|
|
|
GIT_COMMIT := $(shell git rev-parse --short HEAD)
|
|
|
|
|
|
|
|
BUILD_DIR = build/binary/current
|
|
|
|
BUILD_OUTPUT = $(BUILD_DIR)/$(NAME)-$(VERSION)-$(OS)-$(ARCH)
|
2021-04-10 06:12:06 +00:00
|
|
|
BUILD_FLAGS = -tags embed -ldflags "-X github.uio.no/torjus/apiary.Build=$(GIT_COMMIT)" -o $(BUILD_OUTPUT)
|
2021-04-10 05:58:01 +00:00
|
|
|
|
2021-04-10 10:03:13 +00:00
|
|
|
GEODB_URL = https://raw.githubusercontent.com/geoacumen/geoacumen-country/master/Geoacumen-Country.mmdb
|
2021-04-10 05:58:01 +00:00
|
|
|
GEODB_PATH = honeypot/Geoacumen-Country.mmdb
|
|
|
|
|
2021-04-10 07:03:00 +00:00
|
|
|
FRONTEND_BUILD_DIR = web/frontend/dist
|
|
|
|
|
2021-04-10 05:58:01 +00:00
|
|
|
ifeq ($(INSTALL_PREFIX), /)
|
|
|
|
INSTALL_BIN_DIR=/usr/bin
|
|
|
|
INSTALL_ETC_DIR=/etc/$(NAME)
|
|
|
|
else
|
|
|
|
INSTALL_BIN_DIR=$(INSTALL_PREFIX)/bin
|
|
|
|
INSTALL_ETC_DIR=$(INSTALL_PREFIX)/etc/$(NAME)
|
|
|
|
endif
|
|
|
|
|
|
|
|
$(GEODB_PATH):
|
|
|
|
curl $(GEODB_URL) -o $(GEODB_PATH)
|
|
|
|
|
2021-04-10 06:12:06 +00:00
|
|
|
$(BUILD_DIR):
|
2021-04-10 05:58:01 +00:00
|
|
|
mkdir -p $(BUILD_DIR)
|
|
|
|
|
2021-04-10 10:03:13 +00:00
|
|
|
$(FRONTEND_BUILD_DIR):
|
|
|
|
cd web/frontend && yarn install && yarn build
|
|
|
|
|
|
|
|
$(BUILD_OUTPUT): $(BUILD_DIR) $(GEODB_PATH) $(FRONTEND_BUILD_DIR)
|
2021-04-10 06:12:06 +00:00
|
|
|
CGO_ENABLED=0 go build $(BUILD_FLAGS) cmd/apiary.go
|
2021-04-10 05:58:01 +00:00
|
|
|
|
2021-04-10 07:09:43 +00:00
|
|
|
frontend:
|
|
|
|
cd web/frontend && yarn install && yarn build
|
2021-04-10 07:03:00 +00:00
|
|
|
|
2021-04-10 05:58:01 +00:00
|
|
|
clean:
|
|
|
|
rm -rv $(BUILD_DIR)
|
2021-04-10 07:03:00 +00:00
|
|
|
rm -rv $(FRONTEND_BUILD_DIR)
|
2021-04-10 05:58:01 +00:00
|
|
|
|
2021-04-10 06:12:06 +00:00
|
|
|
geodb: $(GEODB_PATH)
|
|
|
|
|
2021-04-10 10:03:13 +00:00
|
|
|
build: $(BUILD_OUTPUT)
|
2021-04-10 05:58:01 +00:00
|
|
|
|
|
|
|
install: build
|
|
|
|
mkdir -p $(INSTALL_BIN_DIR)
|
|
|
|
mkdir -p $(INSTALL_ETC_DIR)
|
|
|
|
install -m 755 $(BUILD_OUTPUT) $(INSTALL_BIN_DIR)/$(NAME)
|
|
|
|
install -m 755 apiary.toml $(INSTALL_ETC_DIR)/apiary.toml
|
|
|
|
|
|
|
|
uninstall:
|
2021-04-10 06:12:06 +00:00
|
|
|
rm -v $(INSTALL_ETC_DIR)/apiary.toml
|
|
|
|
rmdir -v $(INSTALL_ETC_DIR)
|
2021-04-10 05:58:01 +00:00
|
|
|
rm -v $(INSTALL_BIN_DIR)/$(NAME)
|