|
| Re: makefile question |
 |
Fri, 23 Nov 2007 12:13:45 -030 |
Helmut Giese wrote:
> Hello out there,
> seems like I forgot some of the finer points on using a makefile.
>
> I can create a list of .obj files from my source files
> # Create list of .obj files from C files
> COBJS = $(CSRCS:.c=.obj)
>
> and I know about implicit rules like
> # compile any C file
> .c.obj:
> $(CC) -c $(CCFLAGS) -o $@ $<
> which make for compact and easy to maintain makefiles.
> n
> Everything works well as long as source and .obj files share the same
> directory. However I would like to place my .obj files into a sub
> directory (say OBJ) - and I fail miserably when trying to adapt the
> above syntax to using different directories.
Let us assume that we have structure of project like this:
root
|
|----src
|
|----objs
Makefile is in root folder, source files are in src and object files
should go to objs.
Here is a working example with only one source file called main.c:
CSRCS=main.c
OBJS=$(CSRCS:.c=.obj)
OBJDIR=objs
SRCDIR=src
.path.c=$(SRCDIR)
.path.obj=$(OBJDIR)
all: main.exe
clean:
del $(OBJDIR)\*.obj
del main.*
main.exe: $(OBJS)
bcc32 $**
.c.obj:
bcc32 -c -o $@ $<
|
| Post Reply
|
| makefile question |
 |
Fri, 23 Nov 2007 14:37:28 +010 |
Hello out there,
seems like I forgot some of the finer points on using a makefile.
I can create a list of .obj files from my source files
# Create list of .obj files from C files
COBJS = $(CSRCS:.c=.obj)
and I know about implicit rules like
# compile any C file
.c.obj:
$(CC) -c $(CCFLAGS) -o $@ $<
which make for compact and easy to maintain makefiles.
Everything works well as long as source and .obj files share the same
directory. However I would like to place my .obj files into a sub
directory (say OBJ) - and I fail miserably when trying to adapt the
above syntax to using different directories.
I am near to certain that (many) years ago I knew how to achieve this
and so I think that it is possible.
Any tips will be greatly appreciated.
Best regards
Helmut Giese
|
| Post Reply
|
| Re: makefile question |
 |
Fri, 23 Nov 2007 15:34:59 +010 |
Helmut Giese wrote:
> Everything works well as long as source and .obj files share the same
> directory. However I would like to place my .obj files into a sub
> directory (say OBJ) - and I fail miserably when trying to adapt the
> above syntax to using different directories.
I did just that yesterday. My solutions looks like this:
.AUTODEPEND
.path.h = .\headers
.path.c = .\source
.path.obj = .\output
OBJFILES=file01.obj file02.obj
.c.obj:
$(CC) -c $(CCFLAGS) -o $@ $<
main: target.exe
target.exe: $(OBJFILES)
<link command - use $** to get expanded list of obj-files>
No need for a list of source files as these are inferred from the list of
object files.
Ebbe
|
| Post Reply
|
| Re: makefile question |
 |
Fri, 23 Nov 2007 17:20:37 +010 |
Thanks Ebbe and Darko,
I had all forgotten about the 'path' directive.
Have a nice weekend and best regards
|
| Post Reply
|
|
|
|
|
|
|
|
|
|