0

I want to compile my source files twice with different flags each time. Besides that I need to have these executables which I'll acquire after the compilation in different directories (so I want 'make' to create two folders and put into every folder an executable).

I think that them main problem is that I don't know how to main object files. Think that we can create them with different names (because every set of .o files should somehow differ from the another which has different flags) or put them in the directories where we want to have executables.

Still I have no idea how to do it in elegant way :/

Any help greatly appreciated :)

Randy Howard
  • 2,165
  • 16
  • 26
Hubert Siwkin
  • 385
  • 3
  • 16
  • 1
    Are you asking what to do (e.g. give the object files different names or put them in those two directories), or how to get Make do it? (I'd recommend putting the object files in those two directories.) – Beta Apr 02 '13 at 13:49
  • Some of the ideas in this question might be what you are looking for. http://stackoverflow.com/questions/8280963/makefile-to-compile-multiple-sources-with-different-flags?rq=1 Question as is could use more detail. – Randy Howard Apr 02 '13 at 15:21
  • So now my question is how to force Make to put the .o files into those two directories :) – Hubert Siwkin Apr 02 '13 at 16:37

1 Answers1

0

You haven't given us many details, so I'll suppose you have two source files, foo.c and bar.c, and you're building in two directories, red/ and blue/. Here is a crude makefile that will do the job:

OBJS := foo.o bar.o
RED_OBJS := $(addprefix red/,$(OBJS))
BLUE_OBJS := $(addprefix blue/,$(OBJS))

$(RED_OBJS): red/%.o : %.c
    $(CC) -c $< -o $@

$(BLUE_OBJS): blue/%.o : %.c
    $(CC) -c $< -o $@

red/red_exec: $(RED_OBJS)
    $(CC) $< -o $@

blue/blue_exec: $(BLUE_OBJS)
    $(CC) $< -o $@
Beta
  • 96,650
  • 16
  • 149
  • 150