On Sun, May 3, 2009 at 11:25 AM, t-timmy <[email protected]> wrote: > I want to name each of my object files prefixed with the current target > name. That way when I change targets, I won't have to recompile everything to > make sure there is no residue from the previous compilation (which may have > been > for a different target). > > For example: > > target1: c_flags = -DSOMETHING > target1: main.o > > target2: c_flags = -DSOMETHING_ELSE > target2: main.o > > main.o: > gcc $(c_flags) etc...
No, that isn't an example of what you want, because that doesn't use prefixes like you want. As is, you didn't give us enough to go on. You don't show any rules for linking programs, so saying "make target1" will compile main.o but *not* create a program from it, which is almost certainly not what you want, but we can't tell whether "make target1" should build a program "target1" from main.o or whether it should build "target1-someprogram" from main.o Next, you show main.o with an explicit rule. Really? You give each .o an explicit rule instead of using pattern rules? Why? If you actually have a real reason to do that (how can we tell?) then that'll affect what solutions are appropriate. > The only way I can avoid recompiling every time is by manually making a rule > for, let's say, target1-main.o and target2-main.o, but I have a lot of > source files and it's a real hassle. Make give you at least two different ways to let you use the same rule for the two targets. You almost certainly only one of the following; you'll need to decide which though the former is probably simpler. 1) target-specific variable assignments. As described in the info pages, such a setting is propagated to all the prerequisites of the target, so setting CFLAGS for target1 will mean that it'll be set for the files target1 depends on...which would presumably be things like target1-main.o 2) automatic variables. These are the variables like $@ and $^ that are set for you by make with values that depend on the rule involved. You can use the same rule for both target1-main.o and target2-main.o and example $@ in the commands to figure out which settings to use. Philip Guenther _______________________________________________ Help-make mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-make
