Skip to content

Commit 9d6509b

Browse files
committed
dev: Automatic version detection and flags simplification
1 parent 17dd945 commit 9d6509b

File tree

2 files changed

+31
-37
lines changed

2 files changed

+31
-37
lines changed

configure

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ CLOUSEAU_URI=${CLOUSEAU_URI:-"https://github.com/cloudant-labs/clouseau/releases
4646
CLOUSEAU_VSN=${CLOUSEAU_VSN:-"2.25.0"}
4747
CLOUSEAU_DIR="$(pwd)"/clouseau
4848
ARCH="$(uname -m)"
49-
MULTIARCHNAME="$(dpkg-architecture -q DEB_HOST_MULTIARCH)"
49+
MULTIARCH_NAME="$(dpkg-architecture -q DEB_HOST_MULTIARCH || true)"
5050
ERLANG_VER="$(run_erlang 'io:put_chars(erlang:system_info(otp_release)).')"
5151
ERLANG_OS="$(run_erlang 'case os:type() of {OS, _} -> io:format("~s~n", [OS]) end.')"
5252

@@ -328,7 +328,7 @@ if [ "${WITH_SPIDERMONKEY}" = "true" ] && [ "${ERLANG_OS}" = "unix" ]; then
328328

329329
# This list is taken from src/couch/rebar.config.script, please keep them in sync.
330330
if [ ! -d "/usr/include/${SM_HEADERS}" ] && \
331-
[ ! -d "/usr/include/${MULTIARCHNAME}" ] && \
331+
[ ! -d "/usr/include/${MULTIARCH_NAME}/${SM_HEADERS}" ] && \
332332
[ ! -d "/usr/local/include/${SM_HEADERS}" ] && \
333333
[ ! -d "/opt/homebrew/include/${SM_HEADERS}" ]; then
334334
echo "ERROR: SpiderMonkey ${SM_VSN} is not found. Please specify with --spidermonkey-version."

src/couch/rebar.config.script

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ end.
3636
CouchJSPath = filename:join(["priv", CouchJSName]).
3737
Version = case os:getenv("COUCHDB_VERSION") of
3838
false ->
39-
string:strip(os:cmd("git describe --always"), right, $\n);
39+
string:trim(os:cmd("git describe --always"));
4040
Version0 ->
41-
string:strip(Version0, right)
41+
string:trim(Version0)
4242
end.
4343

4444
GitSha = case os:getenv("COUCHDB_GIT_SHA") of
4545
false ->
4646
""; % release builds won\'t get a fallback
4747
GitSha0 ->
48-
string:strip(GitSha0, right)
48+
string:trim(GitSha0)
4949
end.
5050

5151
CouchConfig = case filelib:is_file(os:getenv("COUCHDB_CONFIG")) of
@@ -151,6 +151,25 @@ ProperConfig = case code:lib_dir(proper) of
151151
_ -> [{d, 'WITH_PROPER'}]
152152
end.
153153

154+
DpkgArchitectureCmd = "dpkg-architecture -q DEB_HOST_MULTIARCH".
155+
GenericMozJSIncludePaths = "-I/usr/include/mozjs-" ++ SMVsn ++ " -I/usr/local/include/mozjs-" ++ SMVsn.
156+
GenericMozJSLibPaths = "-L/usr/local/lib -L/opt/homebrew/lib".
157+
158+
WithDpkgArchitecture = case os:find_executable("dpkg-architecture") of
159+
false -> false;
160+
_ -> true
161+
end.
162+
163+
MozJSIncludePath = case WithDpkgArchitecture of
164+
false -> GenericMozJSIncludePaths;
165+
true -> GenericMozJSIncludePaths ++ " -I/usr/include/" ++ string:trim(os:cmd(DpkgArchitectureCmd)) ++ "/mozjs-" ++ SMVsn
166+
end.
167+
168+
MozJSLibPath = case WithDpkgArchitecture of
169+
false -> GenericMozJSLibPaths;
170+
true -> GenericMozJSLibPaths ++ " -L/usr/lib/" ++ string:trim(os:cmd(DpkgArchitectureCmd))
171+
end.
172+
154173
% The include directories (parameters for the `-I` C compiler flag) are
155174
% considered in the `configure` script as a pre-check for their existence.
156175
% Please keep them in sync.
@@ -195,45 +214,20 @@ end.
195214
"-DXP_UNIX -I/usr/include/mozjs-86 -I/usr/local/include/mozjs-86 -I/opt/homebrew/include/mozjs-86/ -std=c++17 -Wno-invalid-offsetof",
196215
"-L/usr/local/lib -L /opt/homebrew/lib/ -std=c++17 -lmozjs-86 -lm"
197216
};
198-
{unix, _} when SMVsn == "91" ->
199-
{
200-
"$CFLAGS -DXP_UNIX -I/usr/include/mozjs-91 -I/usr/local/include/mozjs-91 -I/opt/homebrew/include/mozjs-91/ -std=c++17 -Wno-invalid-offsetof",
201-
"$LDFLAGS -L/usr/local/lib -L /opt/homebrew/lib/ -std=c++17 -lmozjs-91 -lm"
202-
};
203-
{unix, _} when SMVsn == "102" ->
204-
{
205-
"$CFLAGS -DXP_UNIX -I/usr/include/mozjs-102 -I/usr/local/include/mozjs-102 -I/opt/homebrew/include/mozjs-102/ -std=c++17 -Wno-invalid-offsetof",
206-
"$LDFLAGS -L/usr/local/lib -L /opt/homebrew/lib/ -std=c++17 -lmozjs-102 -lm"
207-
};
208-
{unix, _} when SMVsn == "115" ->
209-
{
210-
"$CFLAGS -DXP_UNIX -I/usr/include/mozjs-115 -I/usr/local/include/mozjs-115 -I/opt/homebrew/include/mozjs-115/ -std=c++17 -Wno-invalid-offsetof",
211-
"$LDFLAGS -L/usr/local/lib -L /opt/homebrew/lib/ -std=c++17 -lmozjs-115 -lm"
212-
};
213-
{unix, _} when SMVsn == "128" ->
217+
{unix, _} when SMVsn == "91"; SMVsn == "102"; SMVsn == "115"; SMVsn == "128" ->
214218
{
215-
"$CFLAGS -DXP_UNIX -I/usr/include/mozjs-128 -I/usr/local/include/mozjs-128 -I/opt/homebrew/include/mozjs-128/ -std=c++17 -Wno-invalid-offsetof",
216-
"$LDFLAGS -L/usr/local/lib -L /opt/homebrew/lib/ -std=c++17 -lmozjs-128 -lm"
219+
"$CFLAGS -DXP_UNIX " ++ MozJSIncludePath ++ " -std=c++17 -Wno-invalid-offsetof",
220+
"$LDFLAGS " ++ MozJSLibPath ++ " -std=c++17 -lm -lmozjs-" ++ SMVsn
217221
};
218222
{win32, _} when SMVsn == "91" ->
219223
{
220224
"/std:c++17 /DXP_WIN",
221225
"$LDFLAGS mozjs-91.lib"
222226
};
223-
{win32, _} when SMVsn == "102" ->
224-
{
225-
"/std:c++17 /DXP_WIN /Zc:preprocessor /utf-8",
226-
"$LDFLAGS mozjs-102.lib"
227-
};
228-
{win32, _} when SMVsn == "115" ->
229-
{
230-
"/std:c++17 /DXP_WIN /Zc:preprocessor /utf-8",
231-
"$LDFLAGS mozjs-115.lib"
232-
};
233-
{win32, _} when SMVsn == "128" ->
227+
{win32, _} when SMVsn == "102"; SMVsn == "115"; SMVsn == "128" ->
234228
{
235229
"/std:c++17 /DXP_WIN /Zc:preprocessor /utf-8",
236-
"$LDFLAGS mozjs-128.lib"
230+
"$LDFLAGS mozjs-" ++ SMVsn ++ ".lib"
237231
}
238232
end.
239233

@@ -273,12 +267,12 @@ end.
273267

274268
IcuIncludePath = case WithBrew of
275269
false -> GenericIcuIncludePaths;
276-
true -> "-I" ++ string:strip(os:cmd(BrewIcuPrefixCmd), right, $\n) ++ "/include"
270+
true -> "-I" ++ string:trim(os:cmd(BrewIcuPrefixCmd)) ++ "/include"
277271
end.
278272

279273
IcuLibPath = case WithBrew of
280274
false -> GenericIcuLibPaths;
281-
true -> "-L" ++ string:strip(os:cmd(BrewIcuPrefixCmd), right, $\n) ++ "/lib"
275+
true -> "-L" ++ string:trim(os:cmd(BrewIcuPrefixCmd)) ++ "/lib"
282276
end.
283277

284278
IcuEnv = [{"DRV_CFLAGS", "$DRV_CFLAGS -DPIC -O2 -fno-common"},

0 commit comments

Comments
 (0)