diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-04-05 20:54:00 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-04-05 20:54:00 +0000 |
commit | 16be59858afa332cc8a0f8e61a215e1deea5e897 (patch) | |
tree | 0159742e27848cfac6eec8d9d87bd6579af48c18 /nuttx/lib | |
parent | 3607bf2b4b1f2087cfb52ab4591f2ac347698a9c (diff) | |
download | px4-nuttx-16be59858afa332cc8a0f8e61a215e1deea5e897.tar.gz px4-nuttx-16be59858afa332cc8a0f8e61a215e1deea5e897.tar.bz2 px4-nuttx-16be59858afa332cc8a0f8e61a215e1deea5e897.zip |
Clean kernel-/user-mode module build
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3469 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib')
-rw-r--r-- | nuttx/lib/Makefile | 30 | ||||
-rw-r--r-- | nuttx/lib/lib_internal.h | 34 | ||||
-rw-r--r-- | nuttx/lib/misc/lib_init.c | 3 | ||||
-rwxr-xr-x | nuttx/lib/stdio/lib_dtoa.c | 5 | ||||
-rw-r--r-- | nuttx/lib/stdio/lib_fclose.c | 5 | ||||
-rw-r--r-- | nuttx/lib/string/lib_strdup.c | 5 | ||||
-rw-r--r-- | nuttx/lib/unistd/lib_chdir.c | 2 |
7 files changed, 69 insertions, 15 deletions
diff --git a/nuttx/lib/Makefile b/nuttx/lib/Makefile index 54ba764ff..2484fc3bf 100644 --- a/nuttx/lib/Makefile +++ b/nuttx/lib/Makefile @@ -80,7 +80,9 @@ QUEUEDEPPATH = --dep-path queue MISCDEPPATH = --dep-path misc VPATH = stdio:stdlib:unistd:sched:string:pthread:semaphore:signal:mqueue:math:net:time:libgen:queue:misc -BIN = liblib$(LIBEXT) +UBIN = libulib$(LIBEXT) +KBIN = libklib$(LIBEXT) +BIN = liblib$(LIBEXT) all: $(BIN) @@ -95,6 +97,22 @@ $(BIN): $(OBJS) $(call ARCHIVE, $@, $${obj}); \ done ; ) +ifneq ($(BIN),$(UBIN)) +.userlib: + @$(MAKE) $(UBIN) BIN=$(UBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) + @touch .userlib + +$(UBIN): kclean .userlib +endif + +ifneq ($(BIN),$(KBIN)) +.kernlib: + @$(MAKE) $(KBIN) BIN=$(KBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES) + @touch .kernlib + +$(KBIN): uclean .kernlib +endif + .depend: Makefile $(SRCS) @$(MKDEP) $(ROOTDEPPATH) $(STDIODEPPATH) $(STDLIBDEPPATH) \ $(UNISTDDEPPATH) $(SCHEDDEPPATH) $(STRINGDEPPATH) $(PTHREADDEPPATH) \ @@ -105,7 +123,15 @@ $(BIN): $(OBJS) depend: .depend -clean: +uclean: + @rm -f $(UBIN) .userlib *~ .*.swp + $(call CLEAN) + +kclean: + @rm -f $(KBIN) .kernlib *~ .*.swp + $(call CLEAN) + +clean: uclean kclean @rm -f $(BIN) *~ .*.swp $(call CLEAN) diff --git a/nuttx/lib/lib_internal.h b/nuttx/lib/lib_internal.h index 6ec2fe201..b9c74304e 100644 --- a/nuttx/lib/lib_internal.h +++ b/nuttx/lib/lib_internal.h @@ -1,7 +1,7 @@ /**************************************************************************** * lib/lib_internal.h * - * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -47,6 +47,7 @@ #include <stdio.h> #include <limits.h> #include <semaphore.h> + #include <nuttx/streams.h> /**************************************************************************** @@ -57,10 +58,35 @@ # define CONFIG_LIB_HOMEDIR "/" #endif +/* If C std I/O buffering is not supported, then we don't need its semaphore + * protection. + */ + #if CONFIG_STDIO_BUFFER_SIZE <= 0 -# define lib_sem_initialize(s) -# define lib_take_semaphore(s) -# define lib_give_semaphore(s) +# define lib_sem_initialize(s) +# define lib_take_semaphore(s) +# define lib_give_semaphore(s) +#endif + +/* The NuttX C library an be build in two modes: (1) as a standard, C-libary + * that can be used by normal, user-space applications, or (2) as a special, + * kernel-mode C-library only used within the OS. If NuttX is not being + * built as separated kernel- and user-space modules, then only the first + * mode is supported. + */ + +#if defined(CONFIG_NUTTX_KERNEL) && defined(__KERNEL__) +# include <nuttx/kmalloc.h> +# define lib_malloc(s) kmalloc(s) +# define lib_zalloc(s) kzalloc(s) +# define lib_realloc(p,s) krealloc(p,s) +# define lib_free(p) kfree(p) +#else +# include <stdlib.h> +# define lib_malloc(s) malloc(s) +# define lib_zalloc(s) zalloc(s) +# define lib_realloc(p,s) realloc(p,s) +# define lib_free(p) free(p) #endif #define LIB_BUFLEN_UNKNOWN INT_MAX diff --git a/nuttx/lib/misc/lib_init.c b/nuttx/lib/misc/lib_init.c index 107c73c07..112b0a3c7 100644 --- a/nuttx/lib/misc/lib_init.c +++ b/nuttx/lib/misc/lib_init.c @@ -40,7 +40,6 @@ #include <nuttx/config.h> #include <stdio.h> -#include <stdlib.h> #include <string.h> #include <errno.h> @@ -83,7 +82,7 @@ void weak_const_function lib_initialize(void) FAR struct streamlist *lib_alloclist(void) { FAR struct streamlist *list; - list = (FAR struct streamlist*)zalloc(sizeof(struct streamlist)); + list = (FAR struct streamlist*)lib_zalloc(sizeof(struct streamlist)); if (list) { int i; diff --git a/nuttx/lib/stdio/lib_dtoa.c b/nuttx/lib/stdio/lib_dtoa.c index 942ed2033..894af4f42 100755 --- a/nuttx/lib/stdio/lib_dtoa.c +++ b/nuttx/lib/stdio/lib_dtoa.c @@ -45,10 +45,11 @@ #include <nuttx/config.h> -#include <stdlib.h> #include <stdint.h> #include <string.h> +#include "lib_internal.h" + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -142,7 +143,7 @@ static Bigint *Balloc(int k) else { x = 1 << k; - rv = (Bigint *) malloc(sizeof(Bigint) + (x - 1) * sizeof(long)); + rv = (Bigint *)lib_malloc(sizeof(Bigint) + (x - 1) * sizeof(long)); rv->k = k; rv->maxwds = x; } diff --git a/nuttx/lib/stdio/lib_fclose.c b/nuttx/lib/stdio/lib_fclose.c index 4a9ded90b..8d53b387b 100644 --- a/nuttx/lib/stdio/lib_fclose.c +++ b/nuttx/lib/stdio/lib_fclose.c @@ -39,12 +39,13 @@ #include <nuttx/config.h> -#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <errno.h> +#include "lib_internal.h" + /**************************************************************************** * Global Functions ****************************************************************************/ @@ -68,7 +69,7 @@ int fclose(FAR FILE *stream) if (stream->fs_bufstart) { - free(stream->fs_bufstart); + lib_free(stream->fs_bufstart); } /* Clear the whole structure */ diff --git a/nuttx/lib/string/lib_strdup.c b/nuttx/lib/string/lib_strdup.c index 04ecaffbe..a353c629d 100644 --- a/nuttx/lib/string/lib_strdup.c +++ b/nuttx/lib/string/lib_strdup.c @@ -39,9 +39,10 @@ #include <nuttx/config.h> -#include <stdlib.h> #include <string.h> +#include "lib_internal.h" + /************************************************************************ * Global Functions ************************************************************************/ @@ -51,7 +52,7 @@ FAR char *strdup(const char *s) FAR char *news = NULL; if (s) { - news = (FAR char*)malloc(strlen(s) + 1); + news = (FAR char*)lib_malloc(strlen(s) + 1); if (news) { strcpy(news, s); diff --git a/nuttx/lib/unistd/lib_chdir.c b/nuttx/lib/unistd/lib_chdir.c index c054f2b23..f79b424ff 100644 --- a/nuttx/lib/unistd/lib_chdir.c +++ b/nuttx/lib/unistd/lib_chdir.c @@ -164,7 +164,7 @@ int chdir(FAR const char *path) alloc = strdup(oldpwd); /* kludge needed because environment is realloc'ed */ setenv("OLDPWD", alloc, TRUE); - free(alloc); + lib_free(alloc); /* Set the cwd to the input 'path' */ |