Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tools Build genassym as a host tool. Part of PR toolchain/3...



details:   https://anonhg.NetBSD.org/src/rev/cd49d4528546
branches:  trunk
changeset: 581254:cd49d4528546
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Mon May 30 15:51:36 2005 +0000

description:
Build genassym as a host tool.  Part of PR toolchain/30350

diffstat:

 tools/Makefile             |    6 +-
 tools/genassym/Makefile    |   21 ++++
 tools/genassym/genassym.sh |  196 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 220 insertions(+), 3 deletions(-)

diffs (245 lines):

diff -r b604731e45c7 -r cd49d4528546 tools/Makefile
--- a/tools/Makefile    Mon May 30 15:16:51 2005 +0000
+++ b/tools/Makefile    Mon May 30 15:51:36 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.88 2005/01/27 12:54:05 is Exp $
+#      $NetBSD: Makefile,v 1.89 2005/05/30 15:51:36 thorpej Exp $
 
 .include <bsd.own.mk>
 
@@ -22,8 +22,8 @@
 
 SUBDIR=        host-mkdep .WAIT compat .WAIT \
        binstall .WAIT mktemp .WAIT \
-               cap_mkdb crunchgen ctags gencat hexdump lint lint2 lorder \
-               m4 makewhatis mkdep mtree rpcgen tsort uudecode \
+               cap_mkdb crunchgen ctags genassym gencat hexdump lint lint2 \
+               lorder m4 makewhatis mkdep mtree rpcgen tsort uudecode \
        texinfo .WAIT \
        yacc .WAIT \
        lex .WAIT \
