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
LLT = $(LLTDIR)/libllt.a
# OS flags: LINUX, WIN32, MACOSX
# 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)
FLAGS = -falign-functions -Wall -Wno-strict-aliasing -I$(LLTDIR) $(CFLAGS) -DUSE_COMPUTED_GOTO
LIBFILES = $(LLT)
LIBS = $(LIBFILES) -lm

View File

@ -7,10 +7,7 @@ OBJS = $(SRCS:%.c=%.o)
DOBJS = $(SRCS:%.c=%.do)
TARGET = libllt.a
# OS flags: LINUX, WIN32, MACOSX
# 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)
FLAGS = -Wall -Wno-strict-aliasing $(CFLAGS)
LIBS =
DEBUGFLAGS = -g -DDEBUG $(FLAGS)

View File

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

View File

@ -1,6 +1,33 @@
#ifndef __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);
int str2int(char *str, size_t len, int64_t *res, uint32_t 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));
}
#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)
{
argcount("string.width", nargs, 1);