Date: Mon, 26 Feb 2007 11:56:02 +0800 From: mirnshi@gmail.com To: freebsd-hackers@freebsd.org Subject: the new functions of the crunchgen Message-ID: <fe3493cd0702251956u7afb7bcawe197a76a54c1b6c9@mail.gmail.com> In-Reply-To: <fe3493cd0702251915w75f93e5exe2762e01cdbd2a4d@mail.gmail.com> References: <fe3493cd0702251915w75f93e5exe2762e01cdbd2a4d@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Hi,
Crunchgen is a smart tools to create a tiny "bsd". I've used it for
years.
Sometime, we need some scripts to help crunchgen to generate the makefile
when we combine some foreign packages. If not, the make will stop because of
the definition the symbols. So I modified the codes.
1. Add two options to special command
special progname nlib library-file-name
enter the home directory of the library, run make to rebuild the
static library,
and tell the 'ld' to add this library to the progname.lo.
special progname slib library-file-name
like nlib, except that the library will be linked as a single
file.
2. Add "make xxx || echo Never mind." to meet some Makefiles
3. Disable adding the underscore ('_') to the symbols
see the attachment for detail.
Paul.
[-- Attachment #2 --]
diff -ruN crunchgen.orig/crunchgen.c crunchgen/crunchgen.c
--- crunchgen.orig/crunchgen.c Wed May 31 19:11:59 2006
+++ crunchgen/crunchgen.c Thu Jan 15 21:39:42 2007
@@ -31,6 +31,25 @@
*
* Generates a Makefile and main C file for a crunched executable,
* from specs given in a .conf file.
+ *
+ * --------------------------------------------------------------------------------------------
+ * Original file: 1.35.2.1 2006/05/31 19:11:59 ceri
+ *
+ * 1. Add two options to special command
+ * 2. Add "make xxx || echo Never mind." to meet some Makefiles
+ * 3. Disable adding the underscore (`_') to the symbols
+ *
+ * The new options:
+ * special progname nlib library-file-name
+ * rebuild the static library, and tell the 'ld' to add this library
+ * to the progname.lo.
+ * special progname slib library-file-name
+ * rebuild the static library, unlike nlib, the library will be linked
+ * as a single file.
+ *
+ * By Paul (mirnshi@gmail.com), 1/15/2007.
+ * --------------------------------------------------------------------------------------------
+ *
*/
#include <sys/types.h>
#include <sys/stat.h>
@@ -74,6 +93,8 @@
strlst_t *keeplist;
strlst_t *links;
strlst_t *libs;
+ strlst_t *slibs; /* rebuild libraries */
+ strlst_t *nlibs; /* rebuild libraries, modules*/
strlst_t *libs_so;
int goterror;
} prog_t;
@@ -409,6 +430,8 @@
else
p1->next = p2;
+ /* XXX why again? The struct block has been 'memset'
+ */
p2->ident = NULL;
p2->srcdir = NULL;
p2->realsrcdir = NULL;
@@ -538,6 +561,12 @@
} else if (!strcmp(argv[2], "lib")) {
for (i = 3; i < argc; i++)
add_string(&p->libs, argv[i]);
+ } else if (!strcmp(argv[2], "nlib")) {
+ for (i = 3; i < argc; i++)
+ add_string(&p->nlibs, argv[i]);
+ } else if (!strcmp(argv[2], "slib")) {
+ for (i = 3; i < argc; i++)
+ add_string(&p->slibs, argv[i]);
} else {
warnx("%s:%d: bad parameter name `%s', skipping line",
curfilename, linenum, argv[2]);
@@ -948,6 +977,7 @@
void top_makefile_rules(FILE *outmk)
{
prog_t *p;
+ strlst_t *lst;
if ( subtract_strlst(&libs, &libs_so) )
fprintf(outmk, "# NOTE: Some LIBS declarations below overridden by LIBS_SO\n");
@@ -974,6 +1004,12 @@
fprintf(outmk, "CRUNCHED_OBJS=");
for (p = progs; p != NULL; p = p->next)
fprintf(outmk, " %s.lo", p->name);
+
+ for (p = progs; p != NULL; p = p->next) {
+ if (p->slibs)
+ for (lst = p->slibs; lst != NULL; lst = lst->next)
+ fprintf(outmk, " %s", lst->str);
+ }
fprintf(outmk, "\n");
fprintf(outmk, "SUBMAKE_TARGETS=");
@@ -1027,20 +1063,35 @@
fprintf(outmk, "%s_OPTS+=", p->ident);
output_strlst(outmk, p->buildopts);
}
- fprintf(outmk, "%s_make:\n", p->ident);
+ fprintf(outmk, "%s_make:", p->ident);
+ if (p->slibs)
+ fprintf(outmk, " ${%s_SLIBS}", p->ident);
+ if (p->nlibs)
+ fprintf(outmk, " ${%s_NLIBS}", p->ident);
+ fprintf(outmk, "\n");
+
fprintf(outmk, "\t(cd $(%s_SRCDIR) && ", p->ident);
if (makeobj)
fprintf(outmk, "$(CRUNCHMAKE) obj && ");
fprintf(outmk, "\\\n");
- fprintf(outmk, "\t\t$(CRUNCHMAKE) $(BUILDOPTS) $(%s_OPTS) depend &&",
- p->ident);
+
+ fprintf(outmk, "\t\t($(CRUNCHMAKE) $(BUILDOPTS) $(%s_OPTS) depend || echo Never mind.) && ",
+ p->ident);
fprintf(outmk, "\\\n");
fprintf(outmk, "\t\t$(CRUNCHMAKE) $(BUILDOPTS) $(%s_OPTS) "
"$(%s_OBJS))",
p->ident, p->ident);
fprintf(outmk, "\n");
- fprintf(outmk, "%s_clean:\n", p->ident);
- fprintf(outmk, "\t(cd $(%s_SRCDIR) && $(CRUNCHMAKE) $(BUILDOPTS) clean cleandepend)\n\n",
+ fprintf(outmk, "%s_clean:", p->ident);
+ if (p->slibs)
+ fprintf(outmk, " clean_%s_SLIBS", p->ident);
+ if (p->nlibs)
+ fprintf(outmk, " clean_%s_NLIBS", p->ident);
+ fprintf(outmk, "\n");
+ fprintf(outmk, "\t(cd $(%s_SRCDIR) && $(CRUNCHMAKE) $(BUILDOPTS) clean && ",
+ p->ident);
+ fprintf(outmk, "\\\n");
+ fprintf(outmk, "\t\t($(CRUNCHMAKE) $(BUILDOPTS) cleandepend || echo Never mind.))\n",
p->ident);
} else {
fprintf(outmk, "%s_make:\n", p->ident);
@@ -1061,6 +1112,30 @@
fprintf(outmk, "%s_LIBS=", p->ident);
output_strlst(outmk, p->libs);
}
+ if (p->slibs) {
+ fprintf(outmk, "%s_SLIBS=", p->ident);
+ output_strlst(outmk, p->slibs);
+ fprintf(outmk, "${%s_SLIBS}:\n", p->ident);
+ fprintf(outmk, "\t(cd `dirname ${.TARGET}`; $(CRUNCHMAKE) $(BUILDOPTS) $(%s_OPTS))\n",
+ p->ident);
+ fprintf(outmk, "clean_%s_SLIBS:\n", p->ident);
+ for (lst = p->slibs; lst != NULL; lst = lst->next) {
+ fprintf(outmk, "\t(cd `dirname %s`; $(CRUNCHMAKE) $(BUILDOPTS) clean)\n",
+ lst->str, p->ident);
+ }
+ }
+ if (p->nlibs) {
+ fprintf(outmk, "%s_NLIBS=", p->ident);
+ output_strlst(outmk, p->nlibs);
+ fprintf(outmk, "${%s_NLIBS}:\n", p->ident);
+ fprintf(outmk, "\t(cd `dirname ${.TARGET}`; $(CRUNCHMAKE) $(BUILDOPTS) $(%s_OPTS))\n",
+ p->ident);
+ fprintf(outmk, "clean_%s_NLIBS:\n", p->ident);
+ for (lst = p->nlibs; lst != NULL; lst = lst->next) {
+ fprintf(outmk, "\t(cd `dirname %s`; $(CRUNCHMAKE) $(BUILDOPTS) clean)\n",
+ lst->str, p->ident);
+ }
+ }
fprintf(outmk, "%s_stub.c:\n", p->name);
fprintf(outmk, "\techo \""
@@ -1071,16 +1146,25 @@
p->name, p->name, p->ident);
if (p->libs)
fprintf(outmk, " $(%s_LIBS)", p->ident);
+ if (p->nlibs)
+ fprintf(outmk, " $(%s_NLIBS)", p->ident);
fprintf(outmk, "\n");
fprintf(outmk, "\tld -dc -r -o %s.lo %s_stub.o $(%s_OBJPATHS)",
p->name, p->name, p->ident);
if (p->libs)
fprintf(outmk, " $(%s_LIBS)", p->ident);
+ if (p->nlibs)
+ fprintf(outmk, " $(%s_NLIBS)", p->ident);
fprintf(outmk, "\n");
fprintf(outmk, "\tcrunchide -k _crunched_%s_stub ", p->ident);
+
+ /*
+ * XXX wow, adding the underscore (`_') automatically.
+ * It is not a good idea.
+ */
for (lst = p->keeplist; lst != NULL; lst = lst->next)
- fprintf(outmk, "-k _%s ", lst->str);
+ fprintf(outmk, "-k %s ", lst->str);
fprintf(outmk, "%s.lo\n", p->name);
}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?fe3493cd0702251956u7afb7bcawe197a76a54c1b6c9>
