Skip to content

Commit 9631e00

Browse files
authored
feat(dev): Use brew --prefix to find ICU paths on macOS (#5360)
The Homebrew package `icu4c` is keg-only and not linked into the standard path on macOS after installation. Use the command `brew --prefix` for finding the location of the library.
1 parent 2cfb0c3 commit 9631e00

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/couch/rebar.config.script

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,31 @@ CouchJSEnv = case SMVsn of
262262
]
263263
end.
264264

265+
BrewIcuPrefixCmd = "brew --prefix icu4c".
266+
GenericIcuIncludePaths = "-I/usr/local/opt/icu4c/include -I/opt/homebrew/opt/icu4c/include".
267+
GenericIcuLibPaths = "-L/usr/local/opt/icu4c/lib -L/opt/homebrew/opt/icu4c/lib".
268+
269+
WithBrew = case os:find_executable("brew") of
270+
false -> false;
271+
_ -> true
272+
end.
273+
274+
IcuIncludePath = case WithBrew of
275+
false -> GenericIcuIncludePaths;
276+
true -> "-I" ++ string:strip(os:cmd(BrewIcuPrefixCmd), right, $\n) ++ "/include"
277+
end.
278+
279+
IcuLibPath = case WithBrew of
280+
false -> GenericIcuLibPaths;
281+
true -> "-L" ++ string:strip(os:cmd(BrewIcuPrefixCmd), right, $\n) ++ "/lib"
282+
end.
283+
265284
IcuEnv = [{"DRV_CFLAGS", "$DRV_CFLAGS -DPIC -O2 -fno-common"},
266285
{"DRV_LDFLAGS", "$DRV_LDFLAGS -lm -licuuc -licudata -licui18n -lpthread"},
267286
{"LDFLAGS", "$LDFLAGS"},
268287
{"CFLAGS", "$CFLAGS"}].
269-
IcuDarwinEnv = [{"CFLAGS", "-DXP_UNIX -I/usr/local/opt/icu4c/include -I/opt/homebrew/opt/icu4c/include"},
270-
{"LDFLAGS", "-L/usr/local/opt/icu4c/lib -L/opt/homebrew/opt/icu4c/lib"}].
288+
IcuDarwinEnv = [{"CFLAGS", "-DXP_UNIX " ++ IcuIncludePath},
289+
{"LDFLAGS", IcuLibPath}].
271290
IcuBsdEnv = [{"CFLAGS", "-DXP_UNIX -I/usr/local/include"},
272291
{"LDFLAGS", "-L/usr/local/lib"}].
273292
IcuWinEnv = [{"CFLAGS", "$DRV_CFLAGS /DXP_WIN"},

0 commit comments

Comments
 (0)