Depurando o Makefile / parte 2 /

Métodos de depuração



Nesta parte, falaremos sobre técnicas e problemas comuns de depuração. Em última análise, a depuração é uma mistura de tudo o que funciona em uma determinada situação. Esses métodos funcionam para mim e tenho que confiar neles mesmo em caso de problemas com os makefiles mais simples . Talvez eles ajudem você também.







Depurando o Makefile / parte 1 /







Um bug muito irritante no make



3.80 era a mensagem de erro no makefile , onde make



o número da linha e normalmente o número da linha estavam incorretos. Não me preocupei em investigar por que esse problema ocorre: por causa de arquivos importados, atribuições a variáveis ​​multilinhas ou por causa de macros personalizadas. Normalmente, make



dá um número de linha maior do que deveria. Em makefiles complexos , acontece que o número não coincide em 20 linhas.







Freqüentemente, a maneira mais fácil de ver o valor de uma variável é imprimi-la enquanto executa o destino. Embora seja fácil imprimir com ajuda warning



, a longo prazo pode economizar muito tempo e um pouco de esforço adicionando um alvo comum debug



para variáveis ​​de saída. Aqui está um exemplo de código de destino debug



:







debug:
       $(for v,$(V), \
         $(warning $v = $($v)))
      
      





, debug



:







$ make V="USERNAME SHELL" debug
makefile:2: USERNAME = Owner
makefile:2: SHELL = /bin/sh.exe
make: debug is up to date.
      
      





, MAKECMDGOALS



, V



:







debug:
       $(for v,$(V) $(MAKECMDGOALS), \
         $(if $(filter debug,$v),,$(warning $v = $($v))))
      
      





. , , make



( ) :







$ make debug PATH SHELL
makefile:2: USERNAME = Owner
makefile:2: SHELL = /bin/sh.exe
make: debug is up to date.
make: *** No rule to make target USERNAME. Stop.
      
      





make



, shell



. , , , . — :







DATE := $(shell date +%F)
OUTPUT_DIR = out-$(DATE)
make-directories := $(shell [ -d $(OUTPUT_DIR) ] || mkdir -p $(OUTPUT_DIR))
all: ;
      
      





sh



, :







$ make SHELL="sh -x"
+ date +%F
+ '[' -d out-2004-05-11 ']'
+ mkdir -p out-2004-05-11
      
      





, .







, , :







FIND_TOOL = $(firstword $(wildcard $(addsuffix /$(1).exe,$(TOOLPATH))))
      
      





. :







$(warning $(TOOLPATH))
$(warning $(addsuffix /$(1).exe,$(TOOLPATH)))
$(warning $(wildcard $(addsuffix /$(1).exe,$(TOOLPATH))))
      
      





, ( ) .









make



make



. . , , make



, , . .







make



:







    makefile:n: *** message. Stop
      
      





:







    make:n: *** message. Stop.
      
      





makefile — . — , , , , , .







, make



, , makefile . , - , - . , — . , make



.









: , , .







make



:







foo:
     for f in $SOURCES; \
     do                 \
        …               \
     done
      
      





, make



$S



, OURCES



f



. , f



, :







    OURCES: No such file or directory
      
      





. — .







missing separator



:







    makefile:2:missing separator. Stop.
      
      





( GNU make — .):







    makefile:2:missing separator (did you mean TAB instead of 8 spaces?). Stop.
      
      





make



, :, =, . , - .







commands commence before first target



makefile, ( ). make



, , , , make



.







unterminated variable reference



, . , . make



Lisp! , , Emacs.









: , , , .







" ", .







:







    bash: foo: command not found
      
      





, foo



. , PATH



. , PATH



, .profile (Bourne shell), .bashrc (bash) .cshrc (C shell). , PATH



makefile, PATH



make



.







, . , make



:







$ make
touch /foo/bar
touch: creating /foo/bar: No such file or directory
make: *** [all] Error 1
      
      





touch



, . — make



. makefile , . , , make



.







, @



. .







make



, make



.







No Rule to Make Target



:







    make: *** No rule to make target XXX. Stop.
      
      





:







    make: *** No rule to make target XXX, needed by YYY. Stop.
      
      





, make



XXX, make



. make



.







:







  • makefile . .
  • makefile — . make



    . makefile , . make



    .
  • , make



    - , , make



    . , make



    . — VCS. , make



    - , - . , .







    Overriding Commands for Target



    make



    ( «::» , ). , make



    :







    makefile:5: warning: overriding commands for target foo
          
          





    :







    makefile:2: warning: ignoring old commands for target foo
          
          





    , ; .









makefile , . , , .







, :







# Create a jar file.
$(jar_file):
        $(JAR) $(JARFLAGS) -f $@ $^
      
      





makefile . makefile:







# Set the target for creating the jar and add prerequisites
jar_file = parser.jar
$(jar_file): $(class_files)
      
      





Se você adicionar inadvertidamente um script de comando a tal makefile , um make



aviso de substituição será emitido.








All Articles