Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/file Make this cross-compile friendly - build a cut ...



details:   https://anonhg.NetBSD.org/src/rev/5331f4ea8fb2
branches:  trunk
changeset: 509628:5331f4ea8fb2
user:      simonb <simonb%NetBSD.org@localhost>
date:      Wed May 09 14:05:52 2001 +0000

description:
Make this cross-compile friendly - build a cut down program called
"mkmagic" out of apprentice.c and print.c that is built using the
host compiler and used to generate magic.mgc.

diffstat:

 usr.bin/file/Makefile     |  14 +++++++++-----
 usr.bin/file/apprentice.c |  41 ++++++++++++++++++++++++++++++++++++++---
 2 files changed, 47 insertions(+), 8 deletions(-)

diffs (132 lines):

diff -r 2119fa5b5726 -r 5331f4ea8fb2 usr.bin/file/Makefile
--- a/usr.bin/file/Makefile     Wed May 09 13:58:25 2001 +0000
+++ b/usr.bin/file/Makefile     Wed May 09 14:05:52 2001 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.32 2001/05/09 13:58:25 simonb Exp $
+#      $NetBSD: Makefile,v 1.33 2001/05/09 14:05:52 simonb Exp $
 
 .include <bsd.own.mk>
 
@@ -18,7 +18,7 @@
 CPPFLAGS+=     -DQUICK -DBUILTIN_ELF -DELFCORE
 MAN=           file.1 magic.5
 
-CLEANFILES+=   magic magic.mgc
+CLEANFILES+=   mkmagic magic magic.mgc
 realall:       file magic magic.mgc
 
 MAGDIRF:sh=    echo ${.CURDIR}/magdir/[0-9a-z]*
@@ -28,12 +28,16 @@
                ${MAGDIRF}
 
 .if ${MKSHARE} != "no"
-magic:         ${MAGFILES} ${PROG}
+magic:         ${MAGFILES}
        cat ${MAGFILES} > ${.TARGET}
-magic.mgc:     magic
-       ${.OBJDIR}/${PROG} -C -m ${.ALLSRC}
+magic.mgc:     mkmagic magic
+       ${.OBJDIR}/mkmagic magic
 .else
 magic:
 .endif
 
+mkmagic:       apprentice.c print.c
+       ${HOST_LINK.c} -o mkmagic -DHAVE_CONFIG_H -DQUICK -DCOMPILE_ONLY \
+               -I${.CURDIR} ${.CURDIR}/apprentice.c ${.CURDIR}/print.c
+
 .include <bsd.prog.mk>
diff -r 2119fa5b5726 -r 5331f4ea8fb2 usr.bin/file/apprentice.c
--- a/usr.bin/file/apprentice.c Wed May 09 13:58:25 2001 +0000
+++ b/usr.bin/file/apprentice.c Wed May 09 14:05:52 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: apprentice.c,v 1.22 2001/03/27 00:49:12 pooka Exp $    */
+/*     $NetBSD: apprentice.c,v 1.23 2001/05/09 14:05:52 simonb Exp $   */
 
 /*
  * apprentice - make one pass through /etc/magic, learning its secrets.
@@ -45,7 +45,7 @@
 #if 0
 FILE_RCSID("@(#)Id: apprentice.c,v 1.34 2001/03/11 20:29:16 christos Exp ")
 #else
-__RCSID("$NetBSD: apprentice.c,v 1.22 2001/03/27 00:49:12 pooka Exp $");
+__RCSID("$NetBSD: apprentice.c,v 1.23 2001/05/09 14:05:52 simonb Exp $");
 #endif
 #endif /* lint */
 
@@ -86,6 +86,35 @@
 
 struct mlist mlist;
 
+#ifdef COMPILE_ONLY
+const char *magicfile;
+char *progname;
+int lineno;
+
+int main __P((int, char *[]));
+
+int
+main(argc, argv)
+       int argc;
+       char *argv[];
+{
+       int ret;
+
+       if ((progname = strrchr(argv[0], '/')) != NULL)
+               progname++;
+       else
+               progname = argv[0];
+
+       if (argc != 2) {
+               (void)fprintf(stderr, "usage: %s file\n", progname);
+               exit(1);
+       }
+       magicfile = argv[1];
+
+       exit(apprentice(magicfile, COMPILE));
+}
+#endif /* COMPILE_ONLY */
+
 
 /*
  * Handle one file.
@@ -108,11 +137,14 @@
                else
                        return rv;
        }
+#ifndef COMPILE_ONLY
        if ((rv = apprentice_map(&magic, &nmagic, fn, action)) != 0)
                (void)fprintf(stderr, "%s: Using regular magic file `%s'\n",
                    progname, fn);
-#endif
+#endif /* COMPILE_ONLY */
+#endif /* QUICK */
                
+#ifndef COMPILE_ONLY
        if (rv != 0)
                rv = apprentice_file(&magic, &nmagic, fn, action);
 
@@ -137,6 +169,7 @@
        mlist.prev = ml;
 
        return rv;
+#endif /* COMPILE_ONLY */
 }
 
 
@@ -773,6 +806,7 @@
 }
 
 #ifdef QUICK
+#ifndef COMPILE_ONLY
 /*
  * handle an mmaped file.
  */
@@ -843,6 +877,7 @@
        }
        return -1;
 }
+#endif /* COMPILE_ONLY */
 
 /*
  * handle an mmaped file.



Home | Main Index | Thread Index | Old Index