From: Owen Shepherd Date: Thu, 16 Aug 2012 13:59:39 +0000 (+0100) Subject: Enable building PDCLib with Watcom. This was surprisingly painless: their C99 mode... X-Git-Url: https://pd.if.org/git/?p=pdclib;a=commitdiff_plain;h=48b352165d2cb89126ddde1323a138820687970a Enable building PDCLib with Watcom. This was surprisingly painless: their C99 mode has come a long way! --- diff --git a/Jamrules b/Jamrules index dd0e406..bc9ac17 100644 --- a/Jamrules +++ b/Jamrules @@ -8,16 +8,29 @@ if ! $(PDCLIB_HAVE_PLATFORM) && ! $(PDCLIB_PLATFORM) { } 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" ; + 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 +if $(PDCLIB_TOOLCHAIN) = "" { + local __ccparts = [ SPLIT $(CC) : "-" ] ; + if $(JAM_TOOLSET) = "MINGW" || "gcc" in $(__ccparts) + || "clang" in $(__ccparts) { + # GCC / GCC-alike + PDCLIB_TOOLCHAIN = "gcc" ; + } else if $(JAM_TOOLSET) != "" { + PDCLIB_TOOLCHAIN = $(JAM_TOOLSET) ; + } else { + ECHO PDCLIB_TOOLCHAIN is unset and I can't glean what toolset is being ; + ECHO used from your environment. Please set it. ; + EXIT ; + } +} +if $(PDCLIB_TOOLCHAIN) = "gcc" { # No -Wcast-align : spurious warnings when using char* to do pointer # arithmetic # No -Winline : when compiling with e.g. -Os causes spurious @@ -49,7 +62,18 @@ if ! $(PDCLIB_HAVE_PLATFORM) && ! $(PDCLIB_PLATFORM) { { $(LINK) $(LINKFLAGS) -o $(<) $(UNDEFS) $(>) -Wl,--start-group $(NEEDLIBS) $(LINKLIBS) -Wl,--end-group } -#} +} else if $(PDCLIB_TOOLCHAIN) = "WATCOM" { + ECHO "Watcom!" ; + CCFLAGS = /zq /DWIN32 ; + C++FLAGS = /zq /DWIN32 ; + STDHDRS = $(WATCOM)\\h\\nt ; + + PDCLIB_CCFLAGS = "-za99 -zl" ; +} else { + ECHO The value of PDCLIB_TOOLCHAIN is not recognized ; + ECHO Currently set to $(PDCLIB_TOOLCHAIN) ; + EXIT ; +} if $(PDCLIB_PLATFORM) { include [ FDirName $(PDCLIB_TOP) platform $(PDCLIB_PLATFORM) Config.jam ] ; diff --git a/internals/_PDCLIB_glue.h b/internals/_PDCLIB_glue.h index 09f47b7..d49cc11 100644 --- a/internals/_PDCLIB_glue.h +++ b/internals/_PDCLIB_glue.h @@ -25,7 +25,7 @@ _PDCLIB_BEGIN_EXTERN_C /* A system call that terminates the calling process, returning a given status to the environment. */ -void _PDCLIB_Exit( int status ) _PDCLIB_NORETURN; +_PDCLIB_noreturn void _PDCLIB_Exit( int status ); /* A system call which allocates n pages of memory and returns a pointer to them. On failure, returns NULL diff --git a/platform/example/internals/_PDCLIB_config.h b/platform/example/internals/_PDCLIB_config.h index ff43495..15ee828 100644 --- a/platform/example/internals/_PDCLIB_config.h +++ b/platform/example/internals/_PDCLIB_config.h @@ -27,12 +27,6 @@ /* specific platforms, e.g. by swapping int instead of char. */ #define _PDCLIB_memswp( i, j, size ) char tmp; do { tmp = *i; *i++ = *j; *j++ = tmp; } while ( --size ); -/* Define this to some compiler directive that can be written after the */ -/* parameter list of a function declaration to indicate the function does */ -/* never return. If your compiler does not support such a directive, define */ -/* to nothing. (This is to avoid warnings with the exit functions under GCC.) */ -#define _PDCLIB_NORETURN __attribute__(( noreturn )) - /* The maximum value that errno can be set to. This is used to set the size */ /* of the array in struct lconv () holding error messages for the */ /* strerror() and perror() functions. (If you change this value because you */ diff --git a/platform/posix/internals/_PDCLIB_config.h b/platform/posix/internals/_PDCLIB_config.h index 7e66178..4252cff 100644 --- a/platform/posix/internals/_PDCLIB_config.h +++ b/platform/posix/internals/_PDCLIB_config.h @@ -27,12 +27,6 @@ /* specific platforms, e.g. by swapping int instead of char. */ #define _PDCLIB_memswp( i, j, size ) char tmp; do { tmp = *i; *i++ = *j; *j++ = tmp; } while ( --size ); -/* Define this to some compiler directive that can be written after the */ -/* parameter list of a function declaration to indicate the function does */ -/* never return. If your compiler does not support such a directive, define */ -/* to nothing. (This is to avoid warnings with the exit functions under GCC.) */ -#define _PDCLIB_NORETURN __attribute__(( noreturn )) - /* The maximum value that errno can be set to. This is used to set the size */ /* of the array in struct lconv () holding error messages for the */ /* strerror() and perror() functions. (If you change this value because you */ diff --git a/platform/win32/Config.jam b/platform/win32/Config.jam index c02174f..7dcab3f 100644 --- a/platform/win32/Config.jam +++ b/platform/win32/Config.jam @@ -2,6 +2,10 @@ rule PDCLibTargetConfig { } rule PDCLibTargetHeaders { SubDirHdrs $(PDCLIB_TOP) platform win32 includes ; SubDirHdrs $(PDCLIB_TOP) platform win32 internals ; + + if $(PDCLIB_TOOLCHAIN) = "WATCOM" { + SubDirHdrs $(WATCOM) h ; + } } PDCLIB_TEST_LINKFLAGS += -nostdlib ; diff --git a/platform/win32/crt0.c b/platform/win32/crt0.c index f7f6a92..dd00c53 100644 --- a/platform/win32/crt0.c +++ b/platform/win32/crt0.c @@ -1,8 +1,9 @@ -#include #include #include #include #include +#include // Watcom bug: winnt.h assumes string.h defines wchar_t +#include static char ** argvToAnsi( wchar_t ** wargv, int argc ) { diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_seek.c b/platform/win32/functions/_PDCLIB/_PDCLIB_seek.c index e23cd3c..6bf53e9 100644 --- a/platform/win32/functions/_PDCLIB/_PDCLIB_seek.c +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_seek.c @@ -12,9 +12,11 @@ #include <_PDCLIB_glue.h> #include +#if _PDCLIB_C_MIN(2011) _Static_assert(SEEK_SET == FILE_BEGIN, "SEEK_SET is incorrect"); _Static_assert(SEEK_CUR == FILE_CURRENT, "SEEK_CUR is incorrect"); _Static_assert(SEEK_END == FILE_END, "SEEK_END is incorrect"); +#endif extern void _PDCLIB_w32errno( void ); _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence ) diff --git a/platform/win32/functions/_PDCLIB/_PDCLIB_w32errno.c b/platform/win32/functions/_PDCLIB/_PDCLIB_w32errno.c index 5e03ef5..da237f4 100644 --- a/platform/win32/functions/_PDCLIB/_PDCLIB_w32errno.c +++ b/platform/win32/functions/_PDCLIB/_PDCLIB_w32errno.c @@ -11,6 +11,7 @@ #ifndef REGTEST #include +#include // Watcom bug: winnt.h assumes string.h defines wchar_t #include void _PDCLIB_w32errno(void) diff --git a/platform/win32/functions/stdio/remove.c b/platform/win32/functions/stdio/remove.c index 913bdf3..957a5ed 100644 --- a/platform/win32/functions/stdio/remove.c +++ b/platform/win32/functions/stdio/remove.c @@ -15,6 +15,7 @@ #include #include +#include // Watcom bug: winnt.h assumes string.h defines wchar_t #include extern struct _PDCLIB_file_t * _PDCLIB_filelist; diff --git a/platform/win32/internals/_PDCLIB_config.h b/platform/win32/internals/_PDCLIB_config.h index 27a87b9..17c8ff4 100644 --- a/platform/win32/internals/_PDCLIB_config.h +++ b/platform/win32/internals/_PDCLIB_config.h @@ -273,13 +273,22 @@ struct _PDCLIB_imaxdiv_t */ #ifdef __GNUC__ - typedef char * _PDCLIB_va_list; + typedef __builtin_va_list _PDCLIB_va_list; #define _PDCLIB_va_arg( ap, type ) (__builtin_va_arg( (ap), type )) #define _PDCLIB_va_copy( dest, src ) (__builtin_va_copy( (dest), (src) )) #define _PDCLIB_va_end( ap ) (__builtin_va_end( ap ) ) #define _PDCLIB_va_start( ap, parmN ) (__builtin_va_start( (ap), (parmN) )) +#elif (defined(__i386__) || defined(__i386) || defined(_M_IX86)) && !(defined(__amd64__) || defined(__x86_64__) || defined(_M_AMD64)) + /* Internal helper macro. va_round is not part of . */ + #define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) ) + + typedef char * _PDCLIB_va_list; + #define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) ) + #define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 ) + #define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 ) + #define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 ) #else - #error Compiler support please + #error Compiler/Architecture support please #endif /* -------------------------------------------------------------------------- */