LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   a strange make rule (https://www.linuxquestions.org/questions/programming-9/a-strange-make-rule-477741/)

George2 08-27-2006 05:03 AM

a strange make rule
 
Hello everyone,


Here is a sample make file.

SRC=foo.c
PROC=$(SRC:%.c=%.o)
TARGET=$(PROC:%.o=$(TARGET_DIR)/%.o)

I know the first two lines mean compile *.c defined in SRC to *.o. But what does the 3rd line mean? Convert *.o generated by PROC to *.o? I am confused that why convert *.o to *.o itself?


thanks in advance,
George

tuxdev 08-27-2006 09:34 AM

Note the "$(TARGET_DIR)". Many build systems want the object files in a seperate directory because then the object files aren't cluttering up the src directory. It is easier to work in the source when you don't have object files around. "make clean" is really simple too.

George2 08-28-2006 02:52 AM

Thank you tuxdev,


Quote:

Originally Posted by tuxdev
Note the "$(TARGET_DIR)". Many build systems want the object files in a seperate directory because then the object files aren't cluttering up the src directory. It is easier to work in the source when you don't have object files around. "make clean" is really simple too.

I have also made some tests on this case. I think in my case, TARGET macro simply prefix $(TARGET_DIR) to each string items in PROC macro. Am I correct?


regards,
George

tuxdev 08-28-2006 12:30 PM

That is what I think it does as well. I'm not entirely certain about the make-foo, but it makes sense. I have yet to find decent online docs with an explanation of all the neat make features nobody knows about.


All times are GMT -5. The time now is 07:54 PM.