I'd say that most people should not write makefiles by hand. You should use some higher level build system, that knows how to deal with source files in your language, track their dependencies, etc. A "hello world" makefile with one source file looks simple, but once the project gets more complicated, you quickly end up building such a high level build system yourself, with the additional disadvantage of restricting y…
One line you should add to every makefile
21–30 of 99 posts
Re: One line you should add to every makefile
#22Re: One line you should add to every makefile
#23I'd say that most people should not write makefiles by hand. You should use some higher level build system, that knows how to deal with source files in your language, track their dependencies, etc. A "hello world" makefile with one source file looks simple, but once the project gets more complicated, you quickly end up building such a high level build system yourself, with the additional disadvantage of restricting y…
Makefiles, once you have learned the syntax, are very simple to write, as they can be naturally decomposed into individual steps, and rules are easily generalized for similar file types. Their reputation has been tarnished by autotools, but in that case you're using autotools as your build system, not make.
Re: One line you should add to every makefile
#24# make -V SOURCE_FILES
Re: One line you should add to every makefile
#25Re: One line you should add to every makefile
#26Re: One line you should add to every makefile
#27Better article from years ago, that this blogger is probably rehashing anyway: http://blog.melski.net/2010/11/30/makefile-hacks-print-the-v...
Nope.
Eric (who wrote that blog you are referrring to is a friend), but I wrote this little trick up years before him: http://www.cmcrossroads.com/article/printing-value-makefile-... and now I'm rehashing my own writing 10 years later.
Re: One line you should add to every makefile
#28 print-%: ; @echo $*=$($*)
include Makefile
Now you can use it the following way from any source directory: $ make -f ~/Makefile.debug print-SOURCE_FILESRe: One line you should add to every makefile
#29I'd say that most people should not write makefiles by hand. You should use some higher level build system, that knows how to deal with source files in your language, track their dependencies, etc. A "hello world" makefile with one source file looks simple, but once the project gets more complicated, you quickly end up building such a high level build system yourself, with the additional disadvantage of restricting y…
It may be my inexperience speaking, but every time I come across code that was built not by hand I visibly cringe and search for something else. It's not that it's bad, it's just that if I don't understand it then there is nothing for me to fix or play around with.
Re: One line you should add to every makefile
#30Earlier quoted context omitted.
Makefiles, once you have learned the syntax, are very simple to write, as they can be naturally decomposed into individual steps, and rules are easily generalized for similar file types. Their reputation has been tarnished by autotools, but in that case you're using autotools as your build system, not make.
The problem is that C/C++ files have internal depenedencies which make needs to know about. Yes, for gcc you can use a simple trick to extract the dependencies to makefile rules, but in case you use a different compiler, you need to do it yourself. If you are compiling a different language, you need to do it yourself again. Using something like CMake or even automake, which can automatically track the dependencies, s…