From 7defb2d56a4560484d3564698d97d3d2e8d95737 Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@gmail.com>
Date: Sun, 19 Apr 2015 13:38:07 +0200
Subject: buildsystem configuration for Haiku


diff --git a/source/acinclude.m4 b/source/acinclude.m4
index b64e984..8d78d38 100644
--- a/source/acinclude.m4
+++ b/source/acinclude.m4
@@ -461,6 +461,9 @@ AC_DEFUN([AC_CHECK_STRICT_COMPILE],
         if test "$GCC" = yes
         then
             case "${host}" in
+			*-*-haiku*)
+                CFLAGS="$CFLAGS -std=c9x"
+                ;;
             *)
                 # Do not use -ansi. It limits us to C90, and it breaks some platforms.
                 # We use -std=c99 to disable the gnu99 defaults and its associated warnings
diff --git a/source/config/mh-haiku b/source/config/mh-haiku
index ccf956e..55a3ed2 100644
--- a/source/config/mh-haiku
+++ b/source/config/mh-haiku
@@ -18,7 +18,7 @@ LIBCPPFLAGS =
 THREADSCPPFLAGS =
 
 #
-CPPFLAGS += -D__STDC_ISO_10646__ -DU_CHARSET_IS_UTF8=1
+CPPFLAGS += -DU_CHARSET_IS_UTF8=1
 
 ## Compiler switch to embed a runtime search path
 LD_RPATH=
-- 
2.24.0


From fc02d8ba77b0c4146b5543b8f6ff2def05bcaeb5 Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@gmail.com>
Date: Fri, 3 Oct 2014 11:07:01 +0200
Subject: Don't call tzset and tzname on Haiku

While they exist, they are implemented using ICU, and trying to use them
within ICU results in a deadlock.

diff --git a/source/common/putilimp.h b/source/common/putilimp.h
index 5de801f..c7b33ee 100644
--- a/source/common/putilimp.h
+++ b/source/common/putilimp.h
@@ -105,7 +105,7 @@ typedef size_t uintptr_t;
     /* Use the predefined value. */
 #elif U_PLATFORM_USES_ONLY_WIN32_API
 #   define U_TZSET _tzset
-#elif U_PLATFORM == U_PF_OS400
+#elif U_PLATFORM == U_PF_OS400 || defined(__HAIKU__)
    /* not defined */
 #else
 #   define U_TZSET tzset
@@ -140,7 +140,7 @@ typedef size_t uintptr_t;
     /* Use the predefined value. */
 #elif U_PLATFORM_USES_ONLY_WIN32_API
 #   define U_TZNAME _tzname
-#elif U_PLATFORM == U_PF_OS400
+#elif U_PLATFORM == U_PF_OS400 || defined(__HAIKU__)
    /* not defined */
 #else
 #   define U_TZNAME tzname
diff --git a/source/configure.ac b/source/configure.ac
index 595bd12..dd8b40c 100644
--- a/source/configure.ac
+++ b/source/configure.ac
@@ -807,50 +807,26 @@ else
 fi
 AC_SUBST(U_HAVE_POPEN)
 
-AC_CHECK_FUNC(tzset)
+#AC_CHECK_FUNC(tzset)
 U_HAVE_TZSET=0
-if test x$ac_cv_func_tzset = xyes
-then
-    U_TZSET=tzset
-    U_HAVE_TZSET=1
-else
-    AC_CHECK_FUNC(_tzset)
-    if test x$ac_cv_func__tzset = xyes
-    then
-        U_TZSET=_tzset
-        U_HAVE_TZSET=1
-    else
-      CONFIG_CPPFLAGS="${CONFIG_CPPFLAGS} -DU_HAVE_TZSET=0"
-    fi
-fi
+#if test x$ac_cv_func_tzset = xyes
+#then
+#    U_TZSET=tzset
+#    U_HAVE_TZSET=1
+#else
+#    AC_CHECK_FUNC(_tzset)
+#    if test x$ac_cv_func__tzset = xyes
+#    then
+#        U_TZSET=_tzset
+#        U_HAVE_TZSET=1
+#    else
+#      CONFIG_CPPFLAGS="${CONFIG_CPPFLAGS} -DU_HAVE_TZSET=0"
+#    fi
+#fi
 AC_SUBST(U_HAVE_TZSET)
 AC_SUBST(U_TZSET)
 
 U_HAVE_TZNAME=0
