ysyx-workbench/Makefile

45 lines
1.7 KiB
Makefile
Raw Normal View History

2022-02-21 04:22:27 +00:00
STUID = ysyx_22040000
STUNAME = 张三
# DO NOT modify the following code!!!
2022-03-08 02:50:24 +00:00
TRACER = tracer-ysyx2204
GITFLAGS = -q --author='$(TRACER) <tracer@ysyx.org>' --no-verify --allow-empty
2022-02-21 04:22:27 +00:00
2022-03-08 02:50:24 +00:00
YSYX_HOME = $(NEMU_HOME)/..
WORK_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
WORK_INDEX = $(YSYX_HOME)/.git/index.$(WORK_BRANCH)
2022-03-08 02:50:24 +00:00
TRACER_BRANCH = $(TRACER)
2022-02-25 09:45:35 +00:00
LOCK_DIR = $(YSYX_HOME)/.git/
# prototype: git_soft_checkout(branch)
define git_soft_checkout
git checkout --detach -q && git reset --soft $(1) -q && git checkout $(1) -q
endef
2022-02-21 04:22:27 +00:00
# prototype: git_commit(msg)
define git_commit
-@flock $(LOCK_DIR) $(MAKE) -C $(YSYX_HOME) .git_commit MSG='$(1)'
2022-02-21 04:22:27 +00:00
-@sync
endef
.git_commit:
-@while (test -e .git/index.lock); do sleep 0.1; done; `# wait for other git instances`
-@git branch $(TRACER_BRANCH) -q 2>/dev/null || true `# create tracer branch if not existent`
-@cp -a .git/index $(WORK_INDEX) `# backup git index`
-@$(call git_soft_checkout, $(TRACER_BRANCH)) `# switch to tracer branch`
-@git add . -A --ignore-errors `# add files to commit`
-@(echo "> $(MSG)" && echo $(STUID) $(STUNAME) && uname -a && uptime `# generate commit msg`) \
| git commit -F - $(GITFLAGS) `# commit changes in tracer branch`
-@$(call git_soft_checkout, $(WORK_BRANCH)) `# switch to work branch`
-@mv $(WORK_INDEX) .git/index `# restore git index`
.clean_index:
rm -f $(WORK_INDEX)
2022-02-21 04:22:27 +00:00
_default:
@echo "Please run 'make' under subprojects."
.PHONY: .git_commit .clean_index _default