[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: targets in subdirectories
From: |
Kristof Provost |
Subject: |
Re: targets in subdirectories |
Date: |
Wed, 20 Jun 2007 06:51:06 +0200 |
User-agent: |
Thunderbird 1.5.0.12 (X11/20070604) |
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