trying some preprocessor platform detection
This commit is contained in:
parent
ee807a2cf3
commit
7b771097fc
5
Makefile
5
Makefile
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
85
llt/dtypes.h
85
llt/dtypes.h
|
@ -16,46 +16,69 @@
|
||||||
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
|
||||||
|
#elif defined(__APPLE__) && defined(__MACH__)
|
||||||
|
# define MACOSX
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
# define WIN32
|
||||||
|
#else
|
||||||
|
# error "unknown platform"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(WIN32)
|
||||||
|
# define STDCALL __stdcall
|
||||||
|
# if defined(IMPORT_EXPORTS)
|
||||||
# define DLLEXPORT __declspec(dllimport)
|
# define DLLEXPORT __declspec(dllimport)
|
||||||
# else
|
# else
|
||||||
# define DLLEXPORT __declspec(dllexport)
|
# define DLLEXPORT __declspec(dllexport)
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
#define STDCALL
|
# define STDCALL
|
||||||
#define DLLEXPORT __attribute__ ((visibility("default")))
|
# define DLLEXPORT __attribute__ ((visibility("default")))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LINUX
|
#if defined(LINUX)
|
||||||
#include <features.h>
|
# include <features.h>
|
||||||
#include <endian.h>
|
# include <endian.h>
|
||||||
#define LITTLE_ENDIAN __LITTLE_ENDIAN
|
# define LITTLE_ENDIAN __LITTLE_ENDIAN
|
||||||
#define BIG_ENDIAN __BIG_ENDIAN
|
# define BIG_ENDIAN __BIG_ENDIAN
|
||||||
#define PDP_ENDIAN __PDP_ENDIAN
|
# define PDP_ENDIAN __PDP_ENDIAN
|
||||||
#define BYTE_ORDER __BYTE_ORDER
|
# 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
|
#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
|
|
||||||
#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
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BOEHM_GC
|
#ifdef BOEHM_GC
|
||||||
// boehm GC allocator
|
// boehm GC allocator
|
||||||
|
|
27
llt/utils.h
27
llt/utils.h
|
@ -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);
|
||||||
|
|
8
string.c
8
string.c
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue