On Sun, 2023-03-05 at 04:13 +0800, ljh wrote: > 1. In thie out of source version, I can not omit recipes in both > building and linking rules. This make it a bit complicated.
I'm not sure I understand the problem. If the question is, is there a way to use the normal built-in implicit rules for makefiles so you don't have to add your own implicit rules, while still writing targets to a different directory then the answer is "no". If you want to write targets to some non-local directory you MUST create your own implicit rules. The only way to have targets written to a different directory from sources AND still use the built-in implicit rules, is to invoke make in the object directory, not the source directory. Then you can write targets to the current directory, and use VPATH to locate sources in some other directory. > 2. if I put # comment at the end of the line of export OBJDIR, it > causes mysterious error message in rules involve the variable. In makefiles, whitespace BEFORE the start of a value in an assignment is stripped. But whitespace AFTER the end of a value in an assignment is not stripped, it's preserved. So this line: A = B# this is some value Sets the variable "A" to the value "B". But this line: A = B #this is some value Sets the variable "A" to the value "B " (note the space). In general it's a bad idea to use inline comments in makefiles, particularly in variable assignments.