How do you get the list of targets in a makefile?

后端 未结 20 1497
难免孤独
难免孤独 2020-11-30 16:50

I\'ve used rake a bit (a Ruby make program), and it has an option to get a list of all the available targets, eg

> rake --tasks
rake db:charset      # ret         


        
20条回答
  •  甜味超标
    2020-11-30 17:40

    My favorite answer to this was posted by Chris Down at Unix & Linux Stack Exchange. I'll quote.

    This is how the bash completion module for make gets its list:

    make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'
    

    It prints out a newline-delimited list of targets, without paging.

    User Brainstone suggests piping to sort -u to remove duplicate entries:

    make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}' | sort -u
    

    Source: How to list all targets in make? (Unix&Linux SE)

提交回复
热议问题