Estoy tratando de escribir una función make para tocar/crear un archivo vacío y/o configurar los permisos, usuario y grupo, donde sea posible, o advierta si no. Sin embargo, cada comprobación condicional dentro de mi función parece evaluar a verdadera.
Lo esencial de mi Makefile son
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
Correr make test
salidas
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)
he considerado/probado los siguientes:
- $ (si ...) se evaluado en "tiempo de compilación", antes de llamar a la función con un parámetro. Sin embargo, el código
ifeq "foo" "bar"
codificado también da un resultado inválido. Además,$(info ...)
evalúa correctamente$(fileName)
en "tiempo de compilación". - El documentation en realidad no da ejemplos, por lo que además de
$(if ifeq...)
, también intenté$(ifeq ...)
, que parecía ser ignorado. - "No funcional"
if
(es decir, elifeq
sin el$(if...)
) dentro de una función da/bin/sh: ifeq: command not found
.
¿Alguien puede ayudar a identificar por qué mis condicionales no se comportan como esperaba (o por qué estoy esperando algo equivocado)?
Advertencia: Sé que todavía hay errores por resolver si el archivo no existe, pero eso debería ser trivial en comparación con este obstáculo.
El sitio web de GNU, aunque se ve bien, es tan breve que casi no tiene sentido, ¿verdad? Ellos le dirán que existe una función, y luego no le darán ningún ejemplo sobre cómo usarla, para hostigarlo con ella. – Xennex81