help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: targets in subdirectories


From: kilgore trout
Subject: Re: targets in subdirectories
Date: Wed, 20 Jun 2007 06:29:00 -0700 (PDT)



Date: Wed, 20 Jun 2007 06:23:20 -0700 (PDT)
Subject: Re: targets in subdirectories


Thank you for the reply!
However, I still don't understand something.
 
my rule is:
 
$(BUILD_DIR)/%.o : %.c
      mkdir -p $(BUILD_DIR)            ;  \
      $(CC) $(CFLAGS) $< -o $@    ; \
      echo $(BUILD_DIR)/$@ >> $(BUILD_DIR)/objlist.txt ;
 
(the last line is irrelevant for the current problem, but included just to be complete).
 
When the commands are echoed to the console, $@ expands to CAN_init.o rather than c:/ashell/trunk/ashell/build_dir/CAN_init.o  (where $(BUILD_DIR) is c:/ashell/trunk/ashell/build_dir ).  So that the compiler output is put in the local (current) directory rather than $(BUILD_DIR)/CAN_init.o .
 
Also, the rule doesn't seem to care about the object files in the $(BUILD_DIR) -- if the local versions are present, then make believes it has no more work to do.
 
My _intent_ is to keep the object files only in the $(BUILD_DIR) and have them dependent on the source files which are in a different directory.  Sorry for being so dense, but I don't see how to do that..
 
 
Thanks for your help.  (I'll try to post this to the list as well, which is probably the correct way:).
 
-kt.
 


kilgore trout wrote:
> Greetings,
>
> I am using gmake via Msys on a win xp box.
> The project that I am trying to build, has a 'build_dir' off of the
> root of the project tree which is where I am to keep all the object
> files. I am having a problem writing a rule that will correctly
> detect if that file is missing/up-to-date. I have, for example:
>
> BUILD_DIR=$(PROJ_ROOT)/build_dir
>
> $(BUILD_DIR)/%.o : %.c
> mkdir -p $(BUILD_DIR)
> $(CC) $(CFLAGS) $< -o $@
> mv $@ $(BUILD_DIR)
>
> but it will build if the .o files are missing from the local dir, and
> then not copy to the build_dir.
> If I remove the $(BUILD_DIR) from the rule, it will always rebuild the
> .o files, and copy them.
>
> What am I missing? Can I not include a path in a target rule? How
> can I (properly) do this?
>
> Any and all help appreciated!
>
> -kt.
>
$@ is the full target, so it already includes $(BUILD_DIR). That means
your last line expands to mv $(BUILD_DIR)/%.o $(BUILD_DIR).
If you remove $(BUILD_DIR) from the target your rule will not generate
what it promises (because it moves the output to $(BUILD_DIR)). That's
why he will regenerate the .o file every time.

Kristof



reply via email to

[Prev in Thread] Current Thread [Next in Thread]