summaryrefslogtreecommitdiff
path: root/rules/CC/foreign
diff options
context:
space:
mode:
Diffstat (limited to 'rules/CC/foreign')
-rw-r--r--rules/CC/foreign/EXPRESSIONS142
-rw-r--r--rules/CC/foreign/cmake/EXPRESSIONS70
-rw-r--r--rules/CC/foreign/cmake/RULES81
-rw-r--r--rules/CC/foreign/make/EXPRESSIONS130
-rw-r--r--rules/CC/foreign/make/RULES154
5 files changed, 361 insertions, 216 deletions
diff --git a/rules/CC/foreign/EXPRESSIONS b/rules/CC/foreign/EXPRESSIONS
index 2cc1ac9..64e0e27 100644
--- a/rules/CC/foreign/EXPRESSIONS
+++ b/rules/CC/foreign/EXPRESSIONS
@@ -31,4 +31,146 @@
}
}
}
+, "expand_exec_tool":
+ { "doc":
+ [ "Binary that expands specified env variables in argv and runs exec(2)."
+ , "The syntax for accessing variable \"VAR\" is \"$(VAR)\"."
+ , "Usage: expand_exec [VARS...] -- ARGV"
+ , ""
+ , "Requires a working C compiler for host from \"defaults\"."
+ ]
+ , "vars": ["CC", "ENV", "defaults-transition"]
+ , "imports":
+ { "compiler-cc": ["CC", "compiler-cc"]
+ , "default-ENV": ["CC", "default-ENV"]
+ , "default-TOOLCHAIN": ["CC", "default-TOOLCHAIN"]
+ , "default-NON_SYSTEM_TOOLS": ["CC", "default-NON_SYSTEM_TOOLS"]
+ }
+ , "expression":
+ { "type": "let*"
+ , "bindings":
+ [ ["TOOLCHAIN_DIR", "toolchain"]
+ , ["TOOLCHAIN", {"type": "CALL_EXPRESSION", "name": "default-TOOLCHAIN"}]
+ , [ "TOOLCHAIN"
+ , { "type": "to_subdir"
+ , "subdir": {"type": "var", "name": "TOOLCHAIN_DIR"}
+ , "$1": {"type": "var", "name": "TOOLCHAIN"}
+ }
+ ]
+ , [ "NON_SYSTEM_TOOLS"
+ , {"type": "CALL_EXPRESSION", "name": "default-NON_SYSTEM_TOOLS"}
+ ]
+ , ["CC", {"type": "CALL_EXPRESSION", "name": "compiler-cc"}]
+ , [ "ENV"
+ , { "type": "map_union"
+ , "$1":
+ [ {"type": "CALL_EXPRESSION", "name": "default-ENV"}
+ , {"type": "var", "name": "ENV", "default": {"type": "empty_map"}}
+ ]
+ }
+ ]
+ , [ "expand_exec.c"
+ , { "type": "singleton_map"
+ , "key": "expand_exec.c"
+ , "value":
+ { "type": "BLOB"
+ , "data":
+ { "type": "join"
+ , "separator": "\n"
+ , "$1":
+ [ "#include <stdlib.h>"
+ , "#include <string.h>"
+ , "#include <unistd.h>"
+ , ""
+ , "/* usage: ./expand_exec [VARS...] -- ARGS... */"
+ , "int main(int argc, const char *argv[]) {"
+ , " char** outv;"
+ , " const char** varv;"
+ , " int i, j, varc, sep = 0, retval = 0;"
+ , " for (i = 1; i < argc; ++i) if (strcmp(argv[i], \"--\") == 0) { sep=i; break; }"
+ , " varc = sep-1;"
+ , " argc -= sep+1;"
+ , " if (sep == 0 || argc < 1) return 1; /* error: missing sep or args */"
+ , " varv = &argv[1];"
+ , " argv = &argv[sep+1];"
+ , " outv = (char**)calloc((size_t)(argc+1), sizeof(char*));"
+ , " for (i = 0; i < argc; ++i) { /* iterate ARGS */"
+ , " const char* arg = argv[i];"
+ , " size_t arg_pos = 0, arg_len = strlen(arg);"
+ , " size_t out_pos = 0, out_len = arg_len;"
+ , " size_t str_pos = 0, str_len = 0;"
+ , " char* out = (char*)calloc((size_t)(out_len+1), sizeof(char));"
+ , " for (; arg_pos < arg_len; ++arg_pos) {"
+ , " if (strncmp(&arg[arg_pos], \"$(\", 2) == 0) {"
+ , " const char* start = &arg[arg_pos+2];"
+ , " const char* end = strchr(start, ')');"
+ , " if (end == NULL) {"
+ , " retval = 2; /* error: unterminated $(VAR) expression */"
+ , " free(out);"
+ , " goto cleanup;"
+ , " }"
+ , " for (j = 0; j < varc; ++j) { /* lookup VAR */"
+ , " const char* var = varv[j];"
+ , " size_t len_var = strlen(var);"
+ , " if ((size_t)(end - start) != len_var) continue;"
+ , " if (strncmp(&arg[arg_pos+2], var, len_var) == 0) {"
+ , " size_t val_len, out_len_new;"
+ , " const char* val = getenv(var);"
+ , " if (val == NULL) val = \"\";"
+ , " val_len = strlen(val);"
+ , " out_len_new = out_pos + str_len + val_len;"
+ , " if (out_len_new > out_len) {"
+ , " out = (char*)realloc(out, out_len_new+1);"
+ , " out_len = out_len_new;"
+ , " }"
+ , " strncat(out, &arg[str_pos], str_len); /* concat preceding substr */"
+ , " strncat(out, val, val_len); /* concat variable value */"
+ , " arg_pos += len_var + 2;"
+ , " out_pos += str_len + val_len;"
+ , " str_pos = arg_pos + 1;"
+ , " str_len = 0;"
+ , " break;"
+ , " }"
+ , " }"
+ , " if (j != varc) continue; /* success */"
+ , " }"
+ , " ++str_len;"
+ , " }"
+ , " if (str_len > 0) {"
+ , " if (out_pos + str_len > out_len) {"
+ , " out = (char*)realloc(out, out_pos + str_len + 1);"
+ , " }"
+ , " strncat(out, &arg[str_pos], str_len);"
+ , " }"
+ , " outv[i] = out;"
+ , " }"
+ , " execvp(outv[0], outv);"
+ , " retval = 3; /* error: exec failed */"
+ , "cleanup:"
+ , " for (i = 0; i < argc; ++i) if (outv[i] != NULL) free(outv[i]);"
+ , " free(outv);"
+ , " return retval;"
+ , "}"
+ ]
+ }
+ }
+ }
+ ]
+ ]
+ , "body":
+ { "type": "ACTION"
+ , "inputs":
+ { "type": "map_union"
+ , "$1":
+ [ {"type": "var", "name": "TOOLCHAIN"}
+ , {"type": "var", "name": "expand_exec.c"}
+ ]
+ }
+ , "cmd":
+ [{"type": "var", "name": "CC"}, "expand_exec.c", "-o", "expand_exec"]
+ , "outs": ["expand_exec"]
+ , "env": {"type": "var", "name": "ENV"}
+ }
+ }
+ }
}
diff --git a/rules/CC/foreign/cmake/EXPRESSIONS b/rules/CC/foreign/cmake/EXPRESSIONS
index 425c7a2..2266f61 100644
--- a/rules/CC/foreign/cmake/EXPRESSIONS
+++ b/rules/CC/foreign/cmake/EXPRESSIONS
@@ -1,11 +1,14 @@
{ "cmake-build":
{ "vars":
- [ "source_dir"
+ [ "ARCH"
+ , "HOST_ARCH"
+ , "source_dir"
, "cmake_subdir"
, "localbase_dir"
, "cmake_options"
, "cmake_defines"
, "cmake_jobs"
+ , "cmake_targets"
, "pre_cmds"
, "post_cmds"
, "CC"
@@ -19,6 +22,8 @@
, "ENV"
, "AR"
, "BUILD_POSITION_INDEPENDENT"
+ , "defaults-transition"
+ , "host-defaults-transition"
]
, "imports":
{ "artifacts": ["", "field_artifacts"]
@@ -31,11 +36,22 @@
, "default-ENV": ["CC", "default-ENV"]
, "default-TOOLCHAIN": ["CC", "default-TOOLCHAIN"]
, "default-NON_SYSTEM_TOOLS": ["CC", "default-NON_SYSTEM_TOOLS"]
+ , "expand_exec_tool": ["./", "..", "expand_exec_tool"]
}
, "expression":
{ "type": "let*"
, "bindings":
- [ ["TOOLCHAIN_DIR", "toolchain"]
+ [ [ "expand_exec"
+ , { "type": "let*"
+ , "bindings":
+ [ [ "defaults-transition"
+ , {"type": "var", "name": "host-defaults-transition"}
+ ]
+ ]
+ , "body": {"type": "CALL_EXPRESSION", "name": "expand_exec_tool"}
+ }
+ ]
+ , ["TOOLCHAIN_DIR", "toolchain"]
, ["TOOLCHAIN", {"type": "CALL_EXPRESSION", "name": "default-TOOLCHAIN"}]
, [ "TOOLCHAIN"
, { "type": "to_subdir"
@@ -97,17 +113,6 @@
}
}
]
- , [ "ENV"
- , { "type": "map_union"
- , "$1":
- [ {"type": "CALL_EXPRESSION", "name": "default-ENV"}
- , {"type": "var", "name": "ENV", "default": {"type": "empty_map"}}
- , { "type": "env"
- , "vars": ["CC", "CXX", "CXXFLAGS", "CFLAGS", "LDFLAGS"]
- }
- ]
- }
- ]
, [ "AR"
, { "type": "var"
, "name": "AR"
@@ -131,6 +136,17 @@
}
}
]
+ , [ "ENV"
+ , { "type": "map_union"
+ , "$1":
+ [ {"type": "CALL_EXPRESSION", "name": "default-ENV"}
+ , {"type": "var", "name": "ENV", "default": {"type": "empty_map"}}
+ , { "type": "env"
+ , "vars": ["CC", "CXX", "CXXFLAGS", "CFLAGS", "LDFLAGS", "AR"]
+ }
+ ]
+ }
+ ]
, [ "CMAKE_JOBS"
, { "type": "if"
, "cond": {"type": "var", "name": "cmake_jobs"}
@@ -152,6 +168,13 @@
, "$1": {"type": "var", "name": "cmake_subdir", "default": []}
}
]
+ , [ "cmake_targets"
+ , { "type": "if"
+ , "cond": {"type": "var", "name": "cmake_targets"}
+ , "then": {"type": "var", "name": "cmake_targets"}
+ , "else": ["install"]
+ }
+ ]
, [ "script"
, { "type": "singleton_map"
, "key": "run_cmake.sh"
@@ -165,7 +188,9 @@
, "$1":
[ [ "set -eu"
, "mkdir scratch"
- , "readonly TMPDIR=\"$(pwd)/scratch\""
+ , "readonly ROOT=\"$(pwd)\""
+ , "export TMPDIR=\"$(pwd)/scratch\""
+ , "export LOCALBASE=\"$(pwd)/localbase\""
]
, { "type": "if"
, "cond": {"type": "var", "name": "pre_cmds"}
@@ -181,20 +206,28 @@
, [ "readonly CMAKE_SUBDIR=\"$1\""
, "readonly CMAKE_AR=$(which $2)"
, "shift 2"
- , "cmake \"$@\" -S\"source/${CMAKE_SUBDIR}\" -Bbuild -DCMAKE_AR=${CMAKE_AR} -DCMAKE_INSTALL_PREFIX=./install -DCMAKE_PREFIX_PATH=\"$(pwd)/localbase\" -DPKG_CONFIG_ARGN=--define-prefix --no-warn-unused-cli >configure.log 2>&1 || (cat configure.log && exit 1)"
+ , "${ROOT}/expand_exec TMPDIR LOCALBASE CC CXX CFLAGS CXXFLAGS LDFLAGS AR -- cmake -S\"source/${CMAKE_SUBDIR}\" -Bbuild -DCMAKE_AR=${CMAKE_AR} -DCMAKE_INSTALL_PREFIX=./install -DCMAKE_PREFIX_PATH=\"$LOCALBASE\" -DPKG_CONFIG_ARGN=--define-prefix --no-warn-unused-cli \"$@\" >configure.log 2>&1 || (cat configure.log && exit 1)"
]
- , [ { "type": "join"
+ , { "type": "foreach"
+ , "range": {"type": "var", "name": "cmake_targets"}
+ , "var": "target"
+ , "body":
+ { "type": "join"
, "separator": " "
, "$1":
{ "type": "++"
, "$1":
[ {"type": "var", "name": "CMAKE_JOBS"}
- , [ "cmake --build build --target install >build.log 2>&1 || (cat configure.log build.log && exit 1)"
+ , [ "${ROOT}/expand_exec TMPDIR LOCALBASE CC CXX CFLAGS CXXFLAGS LDFLAGS AR -- cmake --build build --target"
+ , { "type": "join_cmd"
+ , "$1": [{"type": "var", "name": "target"}]
+ }
+ , ">>build.log 2>&1 || (cat build.log && exit 1)"
]
]
}
}
- ]
+ }
, ["find ./install -type l -delete"]
, { "type": "if"
, "cond": {"type": "var", "name": "post_cmds"}
@@ -226,6 +259,7 @@
, "$1":
[ {"type": "var", "name": "TOOLCHAIN"}
, {"type": "var", "name": "source_dir"}
+ , {"type": "var", "name": "expand_exec"}
, { "type": "var"
, "name": "localbase_dir"
, "default": {"type": "empty_map"}
diff --git a/rules/CC/foreign/cmake/RULES b/rules/CC/foreign/cmake/RULES
index e4d16e0..63d6e48 100644
--- a/rules/CC/foreign/cmake/RULES
+++ b/rules/CC/foreign/cmake/RULES
@@ -1,10 +1,18 @@
{ "data":
- { "doc": ["Data produced by CMake configure, build, and install."]
+ { "doc":
+ [ "Data produced by CMake configure, build, and install."
+ , ""
+ , "All variables accessible to commands and options are: \"TMPDIR\","
+ , "\"LOCALBASE\", \"CC\", \"CXX\", \"CFLAGS\", \"CXXFLAGS\", \"LDFLAGS\","
+ , "and \"AR\". \"LOCALBASE\" contains the path to the installed artifacts"
+ , "from \"deps\"."
+ ]
, "target_fields": ["project"]
, "string_fields":
[ "subdir"
, "options"
, "defines"
+ , "targets"
, "jobs"
, "pre_cmds"
, "post_cmds"
@@ -12,7 +20,9 @@
, "out_dirs"
]
, "config_vars":
- [ "CC"
+ [ "ARCH"
+ , "HOST_ARCH"
+ , "CC"
, "CXX"
, "CFLAGS"
, "CXXFLAGS"
@@ -41,6 +51,10 @@
[ "CMake defines for the configuration phase."
, "(e.g., [\"CMAKE_BUILD_TYPE=Release\"])"
]
+ , "targets":
+ [ "The CMake targets to build in the specified order"
+ , "(default: [\"install\"])."
+ ]
, "jobs":
[ "Number of jobs to run simultaneously. If omitted, CMake's default"
, "number is used."
@@ -48,16 +62,17 @@
, "pre_cmds":
[ "List of commands executed in the project directory before calling"
, "CMake. Useful for renaming files or directories. Note that data"
- , "between \"pre_cmds\" and \"post_cmds\" can be exchanged via $TMPDIR,"
- , "which is uniquely reserved for this action."
+ , "between \"pre_cmds\" and \"post_cmds\" can be exchanged via"
+ , "\"$TMPDIR\" which is uniquely reserved for this action."
]
, "post_cmds":
[ "List of commands executed in the install directory after successful"
, "installation but before the output files are collected. Useful for"
, "renaming files or directories. Note that data between \"pre_cmds\" and"
- , "\"post_cmds\" can be exchanged via $TMPDIR, which is uniquely reserved"
- , "for this action. The CMake source and build directory can be accessed"
- , "via $CMAKE_SOURCE_DIR and $CMAKE_BINARY_DIR, respectively."
+ , "\"post_cmds\" can be exchanged via \"$TMPDIR\", which is uniquely"
+ , "reserved for this action. The CMake source and build directory can be"
+ , "accessed via \"$CMAKE_SOURCE_DIR\" and \"$CMAKE_BINARY_DIR\","
+ , "respectively."
]
, "out_files":
[ "Paths to the produced output files. The paths are considered relative"
@@ -133,6 +148,11 @@
{ "stage_field": ["", "stage_singleton_field"]
, "cmake-build": "cmake-build"
, "strip-prefix": ["./", "..", "strip-prefix"]
+ , "for host": ["transitions", "for host"]
+ }
+ , "config_transitions":
+ { "defaults":
+ [{"type": "empty_map"}, {"type": "CALL_EXPRESSION", "name": "for host"}]
}
, "expression":
{ "type": "let*"
@@ -175,9 +195,14 @@
, ["cmake_subdir", {"type": "FIELD", "name": "subdir"}]
, ["cmake_options", {"type": "FIELD", "name": "options"}]
, ["cmake_defines", {"type": "FIELD", "name": "defines"}]
+ , ["cmake_targets", {"type": "FIELD", "name": "targets"}]
, ["cmake_jobs", {"type": "FIELD", "name": "jobs"}]
, ["pre_cmds", {"type": "FIELD", "name": "pre_cmds"}]
, ["post_cmds", {"type": "FIELD", "name": "post_cmds"}]
+ , ["defaults-transition", {"type": "empty_map"}]
+ , [ "host-defaults-transition"
+ , {"type": "CALL_EXPRESSION", "name": "for host"}
+ ]
, [ "full_install_dir"
, {"type": "CALL_EXPRESSION", "name": "cmake-build"}
]
@@ -226,7 +251,14 @@
}
}
, "library":
- { "doc": ["Library produced by CMake configure, build, and install."]
+ { "doc":
+ [ "Library produced by CMake configure, build, and install."
+ , ""
+ , "All variables accessible to commands and options are: \"TMPDIR\","
+ , "\"LOCALBASE\", \"CC\", \"CXX\", \"CFLAGS\", \"CXXFLAGS\", \"LDFLAGS\","
+ , "and \"AR\". \"LOCALBASE\" contains the path to the installed artifacts"
+ , "from \"deps\"."
+ ]
, "target_fields": ["project", "deps"]
, "string_fields":
[ "subdir"
@@ -249,7 +281,9 @@
, "pc_prefix"
]
, "config_vars":
- [ "CC"
+ [ "ARCH"
+ , "HOST_ARCH"
+ , "CC"
, "CXX"
, "CFLAGS"
, "CXXFLAGS"
@@ -282,12 +316,14 @@
, "components are joined with \".\"."
]
, "options":
- [ "CMake options for the configuration phase."
- , "(e.g., [\"-GNinja\", \"-Ax64\"])"
+ [ "CMake options for the configuration phase"
+ , "(e.g., [\"-GNinja\", \"-Ax64\"]). Variables can be accessed via"
+ , "\"$(<varname>)\", e.g., \"$(TMPDIR)\" for variable \"$TMPDIR\"."
]
, "defines":
- [ "CMake defines for the configuration phase."
- , "(e.g., [\"CMAKE_BUILD_TYPE=Release\"])"
+ [ "CMake defines for the configuration phase"
+ , "(e.g., [\"CMAKE_BUILD_TYPE=Release\"]). Variables can be accessed via"
+ , "\"$(<varname>)\", e.g., \"$(TMPDIR)\" for variable \"$TMPDIR\"."
]
, "jobs":
[ "Number of jobs to run simultaneously. If omitted, CMake's default"
@@ -296,17 +332,17 @@
, "pre_cmds":
[ "List of commands executed in the project directory before calling"
, "CMake. Useful for renaming files or directories. Note that data"
- , "between \"pre_cmds\" and \"post_cmds\" can be exchanged via $TMPDIR,"
- , "which is uniquely reserved for this action."
+ , "between \"pre_cmds\" and \"post_cmds\" can be exchanged via"
+ , "\"$TMPDIR\" which is uniquely reserved for this action."
]
, "post_cmds":
[ "List of commands executed in the install directory after successful"
, "installation but before the output files are collected. Useful for"
, "renaming files or directories (e.g., in case of SONAME mismatch). Note"
, "that data between \"pre_cmds\" and \"post_cmds\" can be exchanged via"
- , "$TMPDIR, which is uniquely reserved for this action. The CMake source"
- , "and build directory can be accessed via $CMAKE_SOURCE_DIR and"
- , "$CMAKE_BINARY_DIR, respectively."
+ , "\"$TMPDIR\", which is uniquely reserved for this action. The CMake"
+ , "source and build directory can be accessed via \"$CMAKE_SOURCE_DIR\""
+ , "and \"$CMAKE_BINARY_DIR\", respectively."
]
, "out_hdrs":
[ "Paths to produced public header files. The path is considered"
@@ -417,6 +453,11 @@
, "strip-prefix": ["./", "..", "strip-prefix"]
, "prebuilt result": ["CC/prebuilt", "prebuilt result"]
, "install-deps": ["CC", "install-with-deps stage"]
+ , "for host": ["transitions", "for host"]
+ }
+ , "config_transitions":
+ { "defaults":
+ [{"type": "empty_map"}, {"type": "CALL_EXPRESSION", "name": "for host"}]
}
, "expression":
{ "type": "let*"
@@ -551,6 +592,10 @@
, ["cmake_jobs", {"type": "FIELD", "name": "jobs"}]
, ["pre_cmds", {"type": "FIELD", "name": "pre_cmds"}]
, ["post_cmds", {"type": "FIELD", "name": "post_cmds"}]
+ , ["defaults-transition", {"type": "empty_map"}]
+ , [ "host-defaults-transition"
+ , {"type": "CALL_EXPRESSION", "name": "for host"}
+ ]
, [ "full_install_dir"
, {"type": "CALL_EXPRESSION", "name": "cmake-build"}
]
diff --git a/rules/CC/foreign/make/EXPRESSIONS b/rules/CC/foreign/make/EXPRESSIONS
index 7d733a6..ba98154 100644
--- a/rules/CC/foreign/make/EXPRESSIONS
+++ b/rules/CC/foreign/make/EXPRESSIONS
@@ -2,6 +2,7 @@
{ "vars":
[ "source_dir"
, "subdir"
+ , "localbase_dir"
, "configure"
, "configure_options"
, "make_targets"
@@ -10,14 +11,6 @@
, "make_jobs"
, "pre_cmds"
, "post_cmds"
- , "var_cc"
- , "var_cxx"
- , "var_ccflags"
- , "var_cxxflags"
- , "var_ldflags"
- , "var_ar"
- , "var_prefix"
- , "var_destdir"
, "CC"
, "CXX"
, "CFLAGS"
@@ -31,6 +24,8 @@
, "PREFIX"
, "BUILD_POSITION_INDEPENDENT"
, "TIMEOUT_SCALE"
+ , "defaults-transition"
+ , "host-defaults-transition"
]
, "imports":
{ "artifacts": ["", "field_artifacts"]
@@ -43,11 +38,22 @@
, "default-ENV": ["CC", "default-ENV"]
, "default-TOOLCHAIN": ["CC", "default-TOOLCHAIN"]
, "default-NON_SYSTEM_TOOLS": ["CC", "default-NON_SYSTEM_TOOLS"]
+ , "expand_exec_tool": ["./", "..", "expand_exec_tool"]
}
, "expression":
{ "type": "let*"
, "bindings":
- [ ["TOOLCHAIN_DIR", "toolchain"]
+ [ [ "expand_exec"
+ , { "type": "let*"
+ , "bindings":
+ [ [ "defaults-transition"
+ , {"type": "var", "name": "host-defaults-transition"}
+ ]
+ ]
+ , "body": {"type": "CALL_EXPRESSION", "name": "expand_exec_tool"}
+ }
+ ]
+ , ["TOOLCHAIN_DIR", "toolchain"]
, ["TOOLCHAIN", {"type": "CALL_EXPRESSION", "name": "default-TOOLCHAIN"}]
, [ "TOOLCHAIN"
, { "type": "to_subdir"
@@ -131,81 +137,9 @@
, "$1":
[ {"type": "CALL_EXPRESSION", "name": "default-ENV"}
, {"type": "var", "name": "ENV", "default": {"type": "empty_map"}}
- , { "type": "singleton_map"
- , "key":
- { "type": "if"
- , "cond": {"type": "var", "name": "var_cc"}
- , "then":
- {"type": "join", "$1": {"type": "var", "name": "var_cc"}}
- , "else": "CC"
- }
- , "value": {"type": "var", "name": "CC"}
- }
- , { "type": "singleton_map"
- , "key":
- { "type": "if"
- , "cond": {"type": "var", "name": "var_cxx"}
- , "then":
- {"type": "join", "$1": {"type": "var", "name": "var_cxx"}}
- , "else": "CXX"
- }
- , "value": {"type": "var", "name": "CXX"}
- }
- , { "type": "singleton_map"
- , "key":
- { "type": "if"
- , "cond": {"type": "var", "name": "var_ccflags"}
- , "then":
- { "type": "join"
- , "$1": {"type": "var", "name": "var_ccflags"}
- }
- , "else": "CFLAGS"
- }
- , "value": {"type": "var", "name": "CFLAGS"}
- }
- , { "type": "singleton_map"
- , "key":
- { "type": "if"
- , "cond": {"type": "var", "name": "var_cxxflags"}
- , "then":
- { "type": "join"
- , "$1": {"type": "var", "name": "var_cxxflags"}
- }
- , "else": "CXXFLAGS"
- }
- , "value": {"type": "var", "name": "CXXFLAGS"}
- }
- , { "type": "singleton_map"
- , "key":
- { "type": "if"
- , "cond": {"type": "var", "name": "var_ldflags"}
- , "then":
- { "type": "join"
- , "$1": {"type": "var", "name": "var_ldflags"}
- }
- , "else": "LDFLAGS"
- }
- , "value": {"type": "var", "name": "LDFLAGS"}
- }
- , { "type": "singleton_map"
- , "key":
- { "type": "if"
- , "cond": {"type": "var", "name": "var_ar"}
- , "then":
- {"type": "join", "$1": {"type": "var", "name": "var_ar"}}
- , "else": "AR"
- }
- , "value": {"type": "var", "name": "AR"}
- }
- , { "type": "singleton_map"
- , "key":
- { "type": "if"
- , "cond": {"type": "var", "name": "var_prefix"}
- , "then":
- {"type": "join", "$1": {"type": "var", "name": "var_prefix"}}
- , "else": "PREFIX"
- }
- , "value": {"type": "var", "name": "PREFIX"}
+ , { "type": "env"
+ , "vars":
+ ["CC", "CXX", "CFLAGS", "CXXFLAGS", "LDFLAGS", "AR", "PREFIX"]
}
]
}
@@ -251,7 +185,10 @@
, "$1":
[ [ "set -eu"
, "mkdir scratch"
- , "readonly TMPDIR=\"$(pwd)/scratch\""
+ , "readonly ROOT=\"$(pwd)\""
+ , "export TMPDIR=\"$(pwd)/scratch\""
+ , "export DESTDIR=\"$(pwd)/install\""
+ , "export LOCALBASE=\"$(pwd)/localbase\""
]
, { "type": "if"
, "cond": {"type": "var", "name": "pre_cmds"}
@@ -264,18 +201,14 @@
]
}
}
- , [ "readonly SUBDIR=\"$1\""
- , "readonly VAR_DESTDIR=$2"
- , "shift 2"
- ]
+ , ["readonly SUBDIR=\"$1\"", "shift"]
, { "type": "if"
, "cond": {"type": "var", "name": "configure_args"}
, "then":
- [ "( readonly ROOT=\"$(pwd)\""
- , " cd \"source/${SUBDIR}\""
+ [ "( cd \"source/${SUBDIR}\""
, { "type": "join"
, "$1":
- [ "./configure "
+ [ "${ROOT}/expand_exec TMPDIR DESTDIR LOCALBASE CC CXX CFLAGS CXXFLAGS LDFLAGS AR PREFIX -- ./configure "
, { "type": "join_cmd"
, "$1": {"type": "var", "name": "configure_args"}
}
@@ -291,7 +224,7 @@
, "body":
{ "type": "join"
, "$1":
- [ "make \"$@\" -C \"source/${SUBDIR}\" ${VAR_DESTDIR}=$(pwd)/install "
+ [ "${ROOT}/expand_exec TMPDIR DESTDIR LOCALBASE CC CXX CFLAGS CXXFLAGS LDFLAGS AR PREFIX -- make DESTDIR=${DESTDIR} -C \"source/${SUBDIR}\" \"$@\" "
, { "type": "join_cmd"
, "$1": [{"type": "var", "name": "target"}]
}
@@ -325,6 +258,11 @@
, "$1":
[ {"type": "var", "name": "TOOLCHAIN"}
, {"type": "var", "name": "source_dir"}
+ , {"type": "var", "name": "expand_exec"}
+ , { "type": "var"
+ , "name": "localbase_dir"
+ , "default": {"type": "empty_map"}
+ }
, {"type": "var", "name": "script"}
]
}
@@ -333,12 +271,6 @@
, "$1":
[ ["/bin/sh", "run_make.sh"]
, [{"type": "var", "name": "SUBDIR"}]
- , { "type": "if"
- , "cond": {"type": "var", "name": "var_destdir"}
- , "then":
- [{"type": "join", "$1": {"type": "var", "name": "var_destdir"}}]
- , "else": ["DESTDIR"]
- }
, {"type": "var", "name": "make_options"}
, { "type": "if"
, "cond": {"type": "var", "name": "make_jobs"}
diff --git a/rules/CC/foreign/make/RULES b/rules/CC/foreign/make/RULES
index 992ec2a..79e6b2b 100644
--- a/rules/CC/foreign/make/RULES
+++ b/rules/CC/foreign/make/RULES
@@ -1,5 +1,12 @@
{ "data":
- { "doc": ["Data produced by Configure and Make build and install."]
+ { "doc":
+ [ "Data produced by Configure and Make build and install."
+ , ""
+ , "All variables accessible to commands and options are: \"TMPDIR\","
+ , "\"LOCALBASE\", \"CC\", \"CXX\", \"CFLAGS\", \"CXXFLAGS\", \"LDFLAGS\","
+ , "\"AR\", and \"PREFIX\". \"LOCALBASE\" contains the path to the"
+ , "installed artifacts from \"deps\"."
+ ]
, "target_fields": ["project"]
, "string_fields":
[ "subdir"
@@ -13,17 +20,11 @@
, "post_cmds"
, "out_files"
, "out_dirs"
- , "var_cc"
- , "var_cxx"
- , "var_ccflags"
- , "var_cxxflags"
- , "var_ldflags"
- , "var_ar"
- , "var_prefix"
- , "var_destdir"
]
, "config_vars":
- [ "CC"
+ [ "ARCH"
+ , "HOST_ARCH"
+ , "CC"
, "CXX"
, "CFLAGS"
, "CXXFLAGS"
@@ -47,7 +48,10 @@
]
, "configure": ["Run ./configure if non-empty."]
, "configure_options":
- ["The configure options (the \"--prefix\" option is automatically set."]
+ [ "The configure options (the \"--prefix\" option is automatically set."
+ , "Variables can be accessed via \"$(<varname>)\", e.g., \"$(TMPDIR)\""
+ , "for variable \"$TMPDIR\"."
+ ]
, "targets":
[ "The Make targets to build in the specified order"
, "(default: [\"install\"])."
@@ -59,8 +63,10 @@
, "taken, with the default value being \"/\"."
]
, "options":
- [ "Make options for the configuration phase."
- , "(e.g., [\"-f\", \"Makefile\", \"ARCH=x86\"])"
+ [ "Make options for the configuration phase"
+ , "(e.g., [\"-f\", \"Makefile\", \"ARCH=x86\", \"LD=$(CC)\"]). Variables"
+ , "can be accessed via \"$(<varname>)\", e.g., \"$(TMPDIR)\" for"
+ , "variable \"$TMPDIR\"."
]
, "jobs":
[ "Number of jobs to run simultaneously. If omitted, Make's default"
@@ -68,16 +74,16 @@
]
, "pre_cmds":
[ "List of commands executed in the project directory before calling"
- , "Make. Useful for renaming files or directories. Note that data"
- , "between \"pre_cmds\" and \"post_cmds\" can be exchanged via $TMPDIR,"
- , "which is uniquely reserved for this action."
+ , "Configure or Make. Useful for renaming files or directories. Note"
+ , "that data between \"pre_cmds\" and \"post_cmds\" can be exchanged via"
+ , "\"$TMPDIR\", which is uniquely reserved for this action."
]
, "post_cmds":
[ "List of commands executed in the install directory after successful"
, "installation but before the output files are collected. Useful for"
, "renaming files or directories. Note that data between \"pre_cmds\" and"
- , "\"post_cmds\" can be exchanged via $TMPDIR, which is uniquely reserved"
- , "for this action."
+ , "\"post_cmds\" can be exchanged via \"$TMPDIR\", which is uniquely"
+ , "reserved for this action."
]
, "out_files":
[ "Paths to the produced output files. The paths are considered relative"
@@ -89,22 +95,6 @@
, "relative to the install directory."
, "Note that \"out_files\" and \"out_dirs\" may not overlap."
]
- , "var_cc":
- ["Variable name used to specify the C compiler (default: \"CC\")."]
- , "var_cxx":
- ["Variable name used to specify the C++ compiler (default: \"CXX\")."]
- , "var_ccflags":
- ["Variable name used to specify the C flags (default: \"CFLAGS\")."]
- , "var_cxxflags":
- ["Variable name used to specify the C++ flags (default: \"CXXFLAGS\")."]
- , "var_ldflags":
- ["Variable name used to specify the link flags (default: \"LDFLAGS\")."]
- , "var_ar":
- ["Variable name used to specify the archiver (default: \"AR\")."]
- , "var_prefix":
- ["Variable name used to specify the prefix (default: \"PREFIX\")."]
- , "var_destdir":
- ["Variable name used to specify the destdir (default: \"DESTDIR\")."]
}
, "config_doc":
{ "CC":
@@ -174,6 +164,11 @@
{ "stage_field": ["", "stage_singleton_field"]
, "make-build": "make-build"
, "strip-prefix": ["./", "..", "strip-prefix"]
+ , "for host": ["transitions", "for host"]
+ }
+ , "config_transitions":
+ { "defaults":
+ [{"type": "empty_map"}, {"type": "CALL_EXPRESSION", "name": "for host"}]
}
, "expression":
{ "type": "let*"
@@ -222,14 +217,10 @@
, ["make_jobs", {"type": "FIELD", "name": "jobs"}]
, ["pre_cmds", {"type": "FIELD", "name": "pre_cmds"}]
, ["post_cmds", {"type": "FIELD", "name": "post_cmds"}]
- , ["var_cc", {"type": "FIELD", "name": "var_cc"}]
- , ["var_cxx", {"type": "FIELD", "name": "var_cxx"}]
- , ["var_ccflags", {"type": "FIELD", "name": "var_ccflags"}]
- , ["var_cxxflags", {"type": "FIELD", "name": "var_cxxflags"}]
- , ["var_ldflags", {"type": "FIELD", "name": "var_ldflags"}]
- , ["var_ar", {"type": "FIELD", "name": "var_ar"}]
- , ["var_prefix", {"type": "FIELD", "name": "var_prefix"}]
- , ["var_destdir", {"type": "FIELD", "name": "var_destdir"}]
+ , ["defaults-transition", {"type": "empty_map"}]
+ , [ "host-defaults-transition"
+ , {"type": "CALL_EXPRESSION", "name": "for host"}
+ ]
, ["full_install_dir", {"type": "CALL_EXPRESSION", "name": "make-build"}]
, [ "install_dir"
, { "type": "ACTION"
@@ -276,7 +267,14 @@
}
}
, "library":
- { "doc": ["Library produced by Configure and Make build and install."]
+ { "doc":
+ [ "Library produced by Configure and Make build and install."
+ , ""
+ , "All variables accessible to commands and options are: \"TMPDIR\","
+ , "\"LOCALBASE\", \"CC\", \"CXX\", \"CFLAGS\", \"CXXFLAGS\", \"LDFLAGS\","
+ , "\"AR\", and \"PREFIX\". \"LOCALBASE\" contains the path to the"
+ , "installed artifacts from \"deps\"."
+ ]
, "target_fields": ["project", "deps"]
, "string_fields":
[ "subdir"
@@ -300,17 +298,11 @@
, "hdr_prefix"
, "lib_prefix"
, "pc_prefix"
- , "var_cc"
- , "var_cxx"
- , "var_ccflags"
- , "var_cxxflags"
- , "var_ldflags"
- , "var_ar"
- , "var_prefix"
- , "var_destdir"
]
, "config_vars":
- [ "CC"
+ [ "ARCH"
+ , "HOST_ARCH"
+ , "CC"
, "CXX"
, "CFLAGS"
, "CXXFLAGS"
@@ -357,7 +349,7 @@
, "taken, with the default value being \"/\"."
]
, "options":
- [ "Make options for the configuration phase."
+ [ "Make options for the build phase."
, "(e.g., [\"-f\", \"Makefile\", \"ARCH=x86\"])"
]
, "jobs":
@@ -366,16 +358,16 @@
]
, "pre_cmds":
[ "List of commands executed in the project directory before calling"
- , "Make. Useful for renaming files or directories. Note that data"
- , "between \"pre_cmds\" and \"post_cmds\" can be exchanged via $TMPDIR,"
- , "which is uniquely reserved for this action."
+ , "Configure or Make. Useful for renaming files or directories. Note"
+ , "that data between \"pre_cmds\" and \"post_cmds\" can be exchanged via"
+ , "\"$TMPDIR\", which is uniquely reserved for this action."
]
, "post_cmds":
[ "List of commands executed in the install directory after successful"
, "installation but before the output files are collected. Useful for"
, "renaming files or directories (e.g., in case of SONAME mismatch). Note"
, "that data between \"pre_cmds\" and \"post_cmds\" can be exchanged via"
- , "$TMPDIR, which is uniquely reserved for this action."
+ , "\"$TMPDIR\", which is uniquely reserved for this action."
]
, "out_hdrs":
[ "Paths to produced public header files. The path is considered"
@@ -424,22 +416,6 @@
, "directory components are joined with \"/\". Defaults to"
, "\"lib/pkgconfig\" if not set."
]
- , "var_cc":
- ["Variable name used to specify the C compiler (default: \"CC\")."]
- , "var_cxx":
- ["Variable name used to specify the C++ compiler (default: \"CXX\")."]
- , "var_ccflags":
- ["Variable name used to specify the C flags (default: \"CFLAGS\")."]
- , "var_cxxflags":
- ["Variable name used to specify the C++ flags (default: \"CXXFLAGS\")."]
- , "var_ldflags":
- ["Variable name used to specify the link flags (default: \"LDFLAGS\")."]
- , "var_ar":
- ["Variable name used to specify the archiver (default: \"AR\")."]
- , "var_prefix":
- ["Variable name used to specify the prefix (default: \"PREFIX\")."]
- , "var_destdir":
- ["Variable name used to specify the destdir (default: \"DESTDIR\")."]
}
, "config_doc":
{ "CC":
@@ -506,6 +482,12 @@
, "make-build": "make-build"
, "strip-prefix": ["./", "..", "strip-prefix"]
, "prebuilt result": ["CC/prebuilt", "prebuilt result"]
+ , "install-deps": ["CC", "install-with-deps stage"]
+ , "for host": ["transitions", "for host"]
+ }
+ , "config_transitions":
+ { "defaults":
+ [{"type": "empty_map"}, {"type": "CALL_EXPRESSION", "name": "for host"}]
}
, "expression":
{ "type": "let*"
@@ -564,6 +546,20 @@
, "body": {"type": "CALL_EXPRESSION", "name": "stage_field"}
}
]
+ , [ "localbase_dir"
+ , { "type": "to_subdir"
+ , "subdir": "localbase"
+ , "msg": "dependency installation files may not overlap"
+ , "$1":
+ { "type": "let*"
+ , "bindings":
+ [ ["pc-install-dir", "lib/pkgconfig"]
+ , ["targets", {"type": "FIELD", "name": "deps"}]
+ ]
+ , "body": {"type": "CALL_EXPRESSION", "name": "install-deps"}
+ }
+ }
+ ]
, [ "installed_dirs"
, { "type": "foreach"
, "var": "dir_path"
@@ -629,14 +625,10 @@
, ["make_jobs", {"type": "FIELD", "name": "jobs"}]
, ["pre_cmds", {"type": "FIELD", "name": "pre_cmds"}]
, ["post_cmds", {"type": "FIELD", "name": "post_cmds"}]
- , ["var_cc", {"type": "FIELD", "name": "var_cc"}]
- , ["var_cxx", {"type": "FIELD", "name": "var_cxx"}]
- , ["var_ccflags", {"type": "FIELD", "name": "var_ccflags"}]
- , ["var_cxxflags", {"type": "FIELD", "name": "var_cxxflags"}]
- , ["var_ldflags", {"type": "FIELD", "name": "var_ldflags"}]
- , ["var_ar", {"type": "FIELD", "name": "var_ar"}]
- , ["var_prefix", {"type": "FIELD", "name": "var_prefix"}]
- , ["var_destdir", {"type": "FIELD", "name": "var_destdir"}]
+ , ["defaults-transition", {"type": "empty_map"}]
+ , [ "host-defaults-transition"
+ , {"type": "CALL_EXPRESSION", "name": "for host"}
+ ]
, ["full_install_dir", {"type": "CALL_EXPRESSION", "name": "make-build"}]
, [ "install_dir"
, { "type": "ACTION"