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

后端 未结 20 1463
难免孤独
难免孤独 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条回答
  •  萌比男神i
    2020-11-30 17:40

    I combined these two answers: https://stackoverflow.com/a/9524878/86967 and https://stackoverflow.com/a/7390874/86967 and did some escaping so that this could be used from inside a makefile.

    .PHONY: no_targets__ list
    no_targets__:
    list:
        sh -c "$(MAKE) -p no_targets__ | awk -F':' '/^[a-zA-Z0-9][^\$$#\/\\t=]*:([^=]|$$)/ {split(\$$1,A,/ /);for(i in A)print A[i]}' | grep -v '__\$$' | sort"
    

    .

    $ make -s list
    build
    clean
    default
    distclean
    doc
    fresh
    install
    list
    makefile ## this is kind of extraneous, but whatever...
    run
    

提交回复
热议问题