trying some preprocessor platform detection

This commit is contained in:
Neil 2013-03-17 15:02:33 -04:00
parent ee807a2cf3
commit 7b771097fc
5 changed files with 92 additions and 40 deletions

View File

@ -9,10 +9,7 @@ LIBTARGET = lib$(NAME)
LLTDIR = llt LLTDIR = llt
LLT = $(LLTDIR)/libllt.a LLT = $(LLTDIR)/libllt.a
# OS flags: LINUX, WIN32, MACOSX FLAGS = -falign-functions -Wall -Wno-strict-aliasing -I$(LLTDIR) $(CFLAGS) -DUSE_COMPUTED_GOTO
# architecture flags: __CPU__=xxx, BITS64, ARCH_X86, ARCH_X86_64
CONFIG = -DLINUX -DARCH_X86_64 -DBITS64 -D__CPU__=686
FLAGS = -falign-functions -Wall -Wno-strict-aliasing -I$(LLTDIR) $(CFLAGS) -DUSE_COMPUTED_GOTO $(CONFIG)
LIBFILES = $(LLT) LIBFILES = $(LLT)
LIBS = $(LIBFILES) -lm LIBS = $(LIBFILES) -lm

View File

@ -7,10 +7,7 @@ OBJS = $(SRCS:%.c=%.o)
DOBJS = $(SRCS:%.c=%.do) DOBJS = $(SRCS:%.c=%.do)
TARGET = libllt.a TARGET = libllt.a
# OS flags: LINUX, WIN32, MACOSX FLAGS = -Wall -Wno-strict-aliasing $(CFLAGS)
# architecture flags: __CPU__=xxx, BITS64, ARCH_X86, ARCH_X86_64
CONFIG = -DLINUX -DARCH_X86_64 -DBITS64 -D__CPU__=686
FLAGS = -Wall -Wno-strict-aliasing $(CFLAGS) $(CONFIG)
LIBS = LIBS =
DEBUGFLAGS = -g -DDEBUG $(FLAGS) DEBUGFLAGS = -g -DDEBUG $(FLAGS)

View File

