gcc output directory for submakes

I`m having a makefile with Sub makes. I want to place the Output of the submakes in one Directory. Can anyone explain me how to do this right?

-root |
      |-stub
      |-test
      |-source
      |-out
      |-makefile

all of my submakes shall place their *.o files in out. I`m getting Errors there is no File or Directory ./out/**.o if i add ../out to the Objectfile.

here is my submakefile

# makefile to generate UNIT-tests
# sub makefile for location stub


# define any directories containing header files other than /usr/include
# TODO 


# define any libraries to link into executable:
#	if I want to link in libraries (libx.so or libx.a) I use the -llibname 
#	option, something like (this will link in libmylib.so and libm.so:
LIBS = 

#  TODO define the C source files
SRCS = $(STUBS)

# define the C object files 
#
# This uses Suffix Replacement within a macro:
#	$(name:string1=string2)
#		  For each word in 'name' replace 'string1' with 'string2'

ODIR=../out

OBJ = $(SRCS:%.c=%.o)

# define the C compiler to use
CC = gcc
# define any compile-time flags

#compile without link
CFLAGS = -O0 -Wall -c -g -fmessage-length=0 -fprofile-arcs -ftest-coverage 				
#TODO Linkerflags
LFLAGS = --coverage 

# define the executable file,


all: $(TARGET) $(OBJ)	
	$(CC) $(OBJ) $(CFLAGS) -o $(TARGET) $(LFLAGS) $(OBJ) 
	
	@echo +++ build of stub finished +++
	
	
	
clean:
		$(RM) *.o *~ $(MAIN)

# DO NOT DELETE THIS LINE -- make depend needs it


Source: gcc

Leave a Reply