-AC_CACHE_CHECK(for tzname,ac_cv_var_tzname,
-[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#ifndef __USE_POSIX
-#define __USE_POSIX
-#endif
-#include <stdlib.h>
-#include <time.h>
-#ifndef tzname /* For SGI.  */
-extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
-#endif]], [atoi(*tzname);])],[ac_cv_var_tzname=yes],[ac_cv_var_tzname=no])])
-if test $ac_cv_var_tzname = yes; then
-  U_TZNAME=tzname
-  U_HAVE_TZNAME=1
-else
-  AC_CACHE_CHECK(for _tzname,ac_cv_var__tzname,
-  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
-  #include <time.h>
-  extern char *_tzname[];]], [atoi(*_tzname);])],[ac_cv_var__tzname=yes],[ac_cv_var__tzname=no])])
-    if test $ac_cv_var__tzname = yes; then
-      U_TZNAME=_tzname
-      U_HAVE_TZNAME=1
-    else
-     CONFIG_CPPFLAGS="${CONFIG_CPPFLAGS} -DU_HAVE_TZNAME=0"
-    fi
-fi
 AC_SUBST(U_HAVE_TZNAME)
 AC_SUBST(U_TZNAME)
 
-- 
2.24.0


From 2f457a8ac9b594bb332b330926a83778d5437098 Mon Sep 17 00:00:00 2001
From: Oliver Tappe <zooey@hirschkaefer.de>
Date: Fri, 14 Nov 2014 23:56:19 +0100
Subject: Restore missing parts for proper Haiku port.

* Actually set the platform to U_HAIKU for Haiku target.
* Use gcc to build icudt54l_dat.o for Haiku target.

diff --git a/source/configure.ac b/source/configure.ac
index dd8b40c..206b3f8 100644
--- a/source/configure.ac
+++ b/source/configure.ac
@@ -640,7 +640,7 @@ AC_MSG_CHECKING([for genccode assembly])
 # Check to see if genccode can generate simple assembly.
 GENCCODE_ASSEMBLY=
 case "${host}" in
-*-linux*|*-kfreebsd*-gnu*|i*86-*-*bsd*|i*86-pc-gnu)
+*-linux*|*-kfreebsd*-gnu*|i*86-*-*bsd*|i*86-pc-gnu|*-haiku*)
     if test "$GCC" = yes; then
         # We're using gcc, and the simple -a gcc command line works for genccode
         GENCCODE_ASSEMBLY="-a gcc"
@@ -1244,6 +1244,7 @@ case "${host}" in
 	*-*-nto*)	platform=U_QNX ;;
 	*-dec-osf*) 	platform=U_OSF ;;
 	*-*-beos)		platform=U_BEOS ;;
+	*-*-haiku*)		platform=U_HAIKU ;;
 	*-*-irix*)		platform=U_IRIX ;;
 	*-ncr-*)		platform=U_MPRAS ;;
 	*) 		platform=U_UNKNOWN_PLATFORM ;;
-- 
2.24.0


From 8514a722d2d91fa04812d4aeb9be433da671f756 Mon Sep 17 00:00:00 2001
From: Michael Lotz <mmlr@mlotz.ch>
Date: Sat, 19 Dec 2015 14:44:35 +0000
Subject: Fix missing dependency of yearistype.sh to tzdata extraction.

This caused parallel builds to fail because the script file wasn't yet
extracted when it was copied. The regression was introduced in r26995
when the dependency was reused for TDATA which yearistype.sh isn't part
of.

diff --git a/source/tools/tzcode/Makefile.in b/source/tools/tzcode/Makefile.in
index b6ec447..2820650 100644
--- a/source/tools/tzcode/Makefile.in
+++ b/source/tools/tzcode/Makefile.in
@@ -125,7 +125,7 @@ $(ICUZDUMPTARG):	$(srcdir)/icuzdump.cpp
 		$(LINK.cc)  -I$(srcdir) -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(top_srcdir)/tools/toolutil -I$(top_srcdir)/io  -pedantic $(srcdir)/icuzdump.cpp $(LIBICUUC) $(LIBICUDT) $(LIBICUI18N) $(LIBICUIO) $(LIBICUTOOLUTIL) -o $@
 
 