@ -16,47 +16,70 @@
We assume the LP64 convention for 64-bit platforms. We assume the LP64 convention for 64-bit platforms.
*/ */
#ifdef WIN32
#define STDCALL __stdcall #if defined(__gnu_linux__)
# ifdef IMPORT_EXPORTS # define LINUX
# define DLLEXPORT __declspec(dllimport) #elif defined(__APPLE__) && defined(__MACH__)
# else # define MACOSX
# define DLLEXPORT __declspec(dllexport) #elif defined(_WIN32)
# endif # define WIN32
#else #else
#define STDCALL # error "unknown platform"
#define DLLEXPORT __attribute__ ((visibility("default")))
#endif #endif
#ifdef LINUX
#include <features.h> #ifndef __SIZEOF_POINTER__
#include <endian.h> # error "__SIZEOF_POINTER__ undefined"
#define LITTLE_ENDIAN __LITTLE_ENDIAN #endif
#define BIG_ENDIAN __BIG_ENDIAN #if( 8 == __SIZEOF_POINTER__ )
#define PDP_ENDIAN __PDP_ENDIAN # define BITS64
#define BYTE_ORDER __BYTE_ORDER #elif( 4 == __SIZEOF_POINTER__ )
# define BITS32
#else
# error "this is one weird machine"
#endif #endif
#ifdef MACOSX
#include <machine/endian.h> #if defined(WIN32)
#define __LITTLE_ENDIAN LITTLE_ENDIAN # define STDCALL __stdcall
#define __BIG_ENDIAN BIG_ENDIAN # if defined(IMPORT_EXPORTS)
#define __PDP_ENDIAN PDP_ENDIAN # define DLLEXPORT __declspec(dllimport)
#define __BYTE_ORDER BYTE_ORDER # else
# define DLLEXPORT __declspec(dllexport)
# endif
#else
# define STDCALL
# define DLLEXPORT __attribute__ ((visibility("default")))
#endif #endif
#ifdef WIN32 #if defined(LINUX)
#define __LITTLE_ENDIAN 1234 # include <features.h>
#define __BIG_ENDIAN 4321 # include <endian.h>
#define __PDP_ENDIAN 3412 # define LITTLE_ENDIAN __LITTLE_ENDIAN
#define __BYTE_ORDER __LITTLE_ENDIAN # define BIG_ENDIAN __BIG_ENDIAN
#define __FLOAT_WORD_ORDER __LITTLE_ENDIAN # define PDP_ENDIAN __PDP_ENDIAN
#define LITTLE_ENDIAN __LITTLE_ENDIAN # define BYTE_ORDER __BYTE_ORDER
#define BIG_ENDIAN __BIG_ENDIAN #elif defined(MACOSX)
#define PDP_ENDIAN __PDP_ENDIAN # include <machine/endian.h>
#define BYTE_ORDER __BYTE_ORDER # define __LITTLE_ENDIAN LITTLE_ENDIAN
# define __BIG_ENDIAN BIG_ENDIAN
# define __PDP_ENDIAN PDP_ENDIAN
# define __BYTE_ORDER BYTE_ORDER
#elif defined(WIN32)
# define __LITTLE_ENDIAN 1234
# define __BIG_ENDIAN 4321
# define __PDP_ENDIAN 3412
# define __BYTE_ORDER __LITTLE_ENDIAN
# define __FLOAT_WORD_ORDER __LITTLE_ENDIAN
# define LITTLE_ENDIAN __LITTLE_ENDIAN
# define BIG_ENDIAN __BIG_ENDIAN
# define PDP_ENDIAN __PDP_ENDIAN
# define BYTE_ORDER __BYTE_ORDER
#else
# error "unknown platform"
#endif #endif
#ifdef BOEHM_GC #ifdef BOEHM_GC
// boehm GC allocator // boehm GC allocator
#include <gc.h> #include <gc.h>

View File

@ -1,6 +1,33 @@
#ifndef __UTILS_H_ #ifndef __UTILS_H_
#define __UTILS_H_ #define __UTILS_H_
#if defined( __amd64__ ) || defined( _M_AMD64 )
# define ARCH_X86_64
# define __CPU__ 686
#elif defined( _M_IX86 )//msvs, intel, digital mars, watcom
# if ! defined( __386__ )
# error "unsupported target: 16-bit x86"
# endif
# define ARCH_X86
# define __CPU__ ( _M_IX86 + 86 )
#elif defined( __i686__ )//gnu c
# define ARCH_X86
# define __CPU__ 686
#elif defined( __i586__ )//gnu c
# define ARCH_X86
# define __CPU__ 586
#elif defined( __i486__ )//gnu c
# define ARCH_X86
# define __CPU__ 486
#elif defined( __i386__ )//gnu c
# define ARCH_X86
# define __CPU__ 386
#else
# error "unknown architecture"
#endif
char *uint2str(char *dest, size_t len, uint64_t num, uint32_t base); char *uint2str(char *dest, size_t len, uint64_t num, uint32_t base);
int str2int(char *str, size_t len, int64_t *res, uint32_t base); int str2int(char *str, size_t len, int64_t *res, uint32_t base);
int isdigit_base(char c, int base); int isdigit_base(char c, int base);

View File

@ -47,6 +47,14 @@ value_t fl_string_count(value_t *args, u_int32_t nargs)
return size_wrap(u8_charnum(str+start, stop-start)); return size_wrap(u8_charnum(str+start, stop-start));
} }
#if defined( __WIN32__ ) || defined( __linux__ )
extern int wcwidth( wchar_t );
#else
# error "I need int wcwidth( wchar_t );"
#endif
value_t fl_string_width(value_t *args, u_int32_t nargs) value_t fl_string_width(value_t *args, u_int32_t nargs)
{ {
argcount("string.width", nargs, 1); argcount("string.width", nargs, 1);