diff options
62 files changed, 2763 insertions, 495 deletions
@@ -28,7 +28,7 @@ include Rules.mak -DIRS = misc pwd_grp stdio string termios unistd net signal stdlib sysdeps +DIRS = misc pwd_grp stdio string termios unistd net signal stdlib sysdeps extra all: libc.a @@ -58,7 +58,7 @@ headers: dummy tags: ctags -R - + clean: subdirs_clean rm -f libc.a rm -f include/asm include/net include/linux include/bits @@ -41,7 +41,7 @@ ifeq ($(DODEBUG),true) LDFLAGS = -nostdlib -Wl,-warn-common STRIPTOOL = /bin/true -Since_we_are_debugging else - CFLAGS += $(WARNINGS) #-fomit-frame-pointer + CFLAGS += -DNDEBUG $(WARNINGS) #-fomit-frame-pointer LDFLAGS = -s -nostdlib -Wl,-warn-common endif diff --git a/extra/Makefile b/extra/Makefile new file mode 100644 index 000000000..fa4b50b44 --- /dev/null +++ b/extra/Makefile @@ -0,0 +1,48 @@ +# Makefile for uClibc +# +# Copyright (C) 2000 by Lineo, inc. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU Library General Public License as published by the Free +# Software Foundation; either version 2 of the License, or (at your option) any +# later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more +# details. +# +# You should have received a copy of the GNU Library General Public License +# along with this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Derived in part from the Linux-8086 C library, the GNU C Library, and several +# other sundry sources. Files within this library are copyright by their +# respective copyright holders. + +TOPDIR=../ +include $(TOPDIR)Rules.mak +LIBC=$(TOPDIR)libc.a + + +DIRS = gcc-uClibc + +all: subdirs + +tags: + ctags -R + +clean: subdirs_clean + rm -f *.[oa] *~ core + +subdirs: $(patsubst %, _dir_%, $(DIRS)) +subdirs_clean: $(patsubst %, _dirclean_%, $(DIRS)) + +$(patsubst %, _dir_%, $(DIRS)) : dummy + $(MAKE) -C $(patsubst _dir_%, %, $@) + +$(patsubst %, _dirclean_%, $(DIRS)) : dummy + $(MAKE) -C $(patsubst _dirclean_%, %, $@) clean + +.PHONY: dummy + diff --git a/extra/gcc-uClibc/Makefile b/extra/gcc-uClibc/Makefile new file mode 100644 index 000000000..af9f836a1 --- /dev/null +++ b/extra/gcc-uClibc/Makefile @@ -0,0 +1,40 @@ + +TOPDIR = ../../ +include $(TOPDIR)Rules.mak + +UCLIBC_DIR = $(shell (cd ../.. ; /bin/pwd)) +GCC_BIN = $(CC) +GCC_LIB = $(shell $(CC) -print-libgcc-file-name ) +#GCCINCDIR inherited from Rules.mak + +NATIVE_ARCH = $(shell uname -m | sed -e 's/i.86/i386/' -e 's/sparc.*/sparc/' -e 's/arm.*/arm/g') +GCC_UCLIBC = gcc-uClibc-cross +ifeq ($(TARGET_ARCH), $(NATIVE_ARCH)) + GCC_UCLIBC = gcc-uClibc-native +endif + +all: $(GCC_UCLIBC) + +clean: + rm -f gcc-uClibc.h gcc-uClibc-* + +gcc-uClibc.h: clean + echo "/* this file is created by make */" > gcc-uClibc.h + echo "#define UCLIBC_DIR " \"$(UCLIBC_DIR)/\" >> gcc-uClibc.h + echo "#define GCC_BIN " \"$(GCC_BIN)\" >> gcc-uClibc.h + echo "#define GCC_LIB " \"$(GCC_LIB)\" >> gcc-uClibc.h + echo "#define GCC_INCDIR " \"-I$(GCCINCDIR)/\" >> gcc-uClibc.h + echo "#define TARGET_ARCH " \"$(TARGET_ARCH)\" >> gcc-uClibc.h + +gcc-uClibc-native: gcc-uClibc.h gcc-uClibc.c + # uClibc built for native environment, so why not use it ;-) + $(CC) $(CFLAGS) -nostdinc -I$(UCLIBC_DIR)/include -I$(GCC_INC) \ + -Wl,-static gcc-uClibc.c \ + $(UCLIBC_DIR)/sysdeps/linux/$(TARGET_ARCH)/_start.o \ + -nostdlib $(GCC_LIB) $(UCLIBC_DIR)/libc.a \ + -s -o gcc-uClibc-$(TARGET_ARCH) #-DDEBUG + +gcc-uClibc-cross: gcc-uClibc.h gcc-uClibc.c + # don't use CFLAGS since may not be appropriate + gcc -s gcc-uClibc.c -o gcc-uClibc-$(TARGET_ARCH) + diff --git a/extra/gcc-uClibc/gcc-uClibc.c b/extra/gcc-uClibc/gcc-uClibc.c new file mode 100644 index 000000000..f783cd7bd --- /dev/null +++ b/extra/gcc-uClibc/gcc-uClibc.c @@ -0,0 +1,129 @@ + +/* + * Copyright (C) 2000 Manuel Novoa III + * + * This is a crude wrapper to use uClibc with gcc. + * It was originally written to work around ./configure for ext2fs-utils. + * It certainly can be improved, but it works for me in the normal cases. + * + * TODO: + * Check/modify gcc-specific environment variables? + */ + +#ifdef DEBUG +#include <stdio.h> +#endif + +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "gcc-uClibc.h" + +#define UCLIBC_START UCLIBC_DIR"sysdeps/linux/"TARGET_ARCH"/_start.o" +#define UCLIBC_START_G UCLIBC_START +#define UCLIBC_LIB UCLIBC_DIR"libc.a" +#if 1 +#define UCLIBC_LIB_G UCLIBC_LIB +#else +#define UCLIBC_LIB_G UCLIBC_DIR"libc.a-debug" +#endif +#define UCLIBC_INC "-I"UCLIBC_DIR"include/" + +static char nostdinc[] = "-nostdinc"; +static char nostartfiles[] = "-nostartfiles"; +static char nodefaultlibs[] = "-nodefaultlibs"; +static char nostdlib[] = "-nostdlib"; + +int main(int argc, char **argv) +{ + int debugging = 0, linking = 1; + int use_stdinc = 1, use_start = 1, use_stdlib = 1; + int i, j; + int source_count; + char ** gcc_argv; + + source_count = 0; + + for ( i = 1 ; i < argc ; i++ ) { + if (argv[i][0] == '-') { /* option */ + switch (argv[i][1]) { + case 'c': + case 'S': + case 'E': + case 'r': + if (argv[i][2] == 0) linking = 0; + break; + case 'g': + if (argv[i][2] == 0) debugging = 1; + break; + case 'n': + if (strcmp(nostdinc,argv[i]) == 0) { + use_stdinc = 0; + } else if (strcmp(nostartfiles,argv[i]) == 0) { + use_start = 0; + } else if (strcmp(nodefaultlibs,argv[i]) == 0) { + use_stdlib = 0; + } else if (strcmp(nostdlib,argv[i]) == 0) { + use_start = 0; + use_stdlib = 0; + } + + } + } else { /* assume it is an existing source file */ + ++source_count; + } + } + +#if 1 + gcc_argv = __builtin_alloca(sizeof(char*) * (argc + 20)); +#else + if (!(gcc_argv = malloc(sizeof(char) * (argc + 20)))) { + return EXIT_FAILURE; + } +#endif + + i = 0; + gcc_argv[i++] = GCC_BIN; + for ( j = 1 ; j < argc ; j++ ) { + gcc_argv[i++] = argv[j]; + } + if (use_stdinc) { + gcc_argv[i++] = nostdinc; + gcc_argv[i++] = UCLIBC_INC; + gcc_argv[i++] = GCC_INCDIR; + } + if (linking && source_count) { + gcc_argv[i++] = "-static"; + if (use_start) { + if (debugging) { + gcc_argv[i++] = UCLIBC_START_G; + } else { + gcc_argv[i++] = UCLIBC_START; + } + } + if (use_stdlib) { + gcc_argv[i++] = "-nostdlib"; + if (debugging) { + gcc_argv[i++] = UCLIBC_LIB_G; + } else { + gcc_argv[i++] = UCLIBC_LIB; + } + gcc_argv[i++] = GCC_LIB; + } + } + gcc_argv[i++] = NULL; + +#ifdef DEBUG + for ( j = 0 ; gcc_argv[j] ; j++ ) { + printf("arg[%2i] = %s\n", j, gcc_argv[j]); + } + return EXIT_SUCCESS; +#else + return execvp(GCC_BIN, gcc_argv); +#endif +} + + + + diff --git a/include/getopt.h b/include/getopt.h index a4cb95496..725d9cbd4 100644 --- a/include/getopt.h +++ b/include/getopt.h @@ -1,18 +1,109 @@ -/* Copyright (C) 1996 Robert de Bath <rdebath@cix.compulink.co.uk> - * This file is part of the Linux-8086 C library and is distributed - * under the GNU Library General Public License. - */ +/* Declarations for getopt. + Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. -#ifndef __GETOPT_H -#define __GETOPT_H +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +#ifndef _GETOPT_H +#define _GETOPT_H 1 #include <features.h> +#ifdef __cplusplus +extern "C" { +#endif + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + extern char *optarg; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns EOF, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + extern int optind; + +/* Callers store zero here to inhibit the error message `getopt' prints + for unrecognized options. */ + extern int opterr; + +/* Set to an option character which was unrecognized. */ + extern int optopt; +/* Describe the long-named options requested by the application. + The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector + of `struct option' terminated by an element containing a name which is + zero. + + The field `has_arg' is: + no_argument (or 0) if the option does not take an argument, + required_argument (or 1) if the option requires an argument, + optional_argument (or 2) if the option takes an optional argument. + + If the field `flag' is not NULL, it points to a variable that is set + to the value given in the field `val' when the option is found, but + left unchanged if the option is not found. + + To have a long-named option do something other than set an `int' to + a compiled-in constant, such as set a value from `optarg', set the + option's `flag' field to zero and its `val' field to a nonzero + value (the equivalent single-letter option character, if there is + one). For long options that have a zero `flag' field, `getopt' + returns the contents of the `val' field. */ + +struct option +{ + const char *name; + /* has_arg can't be an enum because some compilers complain about + type mismatches in all the code that assumes it is an int. */ + int has_arg; + int *flag; + int val; +}; + +/* Names for the values of the `has_arg' field of `struct option'. */ + +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + extern int getopt __P((int argc, char *const *argv, const char *shortopts)); +extern int getopt_long __P((int argc, char *const *argv, const char *shortopts, + const struct option *longopts, int *longind)); +extern int getopt_long_only __P((int argc, char *const *argv, + const char *shortopts, + const struct option *longopts, int *longind)); + +#ifdef __cplusplus +} +#endif -#endif /* __GETOPT_H */ +#endif /* _GETOPT_H */ diff --git a/include/stdio.h b/include/stdio.h index a7a468788..01f6667ef 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -105,16 +105,12 @@ typedef struct __stdio_file FILE; #include <bits/stdio_lim.h> #undef __need_FOPEN_MAX - -/* Standard streams. */ -extern FILE stdin[1]; /* Standard input stream. */ -extern FILE stdout[1]; /* Standard output stream. */ -extern FILE stderr[1]; /* Standard error output stream. */ +/* Standard streams (internal). */ +extern FILE _stdio_streams[3]; /* C89/C99 say they're macros. Make them happy. */ -#define stdin stdin -#define stdout stdout -#define stderr stderr - +#define stdin (_stdio_streams) +#define stdout (_stdio_streams+1) +#define stderr (_stdio_streams+2) /* Remove file FILENAME. */ extern int remove __P ((__const char *__filename)); diff --git a/include/sys/param.h b/include/sys/param.h index 511c2ae1e..c59222cd4 100644 --- a/include/sys/param.h +++ b/include/sys/param.h @@ -9,7 +9,7 @@ #include <features.h> #include <limits.h> #include <linux/limits.h> -#include <linux/param.h> +#include <asm/param.h> #include <sys/types.h> diff --git a/libc/inet/Makefile b/libc/inet/Makefile index de5d90d74..56e783ceb 100644 --- a/libc/inet/Makefile +++ b/libc/inet/Makefile @@ -66,8 +66,8 @@ $(MOBJ3): $(MSRC3) $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o $(STRIPTOOL) -x -R .note -R .comment $*.o -$(COBJS): - $(CC) $(CFLAGS) $< -c $*.c -o $*.o +$(COBJS): %.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ $(STRIPTOOL) -x -R .note -R .comment $*.o clean: subdirs_clean diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c index 7abc9b506..18f366e87 100644 --- a/libc/inet/resolv.c +++ b/libc/inet/resolv.c @@ -455,6 +455,8 @@ int dns_lookup(const char *name, int type, int nscount, const char **nsip, extern int searchdomains; extern const char * searchdomain[MAX_SEARCH]; + fd = -1; + if (!packet || !lookup || !nscount) goto fail; @@ -462,8 +464,6 @@ int dns_lookup(const char *name, int type, int nscount, const char **nsip, ns %= nscount; - fd = -1; - while (retries++ < MAX_RETRIES) { if (fd != -1) diff --git a/libc/inet/rpc/Makefile b/libc/inet/rpc/Makefile index 082c78a55..ade5d2422 100644 --- a/libc/inet/rpc/Makefile +++ b/libc/inet/rpc/Makefile @@ -39,8 +39,8 @@ COBJS=$(patsubst %.c,%.o, $(CSRC)) all: $(COBJS) $(LIBC) -$(COBJS): - $(CC) $(CFLAGS) $< -c $*.c -o $*.o +$(COBJS): %.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ $(STRIPTOOL) -x -R .note -R .comment $*.o $(LIBC): $(COBJS) diff --git a/libc/misc/Makefile b/libc/misc/Makefile index 6a3275903..3f84a5065 100644 --- a/libc/misc/Makefile +++ b/libc/misc/Makefile @@ -39,7 +39,7 @@ libc.a: subdirs tags: ctags -R - + clean: subdirs_clean rm -f *.[oa] *~ core diff --git a/libc/misc/assert/Makefile b/libc/misc/assert/Makefile index abc2261ba..d6023490f 100644 --- a/libc/misc/assert/Makefile +++ b/libc/misc/assert/Makefile @@ -35,8 +35,8 @@ $(LIBC): ar-target ar-target: $(OBJS) $(AR) $(ARFLAGS) $(LIBC) $(OBJS) -$(COBJS): - $(CC) $(CFLAGS) $< -c $*.c -o $*.o +$(COBJS): %.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ $(STRIPTOOL) -x -R .note -R .comment $*.o clean: diff --git a/libc/misc/fnmatch/Makefile b/libc/misc/fnmatch/Makefile index 2a952881e..ce2ac2a47 100644 --- a/libc/misc/fnmatch/Makefile +++ b/libc/misc/fnmatch/Makefile @@ -35,8 +35,8 @@ $(LIBC): ar-target ar-target: $(OBJS) $(AR) $(ARFLAGS) $(LIBC) $(OBJS) -$(COBJS): - $(CC) $(CFLAGS) $< -c $*.c -o $*.o +$(COBJS): %.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ $(STRIPTOOL) -x -R .note -R .comment $*.o clean: diff --git a/libc/misc/glob/Makefile b/libc/misc/glob/Makefile index 557106488..8254381ea 100644 --- a/libc/misc/glob/Makefile +++ b/libc/misc/glob/Makefile @@ -35,8 +35,8 @@ $(LIBC): ar-target ar-target: $(OBJS) $(AR) $(ARFLAGS) $(LIBC) $(OBJS) -$(COBJS): - $(CC) $(CFLAGS) $< -c $*.c -o $*.o +$(COBJS): %.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ $(STRIPTOOL) -x -R .note -R .comment $*.o clean: diff --git a/libc/misc/internals/Makefile b/libc/misc/internals/Makefile index be19bbf7b..da693ce51 100644 --- a/libc/misc/internals/Makefile +++ b/libc/misc/internals/Makefile @@ -39,8 +39,8 @@ $(LIBC): ar-target ar-target: $(OBJS) $(AR) $(ARFLAGS) $(LIBC) $(OBJS) -$(COBJS): - $(CC) $(CFLAGS) $< -c $*.c -o $*.o +$(COBJS): %.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ $(STRIPTOOL) -x -R .note -R .comment $*.o clean: diff --git a/libc/misc/lock/Makefile b/libc/misc/lock/Makefile index 6a925b882..041ca5404 100644 --- a/libc/misc/lock/Makefile +++ b/libc/misc/lock/Makefile @@ -35,8 +35,8 @@ $(LIBC): ar-target ar-target: $(OBJS) $(AR) $(ARFLAGS) $(LIBC) $(OBJS) -$(COBJS): - $(CC) $(CFLAGS) $< -c $*.c -o $*.o +$(COBJS): %.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ $(STRIPTOOL) -x -R .note -R .comment $*.o clean: diff --git a/libc/misc/lsearch/Makefile b/libc/misc/lsearch/Makefile index 82f70be97..5ea47e14d 100644 --- a/libc/misc/lsearch/Makefile +++ b/libc/misc/lsearch/Makefile @@ -35,8 +35,8 @@ $(LIBC): ar-target ar-target: $(OBJS) $(AR) $(ARFLAGS) $(LIBC) $(OBJS) -$(COBJS): - $(CC) $(CFLAGS) $< -c $*.c -o $*.o +$(COBJS): %.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ $(STRIPTOOL) -x -R .note -R .comment $*.o clean: diff --git a/libc/misc/mntent/Makefile b/libc/misc/mntent/Makefile index fc8cfb33a..ee163c182 100644 --- a/libc/misc/mntent/Makefile +++ b/libc/misc/mntent/Makefile @@ -35,8 +35,8 @@ $(LIBC): ar-target ar-target: $(OBJS) $(AR) $(ARFLAGS) $(LIBC) $(OBJS) -$(COBJS): - $(CC) $(CFLAGS) $< -c $*.c -o $*.o +$(COBJS): %.o : %.c + $(CC) $(CFLAGS) -c $< -o $@ $(STRIPTOOL) -x -R .note -R .comment $*.o clean: diff --git a/libc/misc/regex/Makefile b/libc/misc/regex/Makefile index 66a585a63..89912aa74 100644 --- a/libc/misc/regex/Makefile +++ b/ |