blob: a741cac39206404d9dd15dc1700b91793bba980f [file] [log] [blame]
% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
% ex: ts=4 sw=4 ft=erlang et
% Licensed under the Apache License, Version 2.0 (the "License"); you may not
% use this file except in compliance with the License. You may obtain a copy of
% the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
% License for the specific language governing permissions and limitations under
% the License.
Unix = "(linux|darwin|freebsd)".
Windows = "win32".
All = "(linux|darwin|freebsd|win32)".
% Windows is "special" so we treat it "specially"
Msys = "msys2_shell.cmd -defterm -no-start -ucrt64 -here -lc ".
PreHooks = [
{Unix, compile, "make CONFIG_LTO=y -C quickjs -j8 libquickjs.lto.a qjsc"},
{Windows, compile, Msys ++ "'make -C quickjs qjsc'"},
{All, compile, "escript build_js.escript compile"}
].
PostHooks = [
{Unix, clean, "make -C quickjs clean"},
{Windows, clean, Msys ++ "'make -C quickjs clean'"},
{All, clean, "escript build_js.escript clean"}
].
UnixEnv = [
{"CFLAGS", "$CFLAGS -flto -g -Wall -DCONFIG_LTO=y -O2 -Iquickjs"},
{"LDFLAGS", "$LDFLAGS -flto -lm quickjs/libquickjs.lto.a"},
% Clear ERL flags out as we're not actually building a NIF or driver here
{"ERL_CFLAGS", ""},
{"ERL_LDFLAGS", ""},
{"EXE_CFLAGS", ""},
{"EXE_LDFLAGS", ""}
].
WindowsEnv = [
{"CFLAGS", "-D_GNU_SOURCE -DCONFIG_BIGNUM -O2 -fwrapv -DCONFIG_VERSION=\\\"0\\\" -Iquickjs"},
{"EXE_CC_TEMPLATE", "gcc.exe -g -c $CFLAGS $PORT_IN_FILES -o $PORT_OUT_FILE"},
{"EXE_LINK_TEMPLATE", "gcc.exe -g -lm $PORT_IN_FILES $LDFLAGS -o $PORT_OUT_FILE"}
].
% couchjs_*_bytecode.c sources are auto-generated by build_js.escript
%
UnixMainjsSrc = ["c_src/couchjs.c", "c_src/couchjs_mainjs_bytecode.c"],
UnixCoffeeSrc = ["c_src/couchjs.c", "c_src/couchjs_coffee_bytecode.c"],
WindowsBaseSrc = [
"quickjs/quickjs.c",
"quickjs/libregexp.c",
"quickjs/libunicode.c",
"quickjs/cutils.c",
"quickjs/libbf.c",
"quickjs/quickjs-libc.c"
].
WindowsMainjsSrc = WindowsBaseSrc ++ UnixMainjsSrc.
WindowsCoffeeSrc = WindowsBaseSrc ++ UnixCoffeeSrc.
PortSpecs = [
{Unix, "priv/couchjs_mainjs", UnixMainjsSrc, [{env, UnixEnv}]},
{Unix, "priv/couchjs_coffee", UnixCoffeeSrc, [{env, UnixEnv}]},
{Windows, "priv/couchjs_mainjs.exe", WindowsMainjsSrc, [{env, WindowsEnv}]},
{Windows, "priv/couchjs_coffee.exe", WindowsCoffeeSrc, [{env, WindowsEnv}]}
].
AddConfig = [
{port_specs, PortSpecs},
{pre_hooks, PreHooks},
{post_hooks, PostHooks}
].
lists:foldl(fun({K, V}, CfgAcc) ->
case lists:keyfind(K, 1, CfgAcc) of
{K, Existent} when is_list(Existent) andalso is_list(V) ->
lists:keystore(K, 1, CfgAcc, {K, Existent ++ V});
false ->
lists:keystore(K, 1, CfgAcc, {K, V})
end
end, CONFIG, AddConfig).