Support Windows build, use official ICU src (for now) 1994-merge-rcouch
authorJoan Touzet <wohali@apache.org>
Sat, 19 Apr 2014 02:31:03 +0000 (22:31 -0400)
committerJoan Touzet <wohali@apache.org>
Sat, 19 Apr 2014 02:31:03 +0000 (22:31 -0400)
COUCHDB-1994

.gitattributes [new file with mode: 0644]
.gitignore
build_icu.ps1 [new file with mode: 0644]
build_icu.sh
rebar.config.script

diff --git a/.gitattributes b/.gitattributes
new file mode 100644 (file)
index 0000000..1135ec5
--- /dev/null
@@ -0,0 +1,2 @@
+* -text
+
index eae0096a4f669bfe97992d56a84a482dafc780c0..e08b3369589f293e378e3f7a12bd5496b373c0e6 100644 (file)
@@ -2,3 +2,6 @@ ebin
 t/*.beam
 .dists
 .libs
+*.pdb
+*~
+priv
diff --git a/build_icu.ps1 b/build_icu.ps1
new file mode 100644 (file)
index 0000000..465d756
--- /dev/null
@@ -0,0 +1,71 @@
+param([switch]$clean)\r
+\r
+$ICU_ZIP = "icu4c-4_8_1-Win32-msvc10.zip"\r
+$ICU_URL="http://download.icu-project.org/files/icu4c/4.8.1"\r
+\r
+$DISTDIR="${pwd}\.dists"\r
+$STATICLIBS="${pwd}\.libs"\r
+$ICUDIR="${STATICLIBS}\icu"\r
+\r
+#\r
+# improved remove-item -recurse -force\r
+# thanks to http://serverfault.com/questions/199921/powershell-remove-force\r
+#\r
+function rmrf($directory = $(throw "Required parameter missing")) {\r
+    if ((test-path $directory) -and -not\r
+            (gi $directory | ? { $_.PSIsContainer })) {\r
+        throw ("rmrf called on non-directory.");\r
+    }\r
+\r
+    $finished = $false;\r
+    $attemptsLeft = 3;\r
+\r
+    do {\r
+        if (test-path $directory) {\r
+            rm $directory -recurse -force 2>&1 | out-null\r
+        }\r
+        if (test-path $directory) {\r
+            Start-Sleep -Milliseconds 500\r
+            $attemptsLeft = $attemptsLeft - 1\r
+        } else {\r
+            $finished = $true\r
+        }\r
+    } while (-not $finished -and $attemptsLeft -gt 0)\r
+\r
+    if (test-path $directory) {\r
+        throw ("Unable to fully remove directory " + $directory)\r
+    }\r
+}\r
+\r
+\r
+#\r
+# main\r
+#\r
+if ($clean -eq $true) {\r
+    write-host "==> icu (clean)"\r
+    rmrf($STATICLIBS)\r
+    rmrf($DISTDIR)\r
+} else {\r
+    write-host "==> icu (binary-download)"\r
+    rmrf($STATICLIBS)\r
+    rmrf($DISTDIR)\r
+    md $STATICLIBS -ea silentlycontinue > $null\r
+    md $DISTDIR -ea silentlycontinue > $null\r
+\r
+    # download the zip\r
+    $source = "${ICU_URL}/${ICU_ZIP}"\r
+    $dest = "${DISTDIR}\${ICU_ZIP}"\r
+    if (-not (test-path $dest)) {\r
+        write-host "==> Fetch ${ICU_ZIP} to ${dest}"\r
+        $wc = New-Object System.Net.WebClient\r
+        $wc.DownloadFile($source, $dest)\r
+    }\r
+\r
+    # unpack the zip\r
+    $shell = new-object -com shell.application\r
+    $zip = $shell.NameSpace($dest)\r
+    foreach($item in $zip.items())\r
+    {\r
+        $shell.Namespace($STATICLIBS).copyhere($item)\r
+    }\r
+}\r
index 04304e6c4776b4dc7c6f330d7d3bb29f22c48db8..7c1e6dbe6fa4fc8960c0ccfcaab3ee0c981512d1 100755 (executable)
@@ -20,7 +20,7 @@ DISTDIR=$CORE_TOP/.dists
 # icu sources
 ICU_VER=4.4.2
 ICU_DISTNAME=icu4c-4_4_2-src.tgz
-ICU_SITE=http://dl.refuge.io
+ICU_SITE=http://download.icu-project.org/files/icu4c/4.4.2
 ICUDIR=$STATICLIBS/icu
 
 
index 3a528690f971e6b8ced5189671e2da37325b7458..90f079f258f4a712825d64ddc42b95ca23dac356 100644 (file)
@@ -42,10 +42,15 @@ IsDarwin = case os:type() of
     _ -> false
 end,
 
+IsWindows = case os:type() of
+    {win32, nt} -> true;
+    _ -> false
+end,
+
 UseSystemIcu = IsDarwin andalso os:getenv("USE_STATIC_ICU") /= "1",
 
-PortEnv = case {UseSystemIcu, BuildStatic} of
-    {true, _} ->
+PortEnv = case {UseSystemIcu, BuildStatic, IsWindows} of
+    {true, _, false} ->
         CFLAGS = GetFlag1("ICU_CFLAGS",
                          "-Iplatform/osx/icu -I/usr/include -fPIC"),
         LDFLAGS = GetFlag1("ICU_LDFLAGS",
@@ -55,8 +60,7 @@ PortEnv = case {UseSystemIcu, BuildStatic} of
             {"CFLAGS", "$DRV_CFLAGS " ++ CFLAGS},
             {"LDFLAGS", LDFLAGS}
         ];
-
-    {_, true} ->
+    {_, true, false} ->
         CFLAGS = GetFlag1("ICU_CFLAGS", "-I.libs/icu/include"),
         LDFLAGS = GetFlag1("ICU_LDFLAGS", ".libs/icu/lib/libicui18n.a " ++
                                           ".libs/icu/lib/libicuuc.a " ++
@@ -67,12 +71,26 @@ PortEnv = case {UseSystemIcu, BuildStatic} of
             {"CFLAGS", "$DRV_CFLAGS " ++ CFLAGS},
             {"LDFLAGS", "-lstdc++ -fPIC $DRV_LDFLAGS " ++ LDFLAGS}
         ];
-    {_, false} ->
+    {_, true, true} ->
+        throw("Static builds not supported on Windows.");
+    {_, false, false} ->
         ICUCFLAGS = GetFlag("ICU_CFLAGS", "--cflags"),
         ICUCXXFLAGS = GetFlag("ICU_CXXFLAGS", "--cxxflags"),
         ICULDFLAGS = GetFlag("ICU_LDFLAGS", "--ldflags"),
         ICUINCPATH = GetFlag("ICU_INCPATH", "--cppflags-searchpath"),
 
+        [
+            {"CFLAGS",  ICUCFLAGS ++  " $CFLAGS " ++ ICUINCPATH},
+            {"CXXFLAGS", ICUCXXFLAGS ++ " $CXXFLAGS " ++ ICUINCPATH},
+            {"LDFLAGS",  ICULDFLAGS ++ " $LDFLAGS"}
+        ];
+    {_, false, true} ->
+        ICUCFLAGS = "",
+        ICUCXXFLAGS = "",
+        ICUINCPATH = "/I.libs\\icu\\include",
+        ICULDFLAGS = ".libs\\icu\\lib\\icuin.lib " ++
+                ".libs\\icu\\lib\\icuuc.lib " ++
+                ".libs\\icu\\lib\\icudt.lib",
         [
             {"CFLAGS",  ICUCFLAGS ++  " $CFLAGS " ++ ICUINCPATH},
             {"CXXFLAGS", ICUCXXFLAGS ++ " $CXXFLAGS " ++ ICUINCPATH},
@@ -84,7 +102,18 @@ PortInfo = [{port_env, PortEnv},
             {port_specs, [
                 {filename:join(["priv", Arch, "couch_collate.so"]),
                     ["c_src/*.c"]}]},
-            {pre_hooks, [{compile, "./build_icu.sh"}]},
-            {post_hooks, [{clean, "./build_icu.sh clean"}]}],
+            {pre_hooks, [
+                {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)",
+                    compile, "./build_icu.sh"},
+                {"(win32|win64)", compile,
+                    "powershell ./build_icu.ps1"}
+            ]},
+            {post_hooks, [
+                {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin)",
+                    clean, "./build_icu.sh clean"},
+                {"(win32|win64)", clean,
+                    "powershell ./build_icu.ps1 -clean"}
+            ]}
+           ],
 
 lists:keymerge(1,lists:keysort(1, PortInfo), lists:keysort(1, CONFIG)).