From f7a440b9c7bb0c686dc2368c4ff53b20bf6371f8 Mon Sep 17 00:00:00 2001 From: Owen Shepherd Date: Sun, 12 Aug 2012 19:47:31 +0100 Subject: [PATCH] * New feature check macro system. See _PDCLIB_aux.h for details * remove "#pragma weak" from strdup.c. It's nonportable and shouldn't be necessary * changed to use new feature test system for strdup + strndup * add strndup implementation * more reliable handling of error messages Build system: * The CoreMake system is dead. It proved to be unscalable * The old Make based system is gone, also * We now use a Jam based system (requires the latest FT_Jam). Reasons: * Make is hard to scale in a non-recursive manner. The interactions get intractably complex * The build system depended upon GNU Make. GNU Make's license (the GPLv3) is about as diametrically opposed to PDCLib's CC0 as you can get without being closed source * Jam is actually more portable. In particular, it doesn't require a Unix emulation layer (unlike GMake) * The Jam system, as is, can be incorporated into the build system of a larger project. Why Jam? * GNU make is too low level. It also incorporates too much magic: it can spend significant ammounts of time trying to update source files from SCCS and RCS files for example (a feature it is doubtful somebody has used in the last decade) * Systems like CMake are too high level: CMake is very difficult to use in a cross compilation environment. * Systems like Scons and Waf pose similar issues. Scons is also incredibly slow. --- CoreMakefile.mk | 42 ----- Jamfile | 43 +++++ Jamrules | 168 ++++++++++++++++++ Makefile | 131 -------------- functions/string/strdup.c | 1 - functions/string/strndup.c | 56 ++++++ includes/assert.h | 20 ++- includes/string.h | 3 +- internals/_PDCLIB_aux.h | 84 ++++++++- platform/example/Config.jam | 10 ++ .../_PDCLIB/{_Exit.c => _PDCLIB_Exit.c} | 0 platform/posix/Config.jam | 10 ++ .../_PDCLIB/{_Exit.c => _PDCLIB_Exit.c} | 0 13 files changed, 375 insertions(+), 193 deletions(-) delete mode 100644 CoreMakefile.mk create mode 100644 Jamfile create mode 100644 Jamrules delete mode 100644 Makefile create mode 100644 functions/string/strndup.c create mode 100644 platform/example/Config.jam rename platform/example/functions/_PDCLIB/{_Exit.c => _PDCLIB_Exit.c} (100%) create mode 100644 platform/posix/Config.jam rename platform/posix/functions/_PDCLIB/{_Exit.c => _PDCLIB_Exit.c} (100%) diff --git a/CoreMakefile.mk b/CoreMakefile.mk deleted file mode 100644 index 39c96be..0000000 --- a/CoreMakefile.mk +++ /dev/null @@ -1,42 +0,0 @@ -TARGETS = pdclib - -ifndef PDCLIB_PLATFORM_EXT -endif - -ifndef PDCLIB_MALLOC - $(error malloc to use unspecified. Set PDCLIB_MALLOC.) -endif - -ifeq ($(PDCLIB_MALLOC),solar) - pdclib_SOURCEDIRS += opt/malloc-solar -else -ifeq ($(PDCLIB_MALLOC),dlmalloc) - pdclib_SOURCEDIRS += opt/dlmalloc -else - $(error Bad malloc specified. Supported: solar, ptmalloc3) -endif -endif - -# No: -Wcast-align; spurious for uses of char* to do pointer arithmetic -# No: -Winline; generates spirous errors on -Os builds -# No: -Wredundant-decls; redefinition of functions is legal and sometimes required -# (especially applicable to PDCLib sources) -# -Wno-unused-parameter; unused parameters are common in some interfaces -WARNINGS := -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Wno-long-long -Wuninitialized -Wstrict-prototypes -Wno-unused-parameter - -pdclib_COMFLAGS += -ffreestanding $(WARNINGS) -pdclib_CFLAGS += -std=c11 -pdclib_SOURCEDIRS += functions/_PDCLIB functions/ctype functions/inttypes \ - functions/locale functions/stdio functions/stdlib \ - functions/string/ -pdclib_OUT_TYPE += archive -pdclib_INCLUDE_DIRS += $(pdclib_SOURCE_DIR)/includes $(pdclib_SOURCE_DIR)/internals - -ifdef PDCLIB_OPT_NOTHREAD - pdclib_SOURCEDIRS += opt/nothread - pdclib_INCLUDE_DIRS += $(pdclib_SOURCE_DIR)/opt/nothread -endif - -ifdef PDCLIB_OPT_NOTIME - pdclib_SOURCEDIRS += opt/notime -endif \ No newline at end of file diff --git a/Jamfile b/Jamfile new file mode 100644 index 0000000..971e21d --- /dev/null +++ b/Jamfile @@ -0,0 +1,43 @@ +SubDir PDCLIB_TOP ; +PDCLibConfig ; + +PDCLIB_SOURCES = [ RecursiveGlob $(PDCLIB_TOP) : [ FDirName functions ] : *.c ] ; + +if $(PDCLIB_PLATFORM) { + PDCLIB_PLATFORM_SOURCE_DIR = + [ FDirName platform $(PDCLIB_PLATFORM) functions ] ; + PDCLIB_SOURCES += [ RecursiveGlob $(PDCLIB_TOP) : $(PDCLIB_PLATFORM_SOURCE_DIR) : *.c ] ; +} + +for opt in $(PDCLIB_OPTIONS) { + optdir = [ FDirName opt $(opt) ] ; + PDCLIB_SOURCES += [ RecursiveGlob $(PDCLIB_TOP) : $(optdir) : *.c ] ; +} + +Library $(PDCLIB) : $(PDCLIB_SOURCES) ; + +if ! $(PDCLIB_NO_TEST) { + for file in $(PDCLIB_SOURCES) { + testfile = $(file:S=_t) ; + regtestfile = $(file:S=_r) ; + test = $(file:S=-test) ; + regtest = $(file:S=-regtest) ; + + Object $(testfile).o : $(file) ; + Object $(regtestfile).o : $(file) ; + MainFromObjects $(testfile) : $(testfile).o ; + MainFromObjects $(regtestfile) : $(regtestfile).o ; + CCFLAGS on $(testfile).o += -DTEST $(PDCLIB_TEST_CCFLAGS) ; + CCFLAGS on $(regtestfile).o += -DTEST -DREGTEST + $(PDCLIB_REGTEST_CCFLAGS) ; + + LINKFLAGS on $(testfile)$(SUFEXE) += $(PDCLIB_TEST_LINKFLAGS) ; + LINKFLAGS on $(regtestfile)$(SUFEXE) += $(PDCLIB_REGTEST_LINKFLAGS) ; + LINKLIBS on $(testfile)$(SUFEXE) += $(PDCLIB_TEST_LINKLIBS) ; + LINKLIBS on $(regtestfile)$(SUFEXE) += $(PDCLIB_REGTEST_LINKLIBS) ; + LinkLibraries $(testfile) : $(PDCLIB) ; + + Test $(test) : $(testfile) ; + RegTest $(regtest) : $(regtestfile) ; + } +} \ No newline at end of file diff --git a/Jamrules b/Jamrules new file mode 100644 index 0000000..8657cc9 --- /dev/null +++ b/Jamrules @@ -0,0 +1,168 @@ +PDCLIB ?= pdclib ; + +ECHO "PDCLIB_TOP: " $(PDCLIB_TOP) ; + +if ! $(PDCLIB_HAVE_PLATFORM) && ! $(PDCLIB_PLATFORM) { + if $(NT) { + PDCLIB_PLATFORM = "win32" ; + } else if $(UNIX) { + PDCLIB_PLATFORM = "posix" ; + } else { + ECHO "PDCLIB_PLATFORM not set and platform not automatically detected" ; + ECHO "Set PDCLIB_PLATFORM to the platform to be built for" ; + EXIT ; + } + PDCLIB_HAVE_PLATFORM = 1 ; +} + +#if $(CC) = "gcc" { +# TODO: Better toolchain handling + + # No -Wcast-align : spurious warnings when using char* to do pointer + # arithmetic + # No -Winline : when compiling with e.g. -Os causes spurious + # warnings that call is unlikely/code size would grow + # No -Wredundant-decls : some functions must be multiply defined + PDCLIB_WARNINGS ?= + -Wall -Wextra -pedantic -Wno-unused-parameter -Wshadow + -Wpointer-arith -Wwrite-strings -Wmissing-declarations -Wno-long-long + -Wuninitialized + ; + PDCLIB_CCWARNINGS ?= + -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes ; + PDCLIB_CCFLAGS = + -ffreestanding + -nostdinc + -std=c11 + -g + -D_PDCLIB_BUILD + $(PDCLIB_WARNINGS) ; + PDCLIB_C++FLAGS = + -ffreestanding + -nostdinc + -std=c++11 + -g + -D_PDCLIB_BUILD + $(PDCLIB_WARNINGS) ; + + actions Link bind NEEDLIBS + { + $(LINK) $(LINKFLAGS) -o $(<) $(UNDEFS) $(>) -Wl,--start-group $(NEEDLIBS) $(LINKLIBS) -Wl,--end-group + } +#} + +if $(PDCLIB_PLATFORM) { + include [ FDirName $(PDCLIB_TOP) platform $(PDCLIB_PLATFORM) Config.jam ] ; +} + +rule PDCLibHeaders { + SubDirHdrs $(PDCLIB_TOP) includes ; + SubDirHdrs $(PDCLIB_TOP) internals ; + SubDirHdrs $(PDCLIB_TOP) testing ; + for opt in $(PDCLIB_OPTIONS) { + SubDirHdrs $(PDCLIB_TOP) opt $(opt) ; + } + PDCLibTargetHeaders ; +} + +rule PDCLibConfig { + SubDirCcFlags $(PDCLIB_CCFLAGS) ; + SubDirC++Flags $(PDCLIB_C++FLAGS) ; + PDCLibHeaders ; + PDCLibTargetConfig ; +} + +# MinGW needs appropriate prodding to cretae executables +if $(TOOLSET) = MINGW { + PDCLIB_TEST_LINKFLAGS += -mconsole ; + PDCLIB_REGTEST_LINKFLAGS += -mconsole ; +} + +# Tests +ALWAYS regtest test ; + +rule Test { + DEPENDS $(<) : $(>) ; + ALWAYS $(<) ; + DEPENDS test : $(<) ; +} + +rule RegTest { + DEPENDS $(<) : $(>) ; + ALWAYS $(<) ; + DEPENDS regtest : $(<) ; +} + +actions Test { + $(>) +} + +actions RegTest { + $(>) +} + +# list all files in a directory, except ., .. +# [ ListDir base : dirname ] +rule ListDir { + # start with empty list + local _result = ; + + # for each file in the directory + local _dirlist = [ GLOB [ FDirName $(1) $(2) ] : * ] ; + for _subdir in $(_dirlist) { + + # if it is not . or .. + switch $(_subdir) { + case *\\. : _dummy = "" ; # is there some no-op statement? + case *\\.. : _dummy = "" ; # is there some no-op statement? + case * : + # add it to the list + _result += $(_subdir:D=$(2)) ; + } + } + + # return resulting list + return $(_result) ; +} + +# same as glob, but recurses into subdirs +rule RecursiveGlob { + # initially use the files in the current directory + local _dir = $(2) ; + local _path = [ FDirName $(1) $(2) ] ; + local _result = [ GLOB $(_path) : $(3) ] ; + _result = $(_result:D=$(_dir)) ; + + # list all subdirectories (and files, but it doesn't hurt) + local _subdirlist = [ ListDir $(1) : $(2) ] ; + + # for each subdir/file + for _subdir in $(_subdirlist) { + # recurse into it + _result += [ RecursiveGlob $(1) : $(_subdir) : $(3) ] ; + } + + # return the resulting list + return $(_result) ; +} + +# Fix to work on targets in subdirs +rule MakeLocate +{ + # Note we grist the directory name with 'dir', + # so that directory path components and other + # targets don't conflict. + + if $(>) + { + local _rev = [ FReverse $(>) ] ; + if $(_rev[1]) = "." { + _rev = $(_rev[2-]) ; + } + local _dir = [ FDirName [ FReverse $(_rev) ] $(<[0]:D) ] ; + + LOCATE on $(<) = [ FDirName $(>) ] ; + Depends $(<) : $(_dir:G=dir) ; + MkDir $(_dir:G=dir) ; + } +} \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index fa2976a..0000000 --- a/Makefile +++ /dev/null @@ -1,131 +0,0 @@ -# $Id$ - -# This is where you chose which platform to compile for (see 'make links' / './platform') -PLATFORM := example - -# This is a list of all non-source files that are part of the distribution. -AUXFILES := Makefile Readme.txt - -# Directories belonging to the project -PROJDIRS := functions includes internals -# All source files of the project -SRCFILES := $(shell find -L $(PROJDIRS) -type f -name "*.c") -# All header files of the project -HDRFILES := $(shell find -L $(PROJDIRS) -type f -name "*.h") -# All .c files in functions/_PDCLIB that do not have a regression test driver -INTFILES := _Exit atomax digits open print scan remove rename seed stdinit strtox_main strtox_prelim filemode eol errno seek prepread prepwrite allocpages tmpfilename closeall -# All object files in the library -OBJFILES := $(patsubst %.c,%.o,$(SRCFILES)) -# All test drivers (.t) -TSTFILES := $(patsubst %.c,%_t,$(SRCFILES)) -# All regression test drivers (.r) -REGFILES := $(filter-out $(patsubst %,functions/_PDCLIB/%_r,$(INTFILES)),$(patsubst %.c,%_r,$(SRCFILES))) -# All library dependency files (.d) -DEPFILES := $(patsubst %.c,%.d,$(SRCFILES)) -# All test driver dependency files (_t.d) -TSTDEPFILES := $(patsubst %,%.d,$(TSTFILES)) -# All regression test driver dependency files (_r.d) -REGDEPFILES := $(patsubst %,%.d,$(REGFILES)) -# All files belonging to the source distribution -ALLFILES := $(SRCFILES) $(HDRFILES) $(AUXFILES) - -WARNINGS := -Wall -Wextra -pedantic -Wno-unused-parameter -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wuninitialized -Wstrict-prototypes -CFLAGS := -fno-builtin -g -std=c99 -I./internals -I./testing $(WARNINGS) $(USERFLAGS) - -.PHONY: all clean srcdist bindist test tests testdrivers regtests regtestdrivers todos fixmes find links unlink help - -all: pdclib.a testdrivers regtestdrivers - @echo - @echo "========================" - @echo "Executing library tests:" - @echo "========================" - @echo - @$(MAKE) tests | grep -v "^ TST" | grep -v "^Failed" - @echo - @echo "===========================" - @echo "Executing regression tests:" - @echo "===========================" - @echo - @$(MAKE) regtests | grep -v "^ RTST" | grep -v "^Failed" - -pdclib.a: $(OBJFILES) - @echo " AR $@" - @ar rc pdclib.a $? - @echo - -test: functions/$(FILE) - functions/$(FILE) - -tests: testdrivers - -@rc=0; count=0; failed=""; for file in $(TSTFILES); do echo " TST $$file"; ./$$file; test=$$?; if [ $$test != 0 ]; then rc=`expr $$rc + $$test`; failed="$$failed $$file"; fi; count=`expr $$count + 1`; done; echo; echo "Tests executed (linking PDCLib): $$count Tests failed: $$rc"; echo; for file in $$failed; do echo "Failed: $$file"; done; echo - -testdrivers: $(TSTFILES) - @echo - -regtests: regtestdrivers - -@rc=0; count=0; failed=""; for file in $(REGFILES); do echo " RTST $$file"; ./$$file; test=$$?; if [ $$test != 0 ]; then rc=`expr $$rc + $$test`; failed="$$failed $$file"; fi; count=`expr $$count + 1`; done; echo; echo "Tests executed (linking system libc): $$count Tests failed: $$rc"; echo; for file in $$failed; do echo "Failed: $$file"; done; echo - -regtestdrivers: $(REGFILES) - @echo - --include $(DEPFILES) $(TSTDEPFILES) $(REGDEPFILES) - -clean: - -@$(RM) $(wildcard $(OBJFILES) $(DEPFILES) $(TSTFILES) $(TSTDEPFILES) $(REGFILES) $(REGDEPFILES) pdclib.a pdclib.tgz scanf_testdata_*) - -srcdist: - @tar czf pdclib.tgz $(ALLFILES) - -todos: - -@for file in $(ALLFILES:Makefile=); do grep -H TODO $$file; done; true - -fixmes: - -@for file in $(ALLFILES:Makefile=); do grep -H FIXME $$file; done; true - -find: - @find functions/ includes/ internals/ platform/ -name "*\.[ch]" -type f | xargs grep $$FIND - -links: - @echo "Linking platform/$(PLATFORM)..." - @for file in $$(find platform/$(PLATFORM) -mindepth 2 -type f ! -path *.svn* -printf "%P\n"); do ln -s $$(dirname $$file | sed "s@[^/]*@..@g")/platform/$(PLATFORM)/$$file $$file; done - -unlink: - @echo "Unlinking platform files..." - @for dir in $(PROJDIRS); do find $$dir -type l -exec rm {} +; done - -help: - @echo "Available make targets:" - @echo - @echo "all - build pdclib.a" - @echo "clean - remove all object files, dependency files and test drivers" - @echo "srcdist - build pdclib.tgz (source tarball)" - @echo "test - test a single testdriver (Usage: FILE=\"test.[rt]\" make test)" - @echo "tests - build and run test drivers (link pdclib.a)" - @echo " testdrivers - build but do not run test drivers" - @echo "regtests - build and run regression test drivers (link system clib)" - @echo " regtestdrivers - build but do not run regression test drivers" - @echo "todos - list all TODO comments in the sources" - @echo "fixmes - list all FIXME comments in the sources" - @echo "find - find a phrase in the sources (Usage: FIND=\"phrase\" make find)" - @echo "links - link platform files (development only)" - @echo "unlink - remove links to platform files (development only)" - @echo "%.o - build an individual object file" - @echo "%.t - build an individual test driver" - @echo "%.r - build an individual regression test driver" - @echo "help - print this list" - @echo - @echo "Any additional compiler flags you want to use can be passed as USERFLAGS" - @echo "(Usage: USERFLAGS=\"flags\" make [...])." - -%.o: %.c Makefile - @echo " CC $(patsubst functions/%,%,$@)" - @$(CC) $(CFLAGS) -MMD -MP -I./includes -c $< -o $@ - -%_t: %.c Makefile pdclib.a - @echo " CC $(patsubst functions/%,%,$@)" - @$(CC) $(CFLAGS) -MMD -MP -DTEST -I./includes $< pdclib.a -o $@ - -%_r: %.c Makefile - @echo " CC $(patsubst functions/%,%,$@)" - @$(CC) $(CFLAGS) -MMD -MP -DTEST -DREGTEST $< -o $@ - diff --git a/functions/string/strdup.c b/functions/string/strdup.c index ac2200e..6ed0f83 100644 --- a/functions/string/strdup.c +++ b/functions/string/strdup.c @@ -9,7 +9,6 @@ #ifndef REGTEST -#pragma weak strdup char *strdup(const char *s) { char* ns = NULL; diff --git a/functions/string/strndup.c b/functions/string/strndup.c new file mode 100644 index 0000000..e25c7ed --- /dev/null +++ b/functions/string/strndup.c @@ -0,0 +1,56 @@ +/* [XSI] char* strndup(const char *, size_t) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#include + +#ifndef REGTEST + +char *strndup( const char * s, size_t len ) +{ + char* ns = NULL; + if(s) { + ns = malloc(len + 1); + if(ns) { + ns[len] = 0; + // strncpy to be pedantic about modification in multithreaded + // applications + return strncpy(ns, s, len); + } + } + return ns; +} + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ + const char *teststr = "Hello, world"; + const char *teststr2 = "\xFE\x8C\n"; + char *testres, *testres2; + + TESTCASE(testres = strndup(teststr, 5)); + TESTCASE(testres2 = strndup(teststr2, 1)); + TESTCASE(strcmp(testres, teststr) != 0); + TESTCASE(strncmp(testres, teststr, 5) == 0); + TESTCASE(strcmp(testres2, teststr2) != 0); + TESTCASE(strncmp(testres2, teststr2, 1) == 0); + free(testres); + free(testres2); + TESTCASE(testres = strndup(teststr, 20)); + TESTCASE(testres2 = strndup(teststr2, 5)); + TESTCASE(strcmp(testres, teststr) == 0); + TESTCASE(strcmp(testres2, teststr2) == 0); + free(testres); + free(testres2); + + return TEST_RESULTS; +} + +#endif diff --git a/includes/assert.h b/includes/assert.h index 7874167..ca0022d 100644 --- a/includes/assert.h +++ b/includes/assert.h @@ -12,6 +12,7 @@ #include <_PDCLIB_config.h> _PDCLIB_BEGIN_EXTERN_C +/* Functions _NOT_ tagged noreturn as this hampers debugging */ void _PDCLIB_assert99( char const * const, char const * const, char const * const ); void _PDCLIB_assert89( char const * const ); @@ -20,23 +21,24 @@ void _PDCLIB_assert89( char const * const ); #ifdef NDEBUG #define assert( ignore ) ( (void) 0 ) -#elif _PDCLIB_C_VERSION >= 99 +#elif _PDCLIB_C_MIN(99) #define assert(expression) \ - do { if(!(expression)) \ - _PDCLIB_assert99("Assertion failed: " #expression \ + do { if(!(expression)) { \ + _PDCLIB_assert99("Assertion failed: " _PDCLIB_symbol2string(expression)\ ", function ", __func__, \ ", file " __FILE__ \ ", line " _PDCLIB_symbol2string( __LINE__ ) \ "." _PDCLIB_endl ); \ + } \ } while(0) #else #define assert(expression) \ - do { \ - if(!(expression)) \ - _PDCLIB_assert89( "Assertion failed: " #expression \ - ", file " __FILE__ \ - ", line " _PDCLIB_symbol2string( __LINE__ ) \ - "." _PDCLIB_endl ); \ + do { if(!(expression)) { \ + _PDCLIB_assert89("Assertion failed: " _PDCLIB_symbol2string(expression)\ + ", file " __FILE__ \ + ", line " _PDCLIB_symbol2string( __LINE__ ) \ + "." _PDCLIB_endl ); \ + } \ } while(0) #endif diff --git a/includes/string.h b/includes/string.h index d2b22e1..00309f5 100644 --- a/includes/string.h +++ b/includes/string.h @@ -184,8 +184,9 @@ char * strerror( int errnum ); */ size_t strlen( const char * s ); -#ifdef _PDCLIB_POSIX_EX +#if _PDCLIB_POSIX_MIN(2008098L) || _PDCLIB_XOPEN_MIN(0) char * strdup( const char* src ); +char * strndup( const char* src, size_t n ); #endif _PDCLIB_END_EXTERN_C diff --git a/internals/_PDCLIB_aux.h b/internals/_PDCLIB_aux.h index 8ea40f4..8990ed8 100644 --- a/internals/_PDCLIB_aux.h +++ b/internals/_PDCLIB_aux.h @@ -37,9 +37,10 @@ #endif #if !defined(__cplusplus) || defined(_PDCLIB_CXX_VERSION) - /* Pass - conditional simplification case */ + #define _PDCLIB_CXX_VERSION 0 #elif __cplusplus == 201103L #define _PDCLIB_CXX_VERSION 2011 + /* TODO: Do we want this? */ #if _PDCLIB_C_VERSION < 2011 #undef _PDCLIB_C_VERSION #define _PDCLIB_C_VERSION 2011 @@ -58,7 +59,8 @@ #endif #if _PDCLIB_CXX_VERSION >= 2011 - #define _PDCLIB_noreturn [[noreturn]] + // Hold off on C++ attribute syntax for now + // #define _PDCLIB_noreturn [[noreturn]] #elif _PDCLIB_C_VERSION >= 2011 #define _PDCLIB_noreturn _Noreturn #endif @@ -90,7 +92,8 @@ #endif #ifndef _PDCLIB_noreturn - #define _PDCLIB_noreturn __attribute__((noreturn)) + /* If you don't use __noreturn__, then stdnoreturn.h will break things! */ + #define _PDCLIB_noreturn __attribute__((__noreturn__)) #endif #endif @@ -111,7 +114,7 @@ #define _PDCLIB_API _PDCLIB_IMPORT #endif #else - #define _PDCLIB_API _PDCLIB_HIDDEN + #define _PDCLIB_API #endif #ifndef _PDCLIB_restrict @@ -160,11 +163,74 @@ #define _PDCLIB_symbol2value( x ) #x #define _PDCLIB_symbol2string( x ) _PDCLIB_symbol2value( x ) -#ifndef __PDCLIB_PURE - #define __PDCLIB_PURE 0 +/* Feature test macros + * + * All of the feature test macros come in the following forms + * _PDCLIB_*_MIN(min): Available in versions > min + * _PDCLIB_*_MINMAX(min, max): Available in versions > min < max + * _PDCLIB_*_MAX(max): Availabel in versions < max + * + * The defined tests are: + * C: C standard versions + * 1990, 1995, 1999, 2011 + * CXX: C++ standard versions + * 1997, 2011 + * POSIX: POSIX extension versions. + * 1 (POSIX.2), 2 (POSIX.2), 199309L (POSIX.1b), + * 199506L (POSIX.1c), 200112L (2001), 200809L (2008) + * XOPEN: X/Open System Interface (XSI)/Single Unix Specification + * 0 (XPG4), 500 (SUSv2/UNIX98), 600 (SUSv3/UNIX03), 700 (SUSv4) + * + * PDCLib does not attempt or claim POSIX comformance, but makes available these + * extensions as + * (a) useful, and + * (b) + */ +#define _PDCLIB_C_MIN(min) _PDCLIB_C_MINMAX(min, 3000) +#define _PDCLIB_CXX_MIN(min) _PDCLIB_CXX_MINMAX(min, 3000) +#define _PDCLIB_XOPEN_MIN(min) _PDCLIB_XOPEN_MINMAX(min, 30000000) +#define _PDCLIB_POSIX_MIN(min) _PDCLIB_POSIX_MINMAX(min, 30000000) +#define _PDCLIB_C_MAX(max) _PDCLIB_C_MINMAX(0, max) +#define _PDCLIB_CXX_MAX(max) _PDCLIB_CXX_MINMAX(0, max) +#define _PDCLIB_XOPEN_MAX(max) _PDCLIB_XOPEN_MINMAX(0, max) +#define _PDCLIB_POSIX_MAX(max) _PDCLIB_POSIX_MINMAX(0, max) +#if defined(_PDCLIB_ALL) || defined(_PDCLIB_BUILD) + #define _PDCLIB_C_MINMAX(min, max) 1 + #define _PDCLIB_CXX_MINMAX(min, max) 1 + #define _PDCLIB_POSIX_MINMAX(min, max) 1 + #define _PDCLIB_XOPEN_MINMAX(min, max) 1 +#else + #define _PDCLIB_C_MINMAX(min, max) \ + (_PDCLIB_C_VERSION >= (min) && _PDCLIB_C_VERSION <= (max)) + #define _PDCLIB_CXX_MINMAX(min, max) \ + (_PDCLIB_CXX_VERSION >= (min) && _PDCLIB_CXX_VERSION <= (max)) + #define _PDCLIB_XOPEN_MINMAX(min, max) \ + (defined(_XOPEN_SOURCE) \ + && _XOPEN_SOURCE >= (min) && _XOPEN_SOURCE <= (max)) + #define _PDCLIB_POSIX_MINMAX(min, max) \ + (defined(_POSIX_C_SOURCE) \ + && _POSIX_C_SOURCE >= (min) && _POSIX_C_SOURCE <= (max)) + + #if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE-1 == -1) + /* If _XOPEN_SOURCE is defined as empty, redefine here as zero */ + #undef _XOPEN_SOURCE + #define _XOPEN_SOURCE 0 + #endif + + #if _PDCLIB_XOPEN_MIN(700) && !_PDCLIB_POSIX_MIN(200809L) + #undef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 2008098L + #elif _PDCLIB_XOPEN_MIN(600) && !_PDCLIB_POSIX_MIN(200112L) + #undef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 200112L + #elif _PDCLIB_XOPEN_MIN(0) && !_PDCLIB_POSIX_MIN(2) + #undef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 2 + #endif + + #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) + #define _POSIX_C_SOURCE 1 + #endif #endif -#ifndef _PDCLIB_POSIX_EX - #define _PDCLIB_POSIX_EX (!__PDCLIB_PURE) -#endif #endif \ No newline at end of file diff --git a/platform/example/Config.jam b/platform/example/Config.jam new file mode 100644 index 0000000..7871eb8 --- /dev/null +++ b/platform/example/Config.jam @@ -0,0 +1,10 @@ +rule PDCLibTargetConfig { } +rule PDCLibTargetHeaders { + SubDirHdrs $(PDCLIB_TOP) platform example includes ; + SubDirHdrs $(PDCLIB_TOP) platform example internals ; +} + +PDCLIB_TEST_LINKFLAGS += -nostdlib ; +PDCLIB_TEST_LINKLIBS += -lgcc ; + +PDCLIB_OPTIONS = nothread notime dlmalloc ; \ No newline at end of file diff --git a/platform/example/functions/_PDCLIB/_Exit.c b/platform/example/functions/_PDCLIB/_PDCLIB_Exit.c similarity index 100% rename from platform/example/functions/_PDCLIB/_Exit.c rename to platform/example/functions/_PDCLIB/_PDCLIB_Exit.c diff --git a/platform/posix/Config.jam b/platform/posix/Config.jam new file mode 100644 index 0000000..92728f9 --- /dev/null +++ b/platform/posix/Config.jam @@ -0,0 +1,10 @@ +rule PDCLibTargetConfig { } +rule PDCLibTargetHeaders { + SubDirHdrs $(PDCLIB_TOP) platform posix includes ; + SubDirHdrs $(PDCLIB_TOP) platform posix internals ; +} + +PDCLIB_TEST_LINKFLAGS += -nostdlib ; +PDCLIB_TEST_LINKLIBS += -lgcc ; + +PDCLIB_OPTIONS = nothread notime dlmalloc ; \ No newline at end of file diff --git a/platform/posix/functions/_PDCLIB/_Exit.c b/platform/posix/functions/_PDCLIB/_PDCLIB_Exit.c similarity index 100% rename from platform/posix/functions/_PDCLIB/_Exit.c rename to platform/posix/functions/_PDCLIB/_PDCLIB_Exit.c -- 2.40.0