Support Windows build, use official ICU src (for now)
COUCHDB-1994
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..1135ec5
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+* -text
+
diff --git a/.gitignore b/.gitignore
index eae0096..e08b336 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,6 @@
t/*.beam
.dists
.libs
+*.pdb
+*~
+priv
diff --git a/build_icu.ps1 b/build_icu.ps1
new file mode 100644
index 0000000..465d756
--- /dev/null
+++ b/build_icu.ps1
@@ -0,0 +1,71 @@
+param([switch]$clean)
+
+$ICU_ZIP = "icu4c-4_8_1-Win32-msvc10.zip"
+$ICU_URL="http://download.icu-project.org/files/icu4c/4.8.1"
+
+$DISTDIR="${pwd}\.dists"
+$STATICLIBS="${pwd}\.libs"
+$ICUDIR="${STATICLIBS}\icu"
+
+#
+# improved remove-item -recurse -force
+# thanks to http://serverfault.com/questions/199921/powershell-remove-force
+#
+function rmrf($directory = $(throw "Required parameter missing")) {
+ if ((test-path $directory) -and -not
+ (gi $directory | ? { $_.PSIsContainer })) {
+ throw ("rmrf called on non-directory.");
+ }
+
+ $finished = $false;
+ $attemptsLeft = 3;
+
+ do {
+ if (test-path $directory) {
+ rm $directory -recurse -force 2>&1 | out-null
+ }
+ if (test-path $directory) {
+ Start-Sleep -Milliseconds 500
+ $attemptsLeft = $attemptsLeft - 1
+ } else {
+ $finished = $true
+ }
+ } while (-not $finished -and $attemptsLeft -gt 0)
+
+ if (test-path $directory) {
+ throw ("Unable to fully remove directory " + $directory)
+ }
+}
+
+
+#
+# main
+#
+if ($clean -eq $true) {
+ write-host "==> icu (clean)"
+ rmrf($STATICLIBS)
+ rmrf($DISTDIR)
+} else {
+ write-host "==> icu (binary-download)"
+ rmrf($STATICLIBS)
+ rmrf($DISTDIR)
+ md $STATICLIBS -ea silentlycontinue > $null
+ md $DISTDIR -ea silentlycontinue > $null
+
+ # download the zip
+ $source = "${ICU_URL}/${ICU_ZIP}"
+ $dest = "${DISTDIR}\${ICU_ZIP}"
+ if (-not (test-path $dest)) {
+ write-host "==> Fetch ${ICU_ZIP} to ${dest}"
+ $wc = New-Object System.Net.WebClient
+ $wc.DownloadFile($source, $dest)
+ }
+
+ # unpack the zip
+ $shell = new-object -com shell.application
+ $zip = $shell.NameSpace($dest)
+ foreach($item in $zip.items())
+ {
+ $shell.Namespace($STATICLIBS).copyhere($item)
+ }
+}
diff --git a/build_icu.sh b/build_icu.sh
index 04304e6..7c1e6db 100755
--- a/build_icu.sh
+++ b/build_icu.sh
@@ -20,7 +20,7 @@
# 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
diff --git a/rebar.config.script b/rebar.config.script
index 3a52869..90f079f 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -42,10 +42,15 @@
_ -> 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 @@
{"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,7 +71,9 @@
{"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"),
@@ -77,6 +83,18 @@
{"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},
+ {"LDFLAGS", ICULDFLAGS ++ " $LDFLAGS"}
]
end,
@@ -84,7 +102,18 @@
{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)).