From 4369378a6cdc7b36174d8b5a8d6e3886e447197b Mon Sep 17 00:00:00 2001 From: cgd Date: Wed, 21 Jan 1998 21:23:18 +0000 Subject: [PATCH] add rules like those in libc to build strchr() and strrchr() (the latter is being added to libkern by this commit). remove strchr.c from archs' Makefile.inc files to go along with this. (If an arch has a .S version, it should be copied down and added to the apropriate Makefile.inc.) --- sys/lib/libkern/Makefile | 50 +++++++++++++++- sys/lib/libkern/arch/alpha/Makefile.inc | 4 +- sys/lib/libkern/arch/arm32/Makefile.inc | 4 +- sys/lib/libkern/arch/i386/Makefile.inc | 4 +- sys/lib/libkern/arch/m68k/Makefile.inc | 4 +- sys/lib/libkern/arch/mips/Makefile.inc | 4 +- sys/lib/libkern/arch/ns32k/Makefile.inc | 4 +- sys/lib/libkern/arch/powerpc/Makefile.inc | 4 +- sys/lib/libkern/arch/sparc/Makefile.inc | 4 +- sys/lib/libkern/arch/vax/Makefile.inc | 4 +- sys/lib/libkern/{strchr.c => index.c} | 14 +---- sys/lib/libkern/rindex.c | 69 +++++++++++++++++++++++ 12 files changed, 138 insertions(+), 31 deletions(-) rename sys/lib/libkern/{strchr.c => index.c} (83%) create mode 100644 sys/lib/libkern/rindex.c diff --git a/sys/lib/libkern/Makefile b/sys/lib/libkern/Makefile index bfe929494e52..a387b0a74fc9 100644 --- a/sys/lib/libkern/Makefile +++ b/sys/lib/libkern/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.37 1997/11/04 20:34:46 gwr Exp $ +# $NetBSD: Makefile,v 1.38 1998/01/21 21:23:18 cgd Exp $ LIB= kern NOPIC= @@ -25,10 +25,58 @@ SRCS+= md5c.c # Files to clean up CLEANFILES+= lib${LIB}.o lib${LIB}.po +# +# Special rules for certain objects +# + # mcount cannot be compiled with profiling mcount.po: mcount.o cp mcount.o mcount.po +# if no machine specific strchr(3), build one out of index(3). +.if empty(SRCS:Mstrchr.S) +OBJS+= strchr.o +strchr.o: index.c + ${COMPILE.c} -DSTRCHR ${.ALLSRC} -o ${.TARGET} + @${LD} -x -r ${.TARGET} + @mv a.out ${.TARGET} + +strchr.po: index.c + ${COMPILE.c} -DSTRCHR -p ${.ALLSRC} -o ${.TARGET} + @${LD} -X -r ${.TARGET} + @mv a.out ${.TARGET} + +strchr.so: index.c + ${COMPILE.c} ${PICFLAG} -DPIC -DSTRCHR ${.ALLSRC} -o ${.TARGET} + +LOBJS+= strchr.ln +strchr.ln: index.c + ${LINT} -DSTRCHR ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i -o ${.TARGET} \ + ${.ALLSRC} +.endif + +# if no machine specific strrchr(3), build one out of rindex(3). +.if empty(SRCS:Mstrrchr.S) +OBJS+= strrchr.o +strrchr.o: rindex.c + ${COMPILE.c} -DSTRRCHR ${.ALLSRC} -o ${.TARGET} + @${LD} -x -r ${.TARGET} + @mv a.out ${.TARGET} + +strrchr.po: rindex.c + ${COMPILE.c} -DSTRRCHR -p ${.ALLSRC} -o ${.TARGET} + @${LD} -X -r ${.TARGET} + @mv a.out ${.TARGET} + +strrchr.so: rindex.c + ${COMPILE.c} ${PICFLAG} -DPIC -DSTRRCHR ${.ALLSRC} -o ${.TARGET} + +LOBJS+= strrchr.ln +strrchr.ln: rindex.c + ${LINT} -DSTRRCHR ${LINTFLAGS} ${CPPFLAGS:M-[IDU]*} -i -o ${.TARGET} \ + ${.ALLSRC} +.endif + # only needed during build libinstall:: diff --git a/sys/lib/libkern/arch/alpha/Makefile.inc b/sys/lib/libkern/arch/alpha/Makefile.inc index e3082f897940..df0da47960bf 100644 --- a/sys/lib/libkern/arch/alpha/Makefile.inc +++ b/sys/lib/libkern/arch/alpha/Makefile.inc @@ -1,10 +1,10 @@ -# $NetBSD: Makefile.inc,v 1.12 1997/10/24 15:32:25 chuck Exp $ +# $NetBSD: Makefile.inc,v 1.13 1998/01/21 21:23:22 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ bswap16.S bswap32.S bswap64.c memchr.c \ bcmp.c bzero.S ffs.S strcat.c strcmp.c strcpy.c strlen.c strncmp.c \ strncpy.c scanc.c skpc.c htonl.S htons.S ntohl.S ntohs.S \ - random.c strncasecmp.c __assert.c strchr.c + random.c strncasecmp.c __assert.c # `source' files built from m4 source SRCS+= __divqu.S __divq.S __divlu.S __divl.S diff --git a/sys/lib/libkern/arch/arm32/Makefile.inc b/sys/lib/libkern/arch/arm32/Makefile.inc index a6c144976365..1bdef1be3a70 100644 --- a/sys/lib/libkern/arch/arm32/Makefile.inc +++ b/sys/lib/libkern/arch/arm32/Makefile.inc @@ -1,8 +1,8 @@ -# $NetBSD: Makefile.inc,v 1.9 1997/10/24 15:32:26 chuck Exp $ +# $NetBSD: Makefile.inc,v 1.10 1998/01/21 21:23:22 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ bswap16.c bswap32.c bswap64.c bcmp.c ffs.c strcat.c strcmp.c \ strcpy.c strlen.c strncmp.c strncpy.c scanc.c skpc.c random.c \ - strncasecmp.c __assert.c strchr.c + strncasecmp.c __assert.c SRCS+= divsi3.S htons.S htonl.S ntohs.S ntohl.S SRCS+= _memcpy.S memcpy.S bcopy.S memset.S bzero.S memchr.c diff --git a/sys/lib/libkern/arch/i386/Makefile.inc b/sys/lib/libkern/arch/i386/Makefile.inc index 7be79bfb1746..fd4700819382 100644 --- a/sys/lib/libkern/arch/i386/Makefile.inc +++ b/sys/lib/libkern/arch/i386/Makefile.inc @@ -1,7 +1,7 @@ -# $NetBSD: Makefile.inc,v 1.15 1997/10/24 15:32:27 chuck Exp $ +# $NetBSD: Makefile.inc,v 1.16 1998/01/21 21:23:23 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ bswap16.S bswap32.S bswap64.c memchr.S \ bcmp.S ffs.S strcat.S strcmp.S strcpy.S strlen.S strncmp.c \ strncpy.c scanc.S skpc.S htonl.S htons.S ntohl.S ntohs.S \ - strncasecmp.c __assert.c strchr.c + strncasecmp.c __assert.c diff --git a/sys/lib/libkern/arch/m68k/Makefile.inc b/sys/lib/libkern/arch/m68k/Makefile.inc index 05b1fec63b77..dcd5314560f2 100644 --- a/sys/lib/libkern/arch/m68k/Makefile.inc +++ b/sys/lib/libkern/arch/m68k/Makefile.inc @@ -1,7 +1,7 @@ -# $NetBSD: Makefile.inc,v 1.15 1997/10/24 15:32:29 chuck Exp $ +# $NetBSD: Makefile.inc,v 1.16 1998/01/21 21:23:24 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ bswap16.S bswap32.S bswap64.S memchr.c \ bcmp.S bzero.S ffs.S strcat.S strcmp.S strcpy.S strlen.S strncmp.S \ strncpy.S htonl.S htons.S ntohl.S ntohs.S scanc.S skpc.S \ - strncasecmp.c __assert.c strchr.c + strncasecmp.c __assert.c diff --git a/sys/lib/libkern/arch/mips/Makefile.inc b/sys/lib/libkern/arch/mips/Makefile.inc index c6fc97879af2..bb2c78215c49 100644 --- a/sys/lib/libkern/arch/mips/Makefile.inc +++ b/sys/lib/libkern/arch/mips/Makefile.inc @@ -1,7 +1,7 @@ -# $NetBSD: Makefile.inc,v 1.8 1997/10/24 15:32:30 chuck Exp $ +# $NetBSD: Makefile.inc,v 1.9 1998/01/21 21:23:25 cgd Exp $ # # There are likely more that we will notice when we go native SRCS+= random.c scanc.c skpc.c strcat.c strcpy.c strncmp.c strncpy.c \ bswap16.c bswap32.c bswap64.c memchr.c \ - strncasecmp.c __assert.c strchr.c + strncasecmp.c __assert.c diff --git a/sys/lib/libkern/arch/ns32k/Makefile.inc b/sys/lib/libkern/arch/ns32k/Makefile.inc index b8b577372bee..1799bf8e4e8a 100644 --- a/sys/lib/libkern/arch/ns32k/Makefile.inc +++ b/sys/lib/libkern/arch/ns32k/Makefile.inc @@ -1,7 +1,7 @@ -# $NetBSD: Makefile.inc,v 1.13 1997/10/24 15:32:31 chuck Exp $ +# $NetBSD: Makefile.inc,v 1.14 1998/01/21 21:23:26 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ bswap16.c bswap32.c bswap64.c memchr.S \ bcmp.S bcopy.S bzero.S ffs.S strcat.S strcmp.S strcpy.S strlen.S \ strncmp.S strncpy.S htonl.S htons.S ntohl.S ntohs.S \ - scanc.c skpc.c strncasecmp.c __assert.c strchr.c + scanc.c skpc.c strncasecmp.c __assert.c diff --git a/sys/lib/libkern/arch/powerpc/Makefile.inc b/sys/lib/libkern/arch/powerpc/Makefile.inc index 25bbb694c77b..a1ed97d9c8f2 100644 --- a/sys/lib/libkern/arch/powerpc/Makefile.inc +++ b/sys/lib/libkern/arch/powerpc/Makefile.inc @@ -1,7 +1,7 @@ -# $NetBSD: Makefile.inc,v 1.4 1997/10/24 15:32:33 chuck Exp $ +# $NetBSD: Makefile.inc,v 1.5 1998/01/21 21:23:27 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ bswap16.c bswap32.c bswap64.c memchr.c \ bcmp.c bzero.c ffs.c scanc.c skpc.c \ strcat.c strcmp.c strcpy.c strlen.c strncmp.c strncpy.c \ - random.c __assert.c strchr.c + random.c __assert.c diff --git a/sys/lib/libkern/arch/sparc/Makefile.inc b/sys/lib/libkern/arch/sparc/Makefile.inc index 95b04c131c25..46475c55c4ab 100644 --- a/sys/lib/libkern/arch/sparc/Makefile.inc +++ b/sys/lib/libkern/arch/sparc/Makefile.inc @@ -1,10 +1,10 @@ -# $NetBSD: Makefile.inc,v 1.17 1997/10/24 15:32:34 chuck Exp $ +# $NetBSD: Makefile.inc,v 1.18 1998/01/21 21:23:27 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ bswap16.c bswap32.c bswap64.c memchr.c \ bcmp.c bzero.S strcat.c strcmp.c strcpy.c strlen.S strncmp.c \ strncpy.c htonl.S htons.S ntohl.S ntohs.S scanc.c skpc.c \ - strncasecmp.c __assert.c strchr.c + strncasecmp.c __assert.c SRCS+= umul.S mul.S rem.S sdiv.S udiv.S umul.S urem.S SRCS+= mul.S saveregs.S umul.S diff --git a/sys/lib/libkern/arch/vax/Makefile.inc b/sys/lib/libkern/arch/vax/Makefile.inc index 4ca3f86c4551..e2b753a20597 100644 --- a/sys/lib/libkern/arch/vax/Makefile.inc +++ b/sys/lib/libkern/arch/vax/Makefile.inc @@ -1,6 +1,6 @@ -# $NetBSD: Makefile.inc,v 1.7 1997/10/24 15:32:34 chuck Exp $ +# $NetBSD: Makefile.inc,v 1.8 1998/01/21 21:23:28 cgd Exp $ SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \ bswap16.c bswap32.c bswap64.c memchr.c \ strcat.c strcmp.c strcpy.c strlen.c strncmp.c \ - strncpy.c scanc.c skpc.c strncasecmp.c __assert.c strchr.c + strncpy.c scanc.c skpc.c strncasecmp.c __assert.c diff --git a/sys/lib/libkern/strchr.c b/sys/lib/libkern/index.c similarity index 83% rename from sys/lib/libkern/strchr.c rename to sys/lib/libkern/index.c index 4e3fa23a67b0..2e1e01fb8bb3 100644 --- a/sys/lib/libkern/strchr.c +++ b/sys/lib/libkern/index.c @@ -1,4 +1,4 @@ -/* $NetBSD: strchr.c,v 1.3 1998/01/21 19:43:23 cgd Exp $ */ +/* $NetBSD: index.c,v 1.1 1998/01/21 21:23:19 cgd Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -38,20 +38,10 @@ #if 0 static char *sccsid = "@(#)index.c 5.7 (Berkeley) 2/24/91"; #else -__RCSID("$NetBSD: strchr.c,v 1.3 1998/01/21 19:43:23 cgd Exp $"); +__RCSID("$NetBSD: index.c,v 1.1 1998/01/21 21:23:19 cgd Exp $"); #endif #endif /* LIBC_SCCS and not lint */ -/* - * XXX This file copied from libc's "index.c", but with the - * "#define STRCHR" and the #ifndef _KERNEL goop added below. - * - * It'd be nice to include the file here unchanged from the libc - * version (and, preferably, with the same name) but I didn't want to - * include the baroque strchr/index + asm/C rules here in libkern. - */ -#define STRCHR - #ifndef _KERNEL #include #else diff --git a/sys/lib/libkern/rindex.c b/sys/lib/libkern/rindex.c new file mode 100644 index 000000000000..7e2d5970bf6a --- /dev/null +++ b/sys/lib/libkern/rindex.c @@ -0,0 +1,69 @@ +/* $NetBSD: rindex.c,v 1.1 1998/01/21 21:23:19 cgd Exp $ */ + +/* + * Copyright (c) 1988 Regents of the University of California. + * 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 the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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. + */ + +#include +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char *sccsid = "@(#)rindex.c 5.9 (Berkeley) 2/24/91"; +#else +__RCSID("$NetBSD: rindex.c,v 1.1 1998/01/21 21:23:19 cgd Exp $"); +#endif +#endif /* LIBC_SCCS and not lint */ + +#ifndef _KERNEL +#include +#else +#include +#define NULL ((char *)0) +#endif + +char * +#ifdef STRRCHR +strrchr(p, ch) +#else +rindex(p, ch) +#endif + register const char *p, ch; +{ + register char *save; + + for (save = NULL;; ++p) { + if (*p == ch) + save = (char *)p; + if (!*p) + return(save); + } + /* NOTREACHED */ +}