2024-03-19 13:50:13 +01:00
|
|
|
#export GOPATH=$(shell pwd)/GO
|
|
|
|
|
#export GOBIN=$(GOPATH)/bin
|
|
|
|
|
#export PATH=$(GOBIN):$(shell echo $${PATH})
|
2024-02-27 07:22:57 +01:00
|
|
|
|
2025-03-12 12:55:41 +01:00
|
|
|
GOFLAGS=
|
2022-02-24 07:26:55 +01:00
|
|
|
GOCMD=go
|
2025-03-12 12:55:41 +01:00
|
|
|
GOBUILD=$(GOCMD) build $(GOFLAGS)
|
2024-06-01 17:26:16 +02:00
|
|
|
GOGENERATE=$(GOCMD) generate
|
2022-02-24 07:26:55 +01:00
|
|
|
GOCLEAN=$(GOCMD) clean
|
|
|
|
|
GOTEST=$(GOCMD) test
|
|
|
|
|
GOGET=$(GOCMD) get
|
2022-01-14 15:21:00 +01:00
|
|
|
|
2022-02-24 07:26:55 +01:00
|
|
|
BUILD_DIR=build
|
2023-02-02 13:11:04 +01:00
|
|
|
OBITOOLS_PREFIX:=
|
2022-01-14 15:21:00 +01:00
|
|
|
|
2022-02-24 07:26:55 +01:00
|
|
|
PACKAGES_SRC:= $(wildcard pkg/*/*.go pkg/*/*/*.go)
|
|
|
|
|
PACKAGE_DIRS:=$(sort $(patsubst %/,%,$(dir $(PACKAGES_SRC))))
|
|
|
|
|
PACKAGES:=$(notdir $(PACKAGE_DIRS))
|
2022-01-14 15:21:00 +01:00
|
|
|
|
2025-03-08 18:56:02 +01:00
|
|
|
GITHOOK_SRC_DIR=git-hooks
|
|
|
|
|
GITHOOKS_SRC:=$(wildcard $(GITHOOK_SRC_DIR)/*)
|
|
|
|
|
|
|
|
|
|
GITHOOK_DIR=.git/hooks
|
|
|
|
|
GITHOOKS:=$(patsubst $(GITHOOK_SRC_DIR)/%,$(GITHOOK_DIR)/%,$(GITHOOKS_SRC))
|
|
|
|
|
|
2022-02-24 07:26:55 +01:00
|
|
|
OBITOOLS_SRC:= $(wildcard cmd/obitools/*/*.go)
|
|
|
|
|
OBITOOLS_DIRS:=$(sort $(patsubst %/,%,$(dir $(OBITOOLS_SRC))))
|
|
|
|
|
OBITOOLS:=$(notdir $(OBITOOLS_DIRS))
|
2022-01-14 15:21:00 +01:00
|
|
|
|
|
|
|
|
|
2022-02-24 07:26:55 +01:00
|
|
|
define MAKE_PKG_RULE
|
2024-06-01 17:26:16 +02:00
|
|
|
pkg-$(notdir $(1)): $(1) pkg/obioptions/version.go
|
2022-02-24 07:26:55 +01:00
|
|
|
@echo -n - Building package $(notdir $(1))...
|
|
|
|
|
@$(GOBUILD) ./$(1) \
|
|
|
|
|
2> pkg-$(notdir $(1)).log \
|
|
|
|
|
|| cat pkg-$(notdir $(1)).log
|
|
|
|
|
@rm -f pkg-$(notdir $(1)).log
|
|
|
|
|
@echo Done.
|
|
|
|
|
endef
|
2022-01-14 15:21:00 +01:00
|
|
|
|
2022-02-24 07:26:55 +01:00
|
|
|
define MAKE_OBITOOLS_RULE
|
2024-06-01 17:26:16 +02:00
|
|
|
$(OBITOOLS_PREFIX)$(notdir $(1)): $(BUILD_DIR) $(1) pkg/obioptions/version.go
|
2022-02-24 07:26:55 +01:00
|
|
|
@echo -n - Building obitool $(notdir $(1))...
|
|
|
|
|
@$(GOBUILD) -o $(BUILD_DIR)/$(OBITOOLS_PREFIX)$(notdir $(1)) ./$(1) \
|
|
|
|
|
2> $(OBITOOLS_PREFIX)$(notdir $(1)).log \
|
|
|
|
|
|| cat $(OBITOOLS_PREFIX)$(notdir $(1)).log
|
|
|
|
|
@rm -f $(OBITOOLS_PREFIX)$(notdir $(1)).log
|
|
|
|
|
@echo Done.
|
|
|
|
|
endef
|
2022-01-14 15:21:00 +01:00
|
|
|
|
2024-06-01 17:26:16 +02:00
|
|
|
GIT=$(shell which git 2>&1 >/dev/null && which git)
|
|
|
|
|
GITDIR=$(shell ls -d .git 2>/dev/null && echo .git || echo)
|
|
|
|
|
ifneq ($(strip $(GIT)),)
|
|
|
|
|
ifneq ($(strip $(GITDIR)),)
|
|
|
|
|
COMMIT_ID:=$(shell $(GIT) log -1 HEAD --format=%h)
|
|
|
|
|
LAST_TAG:=$(shell $(GIT) describe --tags $$($(GIT) rev-list --tags --max-count=1) | \
|
|
|
|
|
tr '_' ' ')
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
OUTPUT:=$(shell mktemp)
|
2022-01-14 15:21:00 +01:00
|
|
|
|
2025-03-08 18:56:02 +01:00
|
|
|
all: install-githook obitools
|
2022-01-14 15:21:00 +01:00
|
|
|
|
2026-02-05 17:38:47 +01:00
|
|
|
obitools: $(patsubst %,$(OBITOOLS_PREFIX)%,$(OBITOOLS))
|
2022-01-14 15:21:00 +01:00
|
|
|
|
2025-03-08 18:56:02 +01:00
|
|
|
install-githook: $(GITHOOKS)
|
2026-02-05 17:38:47 +01:00
|
|
|
|
2025-03-08 18:56:02 +01:00
|
|
|
$(GITHOOK_DIR)/%: $(GITHOOK_SRC_DIR)/%
|
|
|
|
|
@echo installing $$(basename $@)...
|
|
|
|
|
@mkdir -p $(GITHOOK_DIR)
|
|
|
|
|
@cp $< $@
|
|
|
|
|
@chmod +x $@
|
|
|
|
|
|
|
|
|
|
|
2023-03-21 22:02:18 +07:00
|
|
|
update-deps:
|
|
|
|
|
go get -u ./...
|
|
|
|
|
|
2025-03-08 18:56:02 +01:00
|
|
|
test: .FORCE
|
2023-08-27 17:22:51 +02:00
|
|
|
$(GOTEST) ./...
|
2025-02-19 13:17:36 +01:00
|
|
|
|
2026-02-05 17:38:47 +01:00
|
|
|
obitests:
|
2025-02-19 15:55:07 +01:00
|
|
|
@for t in $$(find obitests -name test.sh -print) ; do \
|
2025-03-08 16:54:24 +01:00
|
|
|
bash $${t} || exit 1;\
|
2026-02-05 17:38:47 +01:00
|
|
|
done
|
2025-02-19 14:37:05 +01:00
|
|
|
|
|
|
|
|
githubtests: obitools obitests
|
2022-05-27 11:53:29 +03:00
|
|
|
|
2022-02-24 07:26:55 +01:00
|
|
|
$(BUILD_DIR):
|
|
|
|
|
mkdir -p $@
|
2022-01-14 15:21:00 +01:00
|
|
|
|
|
|
|
|
|
2022-02-24 07:26:55 +01:00
|
|
|
$(foreach P,$(PACKAGE_DIRS),$(eval $(call MAKE_PKG_RULE,$(P))))
|
2022-01-14 15:21:00 +01:00
|
|
|
|
2022-02-24 07:26:55 +01:00
|
|
|
$(foreach P,$(OBITOOLS_DIRS),$(eval $(call MAKE_OBITOOLS_RULE,$(P))))
|
2022-01-14 15:21:00 +01:00
|
|
|
|
2026-02-05 17:38:47 +01:00
|
|
|
pkg/obioptions/version.go: version.txt .FORCE
|
|
|
|
|
@version=$$(cat version.txt); \
|
|
|
|
|
cat $@ \
|
|
|
|
|
| sed -E 's/^var _Version = "[^"]*"/var _Version = "Release '$$version'"/' \
|
2024-06-01 17:26:16 +02:00
|
|
|
> $(OUTPUT)
|
|
|
|
|
|
|
|
|
|
@diff $@ $(OUTPUT) 2>&1 > /dev/null \
|
2026-02-05 17:38:47 +01:00
|
|
|
|| (echo "Update version.go to $$(cat version.txt)" && mv $(OUTPUT) $@)
|
2024-06-01 17:26:16 +02:00
|
|
|
|
|
|
|
|
@rm -f $(OUTPUT)
|
2026-02-05 17:38:47 +01:00
|
|
|
|
|
|
|
|
bump-version:
|
|
|
|
|
@echo "Incrementing version..."
|
|
|
|
|
@current=$$(cat version.txt); \
|
|
|
|
|
echo " Current version: $$current"; \
|
|
|
|
|
major=$$(echo $$current | cut -d. -f1); \
|
|
|
|
|
minor=$$(echo $$current | cut -d. -f2); \
|
|
|
|
|
patch=$$(echo $$current | cut -d. -f3); \
|
|
|
|
|
new_patch=$$((patch + 1)); \
|
|
|
|
|
new_version="$$major.$$minor.$$new_patch"; \
|
|
|
|
|
echo " New version: $$new_version"; \
|
|
|
|
|
echo "$$new_version" > version.txt
|
|
|
|
|
@echo "✓ Version updated in version.txt"
|
|
|
|
|
@$(MAKE) pkg/obioptions/version.go
|
2024-06-01 17:26:16 +02:00
|
|
|
|
2026-01-25 18:43:30 +01:00
|
|
|
jjnew:
|
|
|
|
|
@echo "$(YELLOW)→ Creating a new commit...$(NC)"
|
|
|
|
|
@echo "$(BLUE)→ Documenting current commit...$(NC)"
|
|
|
|
|
@jj auto-describe
|
|
|
|
|
@echo "$(BLUE)→ Done.$(NC)"
|
|
|
|
|
@jj new
|
|
|
|
|
@echo "$(GREEN)✓ New commit created$(NC)"
|
|
|
|
|
|
2026-02-05 17:38:47 +01:00
|
|
|
jjpush:
|
2026-01-25 18:43:30 +01:00
|
|
|
@echo "$(YELLOW)→ Pushing commit to repository...$(NC)"
|
|
|
|
|
@echo "$(BLUE)→ Documenting current commit...$(NC)"
|
|
|
|
|
@jj auto-describe
|
2026-02-05 17:38:47 +01:00
|
|
|
@echo "$(BLUE)→ Creating new commit for version bump...$(NC)"
|
|
|
|
|
@jj new
|
|
|
|
|
@$(MAKE) bump-version
|
|
|
|
|
@echo "$(BLUE)→ Documenting version bump commit...$(NC)"
|
|
|
|
|
@jj auto-describe
|
|
|
|
|
@version=$$(cat version.txt); \
|
2026-02-05 17:53:43 +01:00
|
|
|
tag_name="Release_$$version"; \
|
|
|
|
|
echo "$(BLUE)→ Pushing commits and creating tag $$tag_name...$(NC)"; \
|
2026-02-05 17:38:47 +01:00
|
|
|
jj git push --change @; \
|
2026-02-05 17:53:43 +01:00
|
|
|
git tag -a "$$tag_name" -m "Release $$version" 2>/dev/null || echo "Tag $$tag_name already exists"; \
|
|
|
|
|
git push origin "$$tag_name" 2>/dev/null || echo "Tag already pushed"
|
2026-02-05 17:38:47 +01:00
|
|
|
@echo "$(GREEN)✓ Commits and tag pushed to repository$(NC)"
|
2026-01-25 18:43:30 +01:00
|
|
|
|
|
|
|
|
jjfetch:
|
|
|
|
|
@echo "$(YELLOW)→ Pulling latest commits...$(NC)"
|
|
|
|
|
@jj git fetch
|
|
|
|
|
@jj new master@origin
|
|
|
|
|
@echo "$(GREEN)✓ Latest commits pulled$(NC)"
|
|
|
|
|
|
2026-02-05 17:38:47 +01:00
|
|
|
.PHONY: all obitools update-deps obitests githubtests jjnew jjpush jjfetch bump-version .FORCE
|
|
|
|
|
.FORCE:
|