Depuración de GNU make


¿Hay una forma de línea de comandos en make para averiguar cuál de los requisitos previos de un destino no se actualiza?

Author: Mateusz Piotrowski, 2009-11-17

7 answers

make -d

Debería darte más que suficiente información para depurar tu makefile.

Tenga cuidado: tomará algún tiempo y esfuerzo analizar la salida, pero cargar la salida en su editor favorito y hacer búsquedas le ayudará mucho.

Puede reducir en gran medida la cantidad de salida de depuración si especifica el destino específico que le interesa. Así que si solo estás interesado en el objetivo dodgy, en lugar de solo make -d que puede hacer un centenar de diferentes cosas, prueba:

make clean
make -d dodgy

(asumiendo que tienes un objetivo clean por supuesto).

El make --debug es idéntico a make -d pero también puede especificar:

make --debug=FLAGS

Dónde pueden estar las banderas:

  • a para todas las depuraciones (lo mismo que make -d y make --debug).
  • b para depuración básica.
  • v para una depuración básica ligeramente más detallada.
  • i para reglas implícitas.
  • j para información de invocación.
  • m para información durante makefile remakes.

Parece que make --debug=b es la mejor opción para lo que necesita, como se muestra en la siguiente transcripción:

pax@paxbox> cat makefile
c:a b
    touch c

pax@paxbox> touch a b ; make
touch c

pax@paxbox> make
make: 'c' is up to date.

pax@paxbox> touch a ; make --debug=b
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc. Blah, blah, blah.
Reading makefiles...
Updating goal targets....
 Prerequisite 'a' is newer than target 'c'.
Must remake target 'c'.
touch c
Successfully remade target file 'c'.
 91
Author: paxdiablo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-11-17 01:42:37

¿Estás buscando el "simulacro" de Make? Imprimirá lo que make está haciendo sin hacerlo realmente, lo que le permitirá ver lo que sucede.

La bandera es -n, úsala como make -n.

 19
Author: LiraNuna,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-11-17 01:03:44

Su pregunta es un poco confusa. Si desea ver qué archivos de requisitos previos no se han modificado recientemente, utilice ls-l para ver su hora de modificación. Si quieres ver lo que hace make, prueba esto:

# Make will announce when it is making this target, and why.
sometarget: preq1 preq2 preq3
    @echo making $@
    @echo The following preqs are newer than the target: $?
    do_things
 7
Author: Beta,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-11-17 01:11:30

También está GNU make con un depurador y una mejor salida de trace / error: Remake

screencast: http://showmedo.com/videotutorials/video?name=linuxBernsteinMakeDebug1&fromSeriesID=40

 7
Author: rocky,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-11-07 21:51:34

Lo que normalmente hago es no usar-d como dijeron los que respondieron anteriormente.

O bien:

  1. Use-p para imprimir la base de datos, para ver qué reglas se han creado. Esto es útil si tiene reglas de segunda expansión y está creando reglas sobre la marcha, especialmente la marca recursiva.
  2. Uso intensivo de la función info(info).
  3. Utilice los consejos y trucos descritos en este artículo de DrDobbs Depurar Makefiles

A continuación se muestra un código que estoy usando para imprimir valores:

define pv
$(info $(1) [$(origin $(1))] : >|$($(1))|<)
endef

define pva
$(foreach t,$(1),$(call pv,$(t)))
endef

define itemizer
$(foreach t,$($(1)),$(info $(t)))
endef
 6
Author: George André,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-16 09:33:21

Algunas veces también he usado este (viejo pero todavía funciona) interactivo make debugger por John Graham-Cumming

 1
Author: Alex,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-08-23 10:00:23

Estoy usando plantillas make gnu make para definir las reglas make por destino;

Las plantillas son como macros que escriben reglas, se explican aquí https://www.gnu.org/software/make/manual/html_node/Eval-Function.html

Esta característica es útil cuando tiene un sistema make que incluye un makefile principal para generar todas las reglas por tipo de proyecto; si dice hacer una biblioteca compartida, entonces escribe las reglas para compilar una biblioteca compartida; etc. para otros tipos de objetivo.

En este ejemplo: si agrega SHOW_RULES=1 a la línea de comandos make, también muestra el texto de las reglas generadas por el PROGRAM_target_setup_template ; junto con la generación de las reglas mismas (con eval).

 # this one defines the target for real
 $(foreach prog, $(TARGETS), $(eval $(call PROGRAM_target_setup_template,$(prog))))

 ifneq "$(SHOW_RULES)" ""
 $(foreach prog, $(TARGETS), $(info $(call PROGRAM_target_setup_template,$(prog))))
 endif
  • call (call... ) invoca la plantilla
  • info (info ... ) imprime el resultado de la sustitución de la plantilla; (eval habría invocado el análisis de la salida y la adición al archivo make actual)

Más sobre mis archivos make aquí: http://mosermichael.github.io/cstuff/all/projects/2011/06/17/make-system.html

 0
Author: MichaelMoser,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-20 11:55:58