summaryrefslogtreecommitdiff
path: root/usr.sbin/crunchgen/crunchgen.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/crunchgen/crunchgen.c')
-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",