Subject: no "make depend" for ELF platforms in lib/csu
To: None <tech-toolchain@netbsd.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-toolchain
Date: 02/25/2001 16:02:01
I noticed that there is no .depend files generated for ELF platforms in
lib/csu.  The following does pretty much what I want, but I not sure
if it's the cleanest or easiest way.  It moves the build machinery
to use <bsd.lib.mk> and add some mods to <bsd.lib.mk> to ignore some
targets if ${LIB} is not defined.  One side effect of this is that
previously, /usr/lib/*.o always had local symbols removed, even if you
have something like "COPTS+=-g" in /etc/mk.conf - now local symbols are
kept during debugging builds.

One thing I'd like to remove the remaining {g,}crt0.o rules, but these
are built from the same .c file with different preprocessor defines.
The first idea I had was to add a ${CPPFLAGS_${foo}} type thing to add
per-file CPPFLAGS but that doesn't seem quite like the right solution.
Perhaps best is to just rename each architecture's crt0.c to crt0_body.c
and have a common_elf/crt0.c that is
	
	#define CRT0
	#include "crt0_body.c"

and similar for a common_elf/gcrt0.c.  This way there's no problems
building the .depend files correctly, although currently nothing seems
to include different files for the CRT0/MCRT0 cases.

Comments?

Simon.
--
Simon Burge                            <simonb@wasabisystems.com>
NetBSD CDs, Support and Service:    http://www.wasabisystems.com/

Index: lib/csu/common_elf/Makefile.inc
===================================================================
RCS file: /cvsroot/basesrc/lib/csu/common_elf/Makefile.inc,v
retrieving revision 1.5
diff -d -p -u -r1.5 Makefile.inc
--- lib/csu/common_elf/Makefile.inc	2000/04/02 15:35:47	1.5
+++ lib/csu/common_elf/Makefile.inc	2001/02/25 01:09:20
@@ -4,43 +4,37 @@
 ELFSIZE=32
 .endif
 
+SRCS=		crt0.c gcrt0.c crtbegin.c crtend.c
+.PATH:		${.CURDIR}/../common_elf
+
 CPPFLAGS+=	-DLIBC_SCCS -DPIC -DDYNAMIC -DELFSIZE=${ELFSIZE}
 CPPFLAGS+=	-I${.CURDIR}/../../../libexec/ld.elf_so
 CPPFLAGS+=	-I${.CURDIR}/../common_elf
 CPPFLAGS+=	-I${.CURDIR}/../../libc/dlfcn
 COPTS+=		-fPIC
 
-.PATH:		${.CURDIR}/../common_elf
-
-OBJS=		crt0.o gcrt0.o crtbegin.o crtend.o
-
-CLEANFILES+=	core a.out
-
-realall: ${OBJS}
+gcrt0.c: crt0.c
+	rm -f ${.TARGET}
+	ln -s ${.ALLSRC} ${.TARGET}
+CLEANFILES+=gcrt0.c
 
 crt0.o: crt0.c
-	@echo "${COMPILE.c} -DCRT0 ${.ALLSRC} -o ${.TARGET}"
-	@${COMPILE.c} -DCRT0 ${.ALLSRC} -o ${.TARGET}.o
-	@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
-	@rm -f ${.TARGET}.o
-
-gcrt0.o: crt0.c
-	@echo "${COMPILE.c} -DMCRT0 ${.ALLSRC} -o ${.TARGET}"
-	@${COMPILE.c} -DMCRT0 ${.ALLSRC} -o ${.TARGET}.o
+	@echo "${COMPILE.c} -DCRT0 ${.IMPSRC} -o ${.TARGET}"
+	@${COMPILE.c} -DCRT0 ${.IMPSRC} -o ${.TARGET}.o
 	@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	@rm -f ${.TARGET}.o
 
-crtbegin.o: crtbegin.c
-	@echo "${COMPILE.c} ${.ALLSRC} -o ${.TARGET}"
-	@${COMPILE.c} ${.ALLSRC} -o ${.TARGET}.o
+gcrt0.o: gcrt0.c
+	@echo "${COMPILE.c} -DMCRT0 ${.IMPSRC} -o ${.TARGET}"
+	@${COMPILE.c} -DMCRT0 ${.IMPSRC} -o ${.TARGET}.o
 	@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
 	@rm -f ${.TARGET}.o
 
-crtend.o: crtend.c
-	@echo "${COMPILE.c} ${.ALLSRC} -o ${.TARGET}"
-	@${COMPILE.c} ${.ALLSRC} -o ${.TARGET}.o
-	@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
-	@rm -f ${.TARGET}.o
+afterdepend: .depend
+	@(TMP=/tmp/_depend$$$$; \
+		sed -e 's/^\(crt0\).o[ ]*:/\1.o g\1.o:/' \
+		< .depend > $$TMP; \
+	mv $$TMP .depend)
 
 FILES=${OBJS}
 FILESDIR=/usr/lib
@@ -48,4 +42,4 @@ FILESDIR=/usr/lib
 LINKS=	${LIBDIR}/crtbegin.o ${LIBDIR}/crtbeginS.o \
 	${LIBDIR}/crtend.o ${LIBDIR}/crtendS.o
 
-.include <bsd.prog.mk>
+.include <bsd.lib.mk>
Index: share/mk/bsd.lib.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.lib.mk,v
retrieving revision 1.178
diff -d -p -u -r1.178 bsd.lib.mk
--- share/mk/bsd.lib.mk	2000/12/05 22:18:30	1.178
+++ share/mk/bsd.lib.mk	2001/02/25 01:09:21
@@ -261,15 +261,18 @@ CFLAGS+=	${COPTS}
 	@${LD} -x -r ${.TARGET}.o -o ${.TARGET}
 	@rm -f ${.TARGET}.o
 
+.if defined(LIB)
 .if ${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
 	|| ${MKLINKLIB} != "no"
 _LIBS=lib${LIB}.a
 .else
 _LIBS=
 .endif
+.endif # defined(LIB)
 
 OBJS+=${SRCS:N*.h:N*.sh:R:S/$/.o/g}
 
+.if defined(LIB)
 .if ${MKPROFILE} != "no"
 _LIBS+=lib${LIB}_p.a
 POBJS+=${OBJS:.o=.po}
@@ -292,6 +295,7 @@ _LIBS+=lib${LIB}.so.${SHLIB_FULLVERSION}
 _LIBS+=llib-l${LIB}.ln
 LOBJS+=${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
 .endif
+.endif # defined(LIB)
 
 .if ${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
 	|| ${MKLINKLIB} != "no"
@@ -378,6 +382,7 @@ afterdepend: .depend
 # Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
 libinstall::
 
+.if defined(LIB)
 .if ${MKLINKLIB} != "no"
 libinstall:: ${DESTDIR}${LIBDIR}/lib${LIB}.a
 .PRECIOUS: ${DESTDIR}${LIBDIR}/lib${LIB}.a
@@ -468,6 +473,7 @@ ${DESTDIR}${LINTLIBDIR}/llib-l${LIB}.ln:
 	    -g ${LIBGRP} -m ${LIBMODE} ${.ALLSRC} ${DESTDIR}${LINTLIBDIR}
 .endif
 .endif
+.endif # defined(LIB)
 
 .include <bsd.man.mk>
 .include <bsd.nls.mk>