折腾:
【已解决】写Makefile实现commit提交文件到github.io仓库
期间,想要实现:
makefile中,输入make 传递参数到某个变量中
且如果没有传递参数的话 变量使用默认值
关于传递参数,之前已经看到了:
make – Git commit from within a Makefile – Unix & Linux Stack Exchange
这个不错,传递参数:
git:
git commit -m “$m”
make git m=”My comment”
对于变量默认的值,好像是用问号?
去确认一下
makefile variable default value
bash – Define a Makefile variable using a ENV variable or a default value – Stack Overflow
是用问号 ?=
GNU make – How to Use Variables
期间先去:
【已解决】Makefile中变量赋值时冒号加等号:=是什么含义
然后其中也就说了:
“There is another assignment operator for variables, `?=’. This is called a conditional variable assignment operator, because it only has an effect if the variable is not yet defined. This statement:
FOO ?= bar
is exactly equivalent to this (see section The origin Function):
ifeq ($(origin FOO), undefined)
FOO = bar
endif
Note that a variable set to an empty value is still defined, so `?=’ will not set that variable.”
所以,可以去试试了
【已解决】Makefile的make时传递参数的值中包含双引号
【总结】
然后就可以使用:
################################################################################
# Commit to github
################################################################################
m ?= “1. update book $(BOOK_NAME)”
GITHUB_IO_PATH=/Users/crifan/dev/dev_root/github/github.io/crifan.github.io
## Commit generated files to github io
commit: all
rsync -avzh –progress –stats –delete –force $(OUTPUT_PATH) $(GITHUB_IO_PATH)
cd $(GITHUB_IO_PATH) && \
pwd && \
ls -la && \
git status && \
git add $(BOOK_NAME)/* && \
git status && \
git commit -m $(m) && \
git status && \
git push && \
cd $(CURRENT_DIR) && \
pwd
实现:
(1)当make没有传递m参数时:
make commit
此处m值为:”1. update book http_summary”
(2)当make时传递m参数的值了:
make commit m='”1. update http summary book”
则m的值就是自己定义的值:
“1. update http summary book”
了 -》 后续
git commit -m
就可以获取到make传入到自定义comment的值了。