Gnu Makefile - Handling dependencies

后端 未结 12 2503
滥情空心
滥情空心 2021-02-07 20:24

What approach do C++ programmers on Unix platform use to create and manage Makefiles?

I was using hand made Makefiles for my projects but they don\'t handle header file

相关标签:
12条回答
  • 2021-02-07 20:44

    Instead of the sed scripts, use gcc's -MT option to modify the target of the generated dependency rules. This blog post has more info.

    0 讨论(0)
  • 2021-02-07 20:44

    In Mozilla's build system, we use GCC's -MD switch to generate the dependency files: http://mxr.mozilla.org/mozilla-central/source/configure.in#7134 and then we use a script called mddepend.pl to check for removed header files, such that removing a header simply causes a rebuild, not an error: http://mxr.mozilla.org/mozilla-central/source/config/rules.mk#2066 http://mxr.mozilla.org/mozilla-central/source/build/unix/mddepend.pl

    That script generates an .all.pp file containing all the dependencies, with extra foo.o: FORCE dependencies stuck in for missing header files. We then simply -include the .all.pp file in rules.mk right below there.

    0 讨论(0)
  • 2021-02-07 20:46

    You can use qmake to generate Makefiles for a project even if that project is not using Qt.

    0 讨论(0)
  • 2021-02-07 20:49

    With a more modern version of GCC, you can add the -MP flag to have GCC generate empty rules for the headers itself.

    0 讨论(0)
  • 2021-02-07 20:52
    1. I use that approach too and can't praise it highly enough. And I write my makefiles by hand and reuse them a lot on new projects.
    2. .The expression "s/ *\\$//" will work outside the context of Make. Within a makefile it doesn't work because Make tries to interpret "$/" before handing the result to the shell. So you must use "s/ *\\$$//" (note the extra $) within the makefile, but this won't work outside the context of Make (so testing it is a slight pain).



    EDIT:

    I've tried your makefile, and that sed statement seems to remove trailing backslashes just fine. Try something simpler, like this:

    backslash:
        @echo " \\" > $@
    
    test: backslash
        @echo without sed:
        @cat backslash
        @echo with sed:
        @sed -e 's/ *\\$$//' < backslash
    



    EDIT: All right, now I'm hooked. Could you try these experiments and tell us the results?

    Change the last character to 'z'      :  s/.$/z/
    Change a trailing backslash to 'z'    :  s/\\$/z/
    Change a trailing backslash to 'z'    :  sm\\$mzm
    Delete a trailing backslash           :  s/\\$//
    Delete spaces and a trailing backslash:  s/ *\\$//
    Try all of these inside and outside of Make, with '$' and '$$'.
    
    0 讨论(0)
  • 2021-02-07 20:53

    I must be missing something. Why doesn't generating dependency files work for you?

    0 讨论(0)
提交回复
热议问题