Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 4 Apr 2003 02:03:35 +0200
From:      Dimitry Andric <dim@xs4all.nl>
To:        Pawel Jakub Dawidek <nick@garage.freebsd.pl>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Bug in make(1)?
Message-ID:  <18441906438.20030404020335@xs4all.nl>
In-Reply-To: <20030403212300.GL54604@garage.freebsd.pl>
References:  <20030403212300.GL54604@garage.freebsd.pl>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
On 2003-04-03 at 23:23:00 Pawel Jakub Dawidek wrote:

> IMHO make(1) should put .o files in current directory _and_ look for
> them there when producing an executable file. Right?

I think this is more of a gcc/g++ problem/feature. :)  The info page
says:

     If `-o' is not specified, the default is to put an executable file
     in `a.out', the object file for `SOURCE.SUFFIX' in `SOURCE.o', its
     assembler file in `SOURCE.s', and all preprocessed C source on
     standard output.

So at first glance I would say: "gcc -c some/weird/path/file.c"
outputs the file "some/weird/path/file.o".  But it doesn't, it puts
the object file in the current directory...  This is probably a
feature, and if you change it, I guess a lot of stuff will break. :)

Therefore, the simplest solution is to specify -o options everywhere.
I've attached a patch for /usr/share/mk/sys.mk that does this, but
please beware, it might break stuff which *expects* output files to
always be put in the current directory.

OTOH, make(1) itself seems to be consistent with relative pathnames;
if you tell it a rule to create .b files from .a files, it will
correctly try to use that rule to convert some/path/file.a into
some/path/file.b (and NOT ./file.b).

[-- Attachment #2 --]
--- /usr/share/mk/sys.mk.org	Thu Apr  3 01:07:57 2003
+++ /usr/share/mk/sys.mk	Fri Apr  4 01:43:10 2003
@@ -113,10 +113,10 @@
 
 # SINGLE SUFFIX RULES
 .c:
-	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
+	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} -o ${.TARGET}
 
 .f:
-	${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
+	${FC} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} -o ${.TARGET}
 
 .sh:
 	cp ${.IMPSRC} ${.TARGET}
@@ -125,10 +125,10 @@
 # DOUBLE SUFFIX RULES
 
 .c.o:
-	${CC} ${CFLAGS} -c ${.IMPSRC}
+	${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
 
 .f.o:
-	${FC} ${FFLAGS} -c ${.IMPSRC}
+	${FC} ${FFLAGS} -c ${.IMPSRC} -o ${.TARGET}
 
 .y.o:
 	${YACC} ${YFLAGS} ${.IMPSRC}
@@ -151,12 +151,12 @@
 	mv lex.yy.c ${.TARGET}
 
 .c.a:
-	${CC} ${CFLAGS} -c ${.IMPSRC}
+	${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
 	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
 	rm -f ${.PREFIX}.o
 
 .f.a:
-	${FC} ${FFLAGS} -c ${.IMPSRC}
+	${FC} ${FFLAGS} -c ${.IMPSRC} -o ${.TARGET}
 	${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
 	rm -f ${.PREFIX}.o
 
@@ -172,32 +172,32 @@
 	${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
 
 .c.o:
-	${CC} ${CFLAGS} -c ${.IMPSRC}
+	${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
 
 .cc .cpp .cxx .C:
 	${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
 
 .cc.o .cpp.o .cxx.o .C.o:
-	${CXX} ${CXXFLAGS} -c ${.IMPSRC}
+	${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
 
 .m.o:
-	${OBJC} ${OBJCFLAGS} -c ${.IMPSRC}
+	${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
 
 .p.o:
-	${PC} ${PFLAGS} -c ${.IMPSRC}
+	${PC} ${PFLAGS} -c ${.IMPSRC} -o ${.TARGET}
 
 .e .r .F .f:
 	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
 	    -o ${.TARGET}
 
 .e.o .r.o .F.o .f.o:
-	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC}
+	${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC} -o ${.TARGET}
 
 .S.o:
-	${CC} ${CFLAGS} -c ${.IMPSRC}
+	${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
 
 .s.o:
-	${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
+	${AS} ${AFLAGS} ${.IMPSRC} -o ${.TARGET}
 
 # XXX not -j safe
 .y.o:

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?18441906438.20030404020335>