diff -r b604731e45c7 -r cd49d4528546 tools/genassym/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/genassym/Makefile   Mon May 30 15:51:36 2005 +0000
@@ -0,0 +1,21 @@
+#      $NetBSD: Makefile,v 1.1 2005/05/30 15:51:36 thorpej Exp $
+
+.include <bsd.own.mk>
+
+COMPATOBJ!=    cd ${.CURDIR}/../compat && ${PRINTOBJDIR}
+.-include      "${COMPATOBJ}/defs.mk"
+
+TIMESTAMP=     ${TOOLDIR}/bin/${_TOOL_PREFIX}genassym
+
+CLEANFILES+=   genassym
+
+.include <bsd.hostprog.mk>
+
+install: ${TIMESTAMP}
+${TIMESTAMP}: genassym
+       ${HOST_INSTALL_FILE} -m ${BINMODE} ${.ALLSRC} ${.TARGET}
+
+genassym: genassym.sh
+       sed -e "s,/bin/sh,${HOST_BSHELL},g" < ${.ALLSRC} > ${.TARGET}
+
+realall: genassym
diff -r b604731e45c7 -r cd49d4528546 tools/genassym/genassym.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/genassym/genassym.sh        Mon May 30 15:51:36 2005 +0000
@@ -0,0 +1,196 @@
+#!/bin/sh -
+#      $NetBSD: genassym.sh,v 1.1 2005/05/30 15:51:36 thorpej Exp $
+#
+# Copyright (c) 1997 Matthias Pfaller.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. All advertising materials mentioning features or use of this software
+#    must display the following acknowledgement:
+#      This product includes software developed by Matthias Pfaller.
+# 4. The name of the author may not be used to endorse or promote products
+#    derived from this software without specific prior written permission
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+progname=${0}
+awk=${AWK:-awk}
+
+ccode=0                # generate temporary C file, compile it, execute result
+
+usage()
+{
+
+       echo "usage: ${progname} [-c] -- compiler command" >&2
+}
+
+args=`getopt ck $*`
+if [ $? != 0 ]; then
+       usage;
+       exit 1;
+fi
+set -- $args
+
+for i; do
+       case "$i" in
+       -c)
+               ccode=1
+               shift;;
+       --)
+               shift; break;;
+       esac
+done
+
+# Deal with any leading environment settings..
+
+while [ "$1" ]
+do
+       case "$1" in
+       *=*)
+               eval export "$1"
+               shift
+               ;;
+       *)
+               break
+               ;;
+       esac
+done
+
+genassym_temp=/tmp/genassym.$$
+
+if ! mkdir $genassym_temp; then
+       echo "${progname}: unable to create temporary directory" >&2
+       exit 1
+fi
+trap "rm -rf $genassym_temp" 0 1 2 3 15
+
+$awk '
+BEGIN {
+       printf("#define offsetof(type, member) ((size_t)(&((type *)0)->member))\n");
+       defining = 0;
+       type = "long";
+       asmtype = "n";
+       asmprint = "";
+}
+
+$0 ~ /^[ \t]*#.*/ || $0 ~ /^[ \t]*$/ {
+       # Just ignore comments and empty lines
+       next;
+}
+
+$0 ~ /^config[ \t]/ {
+       type = $2;
+       asmtype = $3;
+       asmprint = $4;
+       next;
+}
+
+/^include[ \t]/ {
+       if (defining != 0) {
+               defining = 0;
+               printf("}\n");
+       }
+       printf("#%s\n", $0);
+       next;
+}
+
+$0 ~ /^if[ \t]/ ||
+$0 ~ /^ifdef[ \t]/ ||
+$0 ~ /^ifndef[ \t]/ ||
+$0 ~ /^else/ ||
+$0 ~ /^elif[ \t]/ ||
+$0 ~ /^endif/ {
+       printf("#%s\n", $0);
+       next;
+}
+
+/^struct[ \t]/ {
+       structname = $2;
+       $0 = "define " structname "_SIZEOF sizeof(struct " structname ")";
+       # fall through
+}
+
+/^member[ \t]/ {
+       if (NF > 2)
+               $0 = "define " $2 " offsetof(struct " structname ", " $3 ")";
+       else
+               $0 = "define " $2 " offsetof(struct " structname ", " $2 ")";
+       # fall through
+}
+
+/^export[ \t]/ {
+       $0 = "define " $2 " " $2;
+       # fall through
+}
+
+/^define[ \t]/ {
+       if (defining == 0) {
+               defining = 1;
+               printf("void f" FNR "(void);\n");
+               printf("void f" FNR "() {\n");
+               if (ccode)
+                       call[FNR] = "f" FNR;
+               defining = 1;
+       }
+       value = $0
+       gsub("^define[ \t]+[A-Za-z_][A-Za-z_0-9]*[ \t]+", "", value)
+       if (ccode)
+               printf("printf(\"#define " $2 " %%ld\\n\", (%s)" value ");\n", type);
+       else
+               printf("__asm(\"XYZZY %s %%%s0\" : : \"%s\" (%s));\n", $2, asmprint, asmtype, value);
+       next;
+}
+
+/^quote[ \t]/ {
+       gsub("^quote[ \t]+", "");
+       print;
+       next;
+}
+
+{
+       printf("syntax error in line %d\n", FNR) >"/dev/stderr";
+       exit(1);
+}
+
+END {
+       if (defining != 0) {
+               defining = 0;
+               printf("}\n");
+       }
+       if (ccode) {
+               printf("int main(int argc, char **argv) {");
+               for (i in call)
+                       printf(call[i] "();");
+               printf("return(0); }\n");
+       }
+}
+' ccode=$ccode > ${genassym_temp}/assym.c || exit 1
+
+if [ $ccode = 1 ] ; then
+       "$@" ${genassym_temp}/assym.c -o ${genassym_temp}/genassym && \
+           ${genassym_temp}/genassym
+else
+       # Kill all of the "#" and "$" modifiers; locore.s already
+       # prepends the correct "constant" modifier.
+       "$@" -S ${genassym_temp}/assym.c -o - > \
+           ${genassym_temp}/genassym.out && \
+           sed -e 's/#//g' -e 's/\$//g' < ${genassym_temp}/genassym.out | \
+           sed -n 's/.*XYZZY/#define/gp'
+fi



Home | Main Index | Thread Index | Old Index