tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Automatic dependencies, .o files in separate directories.



Hello,

   I'm trying to get creative with makefiles, but I'd like to understand
some make behaviors and know if there's a way to work around them. See
attached example files.

   What happens is that if /tmp/.depend doesn't exist, it will be
created but make fails. I understand why this happens (.sinclude can't
open the file on first pass, so it never gets read). If ".include" is
use instead of ".sinclude", make will simply bail without even trying
(which also makes sense).

   On next run, make attempts to *link*. So it appears that it's
including "/tmp/.depend", but it doesn't use the .c.o rule to build the
object files. Back in the OS/2 days, I remember that I had to add a
syntax along the line of "{path\to\files}.c.o:" for rules which applied
to other directories than the current. I don't know if it's a related
issue here, but it sort of behaves like it.

   Questions:
   1) Is is possible to get make to *create and use* a dependency file
on one run?
   2) Why isn't make applying the .c.o rule to the files in the
/tmp/.depend file? Is it because the targets are in a separate directory?

-- 
Kind regards,
Jan Danielsson

void bar(void)
{
}

/* vim: set filetype=c et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :*/

/* vim: set filetype=cpp et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :*/

#include <stdio.h>
#include "foo.h"

int main(void)
{
  return 0;
}

/* vim: set filetype=c et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :*/
/* vim: set filetype=cpp et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :*/

.SUFFIXES: .c .o

.c.o:
        clang -c -o ${.TARGET} ${.IMPSRC}

SRCS=foo.c bar.c

all: /tmp/.depend /tmp/foo

/tmp/.depend: .META
        @mkdep -f /tmp/.depend.${.MAKE.PID} -- ${CFLAGS:C/-([IDU])[  
]*/-\1/Wg:M-[IDU]*} $(SRCS)
        @sed "s/^\([^ ]\)/\/tmp\/\1/" \
                /tmp/.depend.${.MAKE.PID} > /tmp/.depend
        @rm /tmp/.depend.${.MAKE.PID}

.sinclude "/tmp/.depend"

/tmp/foo: /tmp/foo.o /tmp/bar.o
        clang -o /tmp/foo /tmp/foo.o /tmp/bar.o

clean: .PHONY
        -rm .depend /tmp/foo /tmp/foo.o /tmp/bar.o



Home | Main Index | Thread Index | Old Index