-$(TDATA): tdatamarker
+$(TDATA) $(XDATA): tdatamarker
 
 tdatamarker: $(TZDATA)
 	gunzip -d < $(TZDATA) | tar xf - --exclude=Makefile
-- 
2.24.0


From 19a677e4f1b003ae6b99bb2391532c96dcdfea39 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Thu, 2 Jan 2020 21:26:40 +0100
Subject: update tzcode for newer tzdata.


diff --git a/source/tools/tzcode/tz2icu.cpp b/source/tools/tzcode/tz2icu.cpp
index 349aabd..b946ffb 100644
--- a/source/tools/tzcode/tz2icu.cpp
+++ b/source/tools/tzcode/tz2icu.cpp
@@ -1,4 +1,5 @@
-
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 **********************************************************************
 * Copyright (c) 2003-2014, International Business Machines
@@ -742,7 +743,7 @@ struct FinalZone {
                << " and rule ID " << ruleid;
             throw invalid_argument(os.str());
         }
-        if (year < 1900 || year >= 2050) {
+        if (year < 1900) {
             ostringstream os;
             os << "Invalid input year " << year
                << " with offset " << offset
@@ -829,7 +830,7 @@ struct FinalRulePart {
         if (mode != DOM && (dow < 0 || dow >= 7)) {
             os << "Invalid input day of week " << dow;
         }
-        if (offset < 0 || offset > (2 * HOUR)) {
+        if (offset < (-1 * HOUR) || offset > (2 * HOUR)) {
             os << "Invalid input offset " << offset;
         }
         if (isgmt && !isstd) {
@@ -902,7 +903,6 @@ map<string,FinalRule> finalRules;
 
 map<string, set<string> > links;
 map<string, string> reverseLinks;
-map<string, string> linkSource; // id => "Olson link" or "ICU alias"
 
 /**
  * Predicate used to find FinalRule objects that do not have both
@@ -974,9 +974,6 @@ void readFinalZonesAndRules(istream& in) {
 
             links[fromid].insert(toid);
             reverseLinks[toid] = fromid;
-
-            linkSource[fromid] = "Olson link";
-            linkSource[toid] = "Olson link";
         } else if (token.length() > 0 && token[0] == '#') {
             consumeLine(in);
         } else {
@@ -1429,6 +1426,9 @@ void FinalRule::print(ostream& os) const {
     os << part[whichpart].offset << endl;
 }
 
+#define ICU_ZONE_OVERRIDE_SUFFIX "--ICU"
+#define ICU_ZONE_OVERRIDE_SUFFIX_LEN 5
+
 int main(int argc, char *argv[]) {
     string rootpath, zonetab, version;
     bool validArgs = FALSE;
@@ -1492,6 +1492,82 @@ int main(int argc, char *argv[]) {
          << (ZONEINFO.begin())->first << ".."
          << (--ZONEINFO.end())->first << "]" << endl;
 
+    // Overrides TZ database zones with ICU custom zone definition.
+    // These ICU zone overrides are defined in icuzones, with suffix --ICU.
+    // If there is a matching TZ database zone, the zoneinfo is replaced
+    // with the ICU definition. Then, the zone ID with --ICU suffix
+    // will be deleted from the final list.
+    // For example, zoneinfo for Europe/Dublin imported from the TZ database
+    // will be replaced with the zone definition for Europe/Dublin--ICU
+    // in icuzones.
+
+    // Collect zone IDs to be modified with ICU definition.
+    vector<string> customZones;
+    for (ZoneMapIter i = ZONEINFO.begin(); i != ZONEINFO.end(); ++i) {
+        const string& id = i->first;
+        size_t idx = id.rfind(ICU_ZONE_OVERRIDE_SUFFIX);
+        if (idx != string::npos && idx == id.length() - ICU_ZONE_OVERRIDE_SUFFIX_LEN) {
+            cout << "ICU zone override: " << id << endl;
+            customZones.push_back(id.substr(0, idx));
+        }
+    }
+
+    //
+    // BEGIN ICU Custom ZoneInfo Override Handling
+    //
+
+    // Replace zoneinfo with ICU definition, then remove ICU zone ID with
+    // the special suffix.
+    for (vector<string>::iterator i = customZones.begin(); i != customZones.end(); i++) {
+        string& origId = *i;
+        string custId = origId + ICU_ZONE_OVERRIDE_SUFFIX;
+
+        map<string,ZoneInfo>::iterator origZi = ZONEINFO.find(origId);
+        map<string,ZoneInfo>::iterator custZi = ZONEINFO.find(custId);
+        if (origZi != ZONEINFO.end() && custZi != ZONEINFO.end()) {
+            // replace original zone info with custom override,
+            // then delete one custom ID
+            cout << "Replacing ZoneInfo " << origId << " with " << custId << endl;
+            origZi->second = custZi->second;
+            ZONEINFO.erase(custZi);
+        }
+
+        // Also replace final rule
+        map<string,FinalZone>::iterator origFz = finalZones.find(origId);
+        map<string,FinalZone>::iterator custFz = finalZones.find(custId);
+        if (origFz != finalZones.end() && custFz != finalZones.end()) {
+            // replace original final zone with custom override,
+            // then delete one for custom ID
+            cout << "Replacing FinalZone for " << origId << " with " << custId << endl;
+            origFz->second = custFz->second;
+            finalZones.erase(custFz);
+        }
+    }
+
+    // Also remove aliases for ICU custom zoneinfo overrides.
+    for (map<string,set<string>>::const_iterator i = links.begin(); i != links.end(); ) {
+        const string& id = i->first;
+        size_t idx = id.rfind(ICU_ZONE_OVERRIDE_SUFFIX);
+        if (idx != string::npos && idx == id.length() - ICU_ZONE_OVERRIDE_SUFFIX_LEN) {
+            const set<string>& aliases = i->second;
+            // Also remove all revserse links
+            for (set<string>::const_iterator j = aliases.begin(); j != aliases.end(); j++) {
+                const string& alias = *j;
+                cout << "Removing alias " << alias << endl;
+                reverseLinks.erase(alias);
+            }
+
+            links.erase(i++);
+        } else {
+            i++;
+        }
+    }
+
+
+    //
+    // END ICU Custom ZoneInfo Override Handling
+    //
+
     try {
         for_each(finalZones.begin(), finalZones.end(), mergeFinalZone);
     } catch (const exception& error) {
@@ -1509,7 +1585,7 @@ int main(int argc, char *argv[]) {
         const string& olson = i->first;
         const set<string>& aliases = i->second;
         if (ZONEINFO.find(olson) == ZONEINFO.end()) {
-            cerr << "Error: Invalid " << linkSource[olson] << " to non-existent \""
+            cerr << "Error: Invalid 'Link' to non-existent \""
                  << olson << "\"" << endl;
             return 1;
         }
@@ -1713,12 +1789,8 @@ int main(int argc, char *argv[]) {
     ofstream file(filename.c_str());
     if (file) {
         file << "//---------------------------------------------------------" << endl
-             << "// Copyright (C) 2003";
-        if (thisYear > 2003) {
-            file << "-" << thisYear;
-        }
-        file << ", International Business Machines" << endl
-             << "// Corporation and others.  All Rights Reserved." << endl
+             << "// Copyright (C) 2016 and later: Unicode, Inc. and others." << endl
+             << "// License & terms of use: http://www.unicode.org/copyright.html#License" << endl
              << "//---------------------------------------------------------" << endl
              << "// Build tool:  tz2icu" << endl
              << "// Build date:  " << asctime(now) /* << endl -- asctime emits CR */
diff --git a/source/tools/tzcode/tz2icu.h b/source/tools/tzcode/tz2icu.h
index 213608d..b88442f 100644
--- a/source/tools/tzcode/tz2icu.h
+++ b/source/tools/tzcode/tz2icu.h
@@ -1,3 +1,5 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 **********************************************************************
 * Copyright (c) 2003-2013, International Business Machines
-- 
2.24.0

