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
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.
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.
You can use qmake to generate Makefiles for a project even if that project is not using Qt.
With a more modern version of GCC, you can add the -MP flag to have GCC generate empty rules for the headers itself.
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 '$$'.
I must be missing something. Why doesn't generating dependency files work for you?