From 233299e5c8eadc75957b7fa54423b9f7bd1f8dda Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Mon, 4 Oct 2010 00:58:14 +0200 Subject: [PATCH] Haiku OS support; thanks to MrSunshine --- dmd/expression.c | 13 ++++++++++++- dmd/lexer.c | 2 ++ dmd/mars.h | 1 + dmd/root/port.c | 12 +++++++++--- dmd/root/port.h | 2 +- dmd/root/root.c | 4 ++++ gen/linker.cpp | 4 +++- gen/main.cpp | 7 +++++++ 8 files changed, 39 insertions(+), 6 deletions(-) diff --git a/dmd/expression.c b/dmd/expression.c index c1155ee4..9bb45506 100644 --- a/dmd/expression.c +++ b/dmd/expression.c @@ -1704,7 +1704,18 @@ void floatToBuffer(OutBuffer *buf, Type *type, real_t value) if (r == value) // if exact duplication buf->writestring(buffer); else - buf->printf("%La", value); // ensure exact duplication + { + #ifdef __HAIKU__ // broken printf workaround + char buffer2[25]; + char *ptr = (char *)&value; + for(int i = 0; i < sizeof(value); i++) + snprintf(buffer2, sizeof(char), "%x", ptr[i]); + + buf->writestring(buffer2); + #else + buf->printf("%La", value); // ensure exact duplication + #endif + } if (type) { diff --git a/dmd/lexer.c b/dmd/lexer.c index 5b2dd923..963384f3 100644 --- a/dmd/lexer.c +++ b/dmd/lexer.c @@ -16,6 +16,8 @@ #include #endif +#include + /* Lexical Analyzer */ #include diff --git a/dmd/mars.h b/dmd/mars.h index a3184035..3a6a46fa 100644 --- a/dmd/mars.h +++ b/dmd/mars.h @@ -147,6 +147,7 @@ enum OS { OSinvalid, OSLinux, + OSHaiku, OSWindows, OSMacOSX, OSFreeBSD, diff --git a/dmd/root/port.c b/dmd/root/port.c index 98807c55..97219024 100644 --- a/dmd/root/port.c +++ b/dmd/root/port.c @@ -315,7 +315,7 @@ char *Port::strupr(char *s) #endif -#if linux || __APPLE__ || __FreeBSD__ || __MINGW32__ +#if linux || __APPLE__ || __FreeBSD__ || __MINGW32__ || __HAIKU__ #include #if linux @@ -368,7 +368,7 @@ PortInitializer::PortInitializer() #endif } -#ifndef __MINGW32__ +#if !defined __MINGW32__ && !defined __HAIKU__ #undef isnan #endif int Port::isNan(double r) @@ -377,6 +377,8 @@ int Port::isNan(double r) return __inline_isnan(r); #elif defined __MINGW32__ return isnan(r); +#elif defined __HAIKU__ + return isnan(r); #else return ::isnan(r); #endif @@ -388,6 +390,8 @@ int Port::isNan(long double r) return __inline_isnan(r); #elif defined __MINGW32__ return isnan(r); +#elif defined __HAIKU__ + return isnan(r); #else return ::isnan(r); #endif @@ -415,7 +419,7 @@ int Port::isFinite(double r) return ::finite(r); } -#ifndef __MINGW32__ +#if !defined __MINGW32__ && !defined __HAIKU__ #undef isinf #endif int Port::isInfinity(double r) @@ -424,6 +428,8 @@ int Port::isInfinity(double r) return fpclassify(r) == FP_INFINITE; #elif defined __MINGW32__ return isinf(r); +#elif defined __HAIKU__ + return isinf(r); #else return ::isinf(r); #endif diff --git a/dmd/root/port.h b/dmd/root/port.h index 37d33c70..e00ec465 100644 --- a/dmd/root/port.h +++ b/dmd/root/port.h @@ -40,7 +40,7 @@ struct Port static double dbl_min; static long double ldbl_max; -#if __GNUC__ +#if __GNUC__ && !defined __HAIKU__ // These conflict with macros in math.h, should rename them #undef isnan #undef isfinite diff --git a/dmd/root/root.c b/dmd/root/root.c index 9ff3c971..96cfd115 100644 --- a/dmd/root/root.c +++ b/dmd/root/root.c @@ -34,6 +34,10 @@ #include #endif +#ifdef __HAIKU__ +#include +#endif + #if POSIX #include #include diff --git a/gen/linker.cpp b/gen/linker.cpp index 6689bc87..7af6a4dd 100644 --- a/gen/linker.cpp +++ b/gen/linker.cpp @@ -172,7 +172,9 @@ int linkExecutable(const char* argv0) args.push_back("-lpthread"); args.push_back("-lm"); break; - + case OSHaiku: + args.push_back("-lroot"); + break; case OSWindows: // FIXME: I'd assume kernel32 etc break; diff --git a/gen/main.cpp b/gen/main.cpp index 9af0715f..ec9cba97 100644 --- a/gen/main.cpp +++ b/gen/main.cpp @@ -589,6 +589,13 @@ LDC_TARGETS VersionCondition::addPredefinedGlobalIdent("linux"); VersionCondition::addPredefinedGlobalIdent("Posix"); } + // haiku + else if (triple.find("haiku") != npos) + { + global.params.os = OSHaiku; + VersionCondition::addPredefinedGlobalIdent("Haiku"); + VersionCondition::addPredefinedGlobalIdent("Posix"); + } // darwin else if (triple.find("-darwin") != npos) {