summaryrefslogtreecommitdiffstats
path: root/usr.sbin/crunchgen
diff options
context:
space:
mode:
authorguenther <guenther@openbsd.org>2013-10-13 23:33:14 +0000
committerguenther <guenther@openbsd.org>2013-10-13 23:33:14 +0000
commitef0efd1735b637c3d1522b4d4ee1da2c5dab313a (patch)
tree87e5b682a0c76cda2962adcee867ad1d571dfd98 /usr.sbin/crunchgen
parentMake it possible to build to reduced version of a library, including (diff)
downloadwireguard-openbsd-ef0efd1735b637c3d1522b4d4ee1da2c5dab313a.tar.xz
wireguard-openbsd-ef0efd1735b637c3d1522b4d4ee1da2c5dab313a.zip
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
Diffstat (limited to 'usr.sbin/crunchgen')
-rw-r--r--usr.sbin/crunchgen/crunchgen.c34
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",