# Makefile
-MK_PATH:=$(dir $(realpath $(lastword $(MAKEFILE_LIST))))
-WORKSPACE_LOC:=$(MK_PATH)../../
+BUILD_DIR = $(shell pwd)
+BIN_DIR = bin
+COMMITINFO := $(wildcard bin/commitinfo.sh)
-WorkFiles := checksums.json AM-GlobalFunc.rsc
-WORK_DIR := /var/www/ros.vados.ru
+HTML_DIR = html
+ALL_RSC := $(wildcard html/*.rsc html/*/*.rsc)
+GLOB_FUNC := $(wildcard html/AM-GlobalFunc.rsc)
DATE ?= $(shell (date '+%T %d.%m.%Y'))
DTSTAMP ?= $(shell (date '+%Y%d%m%H%M%S'))
VERSION ?= $(shell git symbolic-ref --short HEAD 2>/dev/null)/$(shell git rev-list --count HEAD 2>/dev/null)/$(shell git rev-parse --short=8 HEAD 2>/dev/null)
-OWNER ?= $(shell whoami)
-
-#SEDCMD ?= $(shell sed -e "/^:global CommitId/c :global CommitId \"${COMMITID:-unknown}\";")/$(shell sed )
-
-all: $(WorkFiles)
-
-.PHONY: $(WorkFiles)
-
-checksums.json : ALL_RSC := $(wildcard *.rsc */*.rsc)
-AM-GlobalFunc.rsc : COMMITID := $(VERSION)
-AM-GlobalFunc.rsc : COMMITINFO := "$(DATE) - Commit owner: $(OWNER)"
-
-ifeq ($@,AM-GlobalFunc.rsc)
-define sed-cmd =
- cd $(WORK_DIR) && \
- sed \
- -e "/^:global CommitId/c :global CommitId \"${COMMITID:-unknown}\";" \
- -e "/^:global CommitInfo/c :global CommitInfo \"${COMMITINFO:-unknown}\";" \
- < "./html/${1}"
- endef
+RUN_OWNER := $(shell whoami 2>/dev/null)
+COMM_REPO := $(shell git rev-parse --show-toplevel | rev | cut -d/ -f1 | rev 2>/dev/nul)
+COMM_BRANCH := $(shell git symbolic-ref --short HEAD 2>/dev/null)
+
+COMM_TAG := $(shell git rev-list --abbrev-commit --tags --max-count=1)
+# `2>/dev/null` suppress errors and `|| true` suppress the error codes.
+TAG := $(shell git describe --abbrev=0 --tags ${COMM_TAG} 2>/dev/null || true)
+# here we strip the version prefix
+TAG_VERS := $(TAG:v%=%)
+# get the latest commit hash in the short form
+COMM_HASH := $(shell git rev-parse --short=8 HEAD 2>/dev/null) # Get short commit hash
+#COMMIT := $(shell git rev-parse --short HEAD)
+# get the latest commit date in the form of YYYYmmdd
+COMM_DATE := $(shell git log -1 --format=%cd --date=format:"%Y%m%d%H%M")
+ifneq ($(COMM_HASH), $(COMM_TAG))
+ TAG_VERS := $(TAG_VERS)-next-$(COMM_HASH)-$(COMM_DATE)
endif
-
-ifeq ($@,checksums.json)
- define get-sums =
- cd $(WORK_DIR)/html && \
- md5sum $(find -name '*.rsc' | sort) | \
- sed -e "s| \./||" -e 's|.rsc$||' | \
- jq --raw-input --null-input '[ inputs | split (" ") | { (.[1]): (.[0]) }] | add' > $@
- endef
+ifeq ($(TAG_VERS), )
+ TAG_VERS := $(COMM_HASH)-$(COMM_DATE)
endif
-
-$(WorkFiles):
-ifeq ($@,checksums.json)
- $(get-sums) $(ALL_RSC); > $@
+ifneq ($(shell git status --porcelain), )
+ TAG_VERS := $(TAG_VERS)-dirty
endif
-checksums: checksums.json
- cd $(WORK_DIR)/html
-
-checksums.json: $(WORK_DIR)/bin/checksums.sh $(ALL_RSC)
- $(WORK_DIR)/bin/checksums.sh > $(WORK_DIR)/html/$@
-
+COMMIT_ID := $(VERSION)
+COMM_INFO := $(shell echo -e "Autocommit in repo: $(COMM_REPO), generated by owner: $(RUN_OWNER), in $(DATE)." 2>/dev/null)
-$(FuncFile): ./html/$@
- $(sed-cmd) $< > $<~
- mv $<~ $<
+export BUILD_DIR BIN_DIR HTML_DIR DATE DTSTAMP VERSION COMMIT_ID COMM_TAG COMM_HASH COMM_INFO
-#$(WORK_DIR)/html/AM-GlobalFunc.rsc
-# cd $(WORK_DIR)/html && $(WORK_DIR)/bin/commitinfo.sh $< > $<~
-# mv $<~ $<
+define rungit =
+ cd $(BUILD_DIR) && \
+ git
+endef
-#commitinfo: push
-# $(WORK_DIR)/bin/$@.sh
-#clean
+.PHONY: all checksums gitcheck commitinfo clean
+#$(COMMITINFO) gitcheck clean
+# docs rsc clean
-#checkout: git checkout HEAD .
+all: checksums commitinfo
+# $(COMMITINFO)
+# docs rsc
-#push:
-# git $@ origin
-
-#ifeq (git,$(firstword $(MAKECMDGOALS)))
-# # Remaining arguments form the commit string
-# GIT_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
-# # ...and turn them into do-nothing targets
-# $(eval $(GIT_ARGS):;@:)
-#endif
-
-# git function to push to repo
-#git:
-# git add . && git commit -m "$(GIT_ARGS)" && git push
+checksums: checksums.json
+checksums.json: bin/checksums.sh $(ALL_RSC)
+ bin/checksums.sh > html/$@
+#
+commitinfo: check-uncommitted
+ $(COMMITINFO)
+
+# ls -la bin
+# exit 0;
+
+# git add . \
+# git commit -m $(COMM_INFO) \
+# $(COMMITINFO)
+
+.PHONY: $(COMMITINFO)
+$(COMMITINFO): $(GLOB_FUNC)
+ $@ $< > $<~
+ mv $<~ $<
+
+
+
+gitcheck: check-uncommitted
+ $(COMMITINFO)
+
+#@if [ -n "$$(git diff --quiet)" ] && [ -n "$$(git diff --cached --quiet)" ] && [ -n "$$(git ls-files --others --exclude-standard)" ]; then \
+
+check-uncommitted:
+ @if [ -n "$$(git diff --quiet)" ] && [ -n "$$(git diff --cached --quiet)" ] && [ -n "$$(git status --porcelain)" ]; then \
+ echo "Warning: Uncommitted changes detected! Go to autocmmit..."; \
+ else \
+ echo "Repository is clean (no uncommitted or untracked changes). Exit."; \
+ exit 0; \
+ fi
+
+
+# if [[ -n "`$(rungit) status --porcelain`" ]];: then \
+ echo "Warning: Uncommitted changes detected! Go to autocmmit..."; \
+ git commit -m "$(COMM_INFO)"; \
+ git push origin $(COMM_BANCH); \
+ else \
+ echo "Repository is clean (no uncommitted or untracked changes). Exit 0."; \
+ exit 0; \
+ fi
+
+#check-uncommitted:
+# @echo "Warning: Uncommitted changes detected! Go to autocmmit...";
+# git add .
+# git commit -m $(COMMITINFO)
+# $@
+
+#.PHONY: check-uncommitted
+#check-uncommitted:
+fake_target:
+ @if git diff --quiet && git diff --cached --quiet && [ -z "$$(git ls-files --others --exclude-standard)" ]; then \
+ echo "Repository is clean (no uncommitted or untracked changes). Exit."; \
+ exit 0; \
+ else \
+ git add . && backcheck:; \
+ fi
+
+# echo $(shell git status --porcelain 2>/dev/null); \
+
+
+git-%:
+ ifeq ($(@:git-%=%), push)
+ git push origin $(BRANCH)
+ endif
+
+# git add . && \
+# commitinfo && \
+# git push origin $(BRANCH)
+# git commit -m "$(@:git-%=%)"
+
+clean:
+ cd $(HTML_DIR) && \
+ git checkout HEAD -- .
-#clean:
# rm -f $(HTML) checksums.json
-# make -C tmpl/ clean
+# make -C contrib/ clean
+++ /dev/null
-.bin/checksums.sh > checksums.json
-.bin/checksums.sh > checksums.json
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-.bin/checksums.sh > checksums.json
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.
-make: Nothing to be done for 'checksums'.