का मूल्यांकन करता है, मैं एक खाली फ़ाइल को स्पर्श/बनाने/या अनुमतियों, उपयोगकर्ता और समूह को सेट करने के लिए एक मेक फ़ंक्शन लिखने की कोशिश कर रहा हूं, जहां संभव हो, या चेतावनी अगर चेतावनी दी। हालांकि, मेरे फ़ंक्शन के भीतर प्रत्येक सशर्त जांच सत्य का मूल्यांकन करती है।/कोशिश की
मेरी Makefile के अनिवार्य
INSTALL_USER := fileUser
INSTALL_GROUP := fileGroup
.PHONY: test
test:
$(call touchFile,~/test.ini)
define touchFile
$(eval fileName := $(strip $(1)))
-touch $(fileName)
-chmod -c 664 $(fileName)
$(info filename info $(fileName))
$(info $(shell stat -c "%a %U:%G" $(fileName)))
$(if ifeq "foo" "bar", @echo match is broken, @echo match works)
$(if ifneq "foo" "bar", @echo match works, @echo match is broken)
$(if ifneq ($(shell stat -c %a $(fileName)),664), $(warning Error - $(fileName) does not have expected permissions of 664))
-chgrp -c $(INSTALL_GROUP) $(fileName)
$(if ifneq ($(shell stat -c %G $(fileName)),$(INSTALL_GROUP)), $(warning Error - $(fileName) does not belong to $(INSTALL_GROUP) group))
-chown -c $(INSTALL_USER) $(fileName)
$(if ifneq ($(shell stat -c %U $(fileName)),$(INSTALL_USER)), $(warning Error - $(fileName) does not belong to $(INSTALL_USER) user))
endef
make test
आउटपुट
filename info ~/test.ini
664 myUserName:myGroup
Makefile:7: Error - ~/test.ini does not have expected permissions of 664
Makefile:7: Error - ~/test.ini does not belong to common group
Makefile:7: Error - ~/test.ini does not belong to netserve user
touch ~/test.ini
chmod -c 664 ~/test.ini
match is broken
match works
chgrp -c fileGroup ~/test.ini
changed group of `/home/myUserName/test.ini' to fileGroup
chown -c fileUser ~/test.ini
chown: changing ownership of `/home/myUserName/test.ini': Operation not permitted
make: [test] Error 1 (ignored)
मैं माना जाता है चल रहे हैं निम्नलिखित:
- $ (अगर ...) है फ़ंक्शन को पैरामीटर के साथ बुलाए जाने से पहले, "संकलन-समय" पर मूल्यांकन किया जाता है। लेकिन, हार्ड-कोडेड
ifeq "foo" "bar"
भी एक अवैध परिणाम देता है। इसके अतिरिक्त,$(info ...)
"संकलन-समय" पर$(fileName)
का सही मूल्यांकन करता है। - documentation वास्तव में उदाहरण नहीं देता है, इसलिए
$(if ifeq...)
के अलावा, मैंने$(ifeq ...)
भी कोशिश की, जिसे अनदेखा किया गया। - "गैर-कार्यात्मक"
if
(यानीifeq
बिना$(if...)
) फ़ंक्शन के अंदर/bin/sh: ifeq: command not found
देता है।
क्या कोई यह पहचानने में सहायता कर सकता है कि मेरी सशर्तताएं क्यों व्यवहार नहीं कर रही हैं (या मैं गलत चीज़ की अपेक्षा क्यों कर रहा हूं)?
चेतावनी: मुझे पता है कि फ़ाइल मौजूद नहीं है, लेकिन यह बाधा की तुलना में छोटी होनी चाहिए, लेकिन यह बाधाओं की तुलना में तुच्छ होना चाहिए।
जीएनयू वेबसाइट, हालांकि यह अच्छी लगती है, यह लगभग निर्बाध होने के लिए इतनी संक्षिप्त है, है ना। वे आपको बताएंगे कि एक फ़ंक्शन मौजूद है, और फिर आपको इसका उपयोग करने के तरीके पर कोई उदाहरण नहीं दिया गया है, ताकि आप इसे परेशान कर सकें। – Xennex81