diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2013-10-13 23:33:15 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2013-10-13 23:33:15 +0000 |
commit | c86867ef452b4b3e3628e4b0f28743e484657dbc (patch) | |
tree | 85ea139de3e0b86aa0bd85040ce6b576ded24d86 | |
parent | ef81203d7dbea514733b1e2161cf229b4b08d1e5 (diff) |
Use the new DIST_LIB/DIST_OBJS hooks to make it possible to link crunched
binaries against libraries compiled with smaller objects. Determination
of which objects to include done by linking once and checking the link map.
SRCLIBDIR must be set by the calling makefile to /usr/src/lib for this to
have any effect
-rw-r--r-- | usr.sbin/crunchgen/crunchgen.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/usr.sbin/crunchgen/crunchgen.c b/usr.sbin/crunchgen/crunchgen.c index e4a158951df..e0cfb11608e 100644 --- a/usr.sbin/crunchgen/crunchgen.c +++ b/usr.sbin/crunchgen/crunchgen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crunchgen.c,v 1.8 2012/08/29 16:23:34 deraadt Exp $ */ +/* $OpenBSD: crunchgen.c,v 1.9 2013/10/13 23:33:14 guenther Exp $ */ /* * Copyright (c) 1994 University of Maryland @@ -907,11 +907,39 @@ top_makefile_rules(FILE * outmk) fprintf(outmk, " %s_make", p->ident); fprintf(outmk, "\n\n"); - fprintf(outmk, "%s: %s.o $(CRUNCHED_OBJS)\n", + fprintf(outmk, "CLIB=\n"); + fprintf(outmk, ".if defined(SRCLIBDIR)\n"); + fprintf(outmk, ". for lib in ${LIBS:M-l*:S/-l//}\n"); + fprintf(outmk, ". if exists(${SRCLIBDIR}/lib${lib})\n"); + fprintf(outmk, "CLIB+=lib${lib}.a\n"); + fprintf(outmk, ". endif\n"); + fprintf(outmk, ". endfor\n"); + fprintf(outmk, ".endif\n\n"); + + fprintf(outmk, "%s: %s.o $(CRUNCHED_OBJS) ${CLIB}\n", execfname, execfname); - fprintf(outmk, "\t$(CC) -static ${LDFLAGS} -o $@ %s.o $(CRUNCHED_OBJS) $(LIBS)\n", + fprintf(outmk, "\t$(CC) -static -L. ${LDFLAGS} -o $@ %s.o $(CRUNCHED_OBJS) $(LIBS)\n", execfname); fprintf(outmk, "\t$(STRIP) %s\n", execfname); + + fprintf(outmk, "\n"); + fprintf(outmk, ".if !empty(CLIB)\n"); + fprintf(outmk, ".SUFFIXES: .a .olist\n"); + fprintf(outmk, ".olist.a:\n"); + fprintf(outmk, "\t@rm -f ${.TARGET}\n"); + fprintf(outmk, "\t@cd ${SRCLIBDIR}/${.PREFIX} &&\t\t\t\t\\\n"); + fprintf(outmk, "\t${MAKE} DIST_OBJS=\"`cat ${.OBJDIR}/${.IMPSRC}`\"\t\t\\\n"); + fprintf(outmk, "\t DIST_LIB=${.OBJDIR}/${.TARGET} ${.OBJDIR}/${.TARGET}\n\n"); + + fprintf(outmk, "%s.map: %s.o $(CRUNCHED_OBJS)\n", execfname, execfname); + fprintf(outmk, "\t$(CC) -static ${LDFLAGS} -o /dev/null %s.o $(CRUNCHED_OBJS) \\\n", execfname); + fprintf(outmk, "\t $(LIBS) -Wl,-M | sed -e '/^Allocating/q' >${.TARGET}\n\n"); + + fprintf(outmk, "${CLIB:.a=.olist}: %s.map\n", execfname); + fprintf(outmk, "\tsed -n -e 's!^/usr/lib/${.TARGET:R}\\.a(\\([^)]*\\.o\\)).*!\\1!p' \\\n"); + fprintf(outmk, "\t < %s.map | tr '\\012' ' ' >$@\n", execfname); + fprintf(outmk, ".endif\n\n"); + fprintf(outmk, "all: objs exe\nobjs: $(SUBMAKE_TARGETS)\n"); fprintf(outmk, "exe: %s\n", execfname); fprintf(outmk, "clean:\n\trm -f %s *.lo *.o *_stub.c\n", |