diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2023-05-30 15:38:40 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2023-05-30 15:38:40 +0200 |
commit | 14300d3768522b1a201c30c94b6e54e096520b20 (patch) | |
tree | eaa057fd88ddba1a94c48585fcfcbb71628fcbe7 /rules/CC/foreign | |
parent | 2d7051782625966857286aace6ff18760114ecc7 (diff) | |
parent | 9f535dadf06c6c6554bac632069777cf1b63ebf5 (diff) | |
download | rules-cc-14300d3768522b1a201c30c94b6e54e096520b20.tar.gz |
Merge commit '9f535dadf06c6c6554bac632069777cf1b63ebf5' into rules/rules-cc
Diffstat (limited to 'rules/CC/foreign')
-rw-r--r-- | rules/CC/foreign/cmake/EXPRESSIONS | 80 | ||||
-rw-r--r-- | rules/CC/foreign/cmake/RULES | 18 | ||||
-rw-r--r-- | rules/CC/foreign/make/EXPRESSIONS | 307 | ||||
-rw-r--r-- | rules/CC/foreign/make/RULES | 52 |
4 files changed, 305 insertions, 152 deletions
diff --git a/rules/CC/foreign/cmake/EXPRESSIONS b/rules/CC/foreign/cmake/EXPRESSIONS index 8977d5a..4c21f4b 100644 --- a/rules/CC/foreign/cmake/EXPRESSIONS +++ b/rules/CC/foreign/cmake/EXPRESSIONS @@ -1,6 +1,7 @@ { "cmake-build": { "vars": [ "source_dir" + , "cmake_subdir" , "cmake_options" , "cmake_defines" , "cmake_jobs" @@ -27,11 +28,24 @@ , "default-LDFLAGS": ["CC", "default-LDFLAGS"] , "default-AR": ["CC", "default-AR"] , "default-ENV": ["CC", "default-ENV"] + , "default-TOOLCHAIN": ["CC", "default-TOOLCHAIN"] + , "default-NON_SYSTEM_TOOLS": ["CC", "default-NON_SYSTEM_TOOLS"] } , "expression": { "type": "let*" , "bindings": - [ [ "CMAKE_FLAGS" + [ ["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"} + ] + , [ "CMAKE_FLAGS" , { "type": "++" , "$1": [ { "type": "foreach" @@ -47,6 +61,7 @@ , "cond": {"type": "var", "name": "BUILD_POSITION_INDEPENDENT"} , "then": ["-DCMAKE_POSITION_INDEPENDENT_CODE=ON"] } + , ["-DCMAKE_INSTALL_RPATH=$ORIGIN;$ORIGIN/../lib"] ] } ] @@ -84,26 +99,35 @@ , [ "ENV" , { "type": "map_union" , "$1": - { "type": "++" - , "$1": - [ {"type": "CALL_EXPRESSION", "name": "default-ENV"} - , [ { "type": "var" - , "name": "ENV" - , "default": {"type": "empty_map"} - } - ] - , [ { "type": "env" - , "vars": ["CC", "CXX", "CXXFLAGS", "CFLAGS", "LDFLAGS"] - } - ] - ] - } + [ {"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" - , "default": {"type": "CALL_EXPRESSION", "name": "default-AR"} + , "default": + { "type": "join" + , "$1": + { "type": "++" + , "$1": + [ { "type": "if" + , "cond": + { "type": "lookup" + , "key": "AR" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": + ["./", {"type": "var", "name": "TOOLCHAIN_DIR"}, "/"] + } + , {"type": "CALL_EXPRESSION", "name": "default-AR"} + ] + } + } } ] , [ "CMAKE_JOBS" @@ -121,6 +145,12 @@ ] } ] + , [ "CMAKE_SUBDIR" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "var", "name": "cmake_subdir", "default": []} + } + ] , [ "script" , { "type": "singleton_map" , "key": "run_cmake.sh" @@ -147,9 +177,10 @@ ] } } - , [ "readonly CMAKE_AR=$(which $1)" - , "shift" - , "cmake \"$@\" -Ssource -Bbuild -DCMAKE_AR=${CMAKE_AR} -DCMAKE_INSTALL_PREFIX=./install >configure.log || (cat configure.log && exit 1)" + , [ "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 >configure.log 2>&1 || (cat configure.log && exit 1)" ] , [ { "type": "join" , "separator": " " @@ -157,7 +188,7 @@ { "type": "++" , "$1": [ {"type": "var", "name": "CMAKE_JOBS"} - , [ "cmake --build build --target install >build.log || (cat configure.log build.log && exit 1)" + , [ "cmake --build build --target install >build.log 2>&1 || (cat configure.log build.log && exit 1)" ] ] } @@ -192,14 +223,19 @@ , "inputs": { "type": "map_union" , "$1": - [ {"type": "var", "name": "source_dir"} + [ {"type": "var", "name": "TOOLCHAIN"} + , {"type": "var", "name": "source_dir"} , {"type": "var", "name": "script"} ] } , "cmd": { "type": "++" , "$1": - [ ["/bin/sh", "run_cmake.sh", {"type": "var", "name": "AR"}] + [ [ "/bin/sh" + , "run_cmake.sh" + , {"type": "var", "name": "CMAKE_SUBDIR"} + , {"type": "var", "name": "AR"} + ] , {"type": "var", "name": "CMAKE_FLAGS"} ] } diff --git a/rules/CC/foreign/cmake/RULES b/rules/CC/foreign/cmake/RULES index 8651f4e..a53b92e 100644 --- a/rules/CC/foreign/cmake/RULES +++ b/rules/CC/foreign/cmake/RULES @@ -2,7 +2,8 @@ { "doc": ["Data produced by CMake configure, build, and install."] , "target_fields": ["project"] , "string_fields": - [ "options" + [ "subdir" + , "options" , "defines" , "jobs" , "pre_cmds" @@ -27,6 +28,10 @@ , "field_doc": { "project": ["The CMake project directory. It should contain a single tree artifact"] + , "subdir": + [ "The subdirectory that contains the entry CMakeLists.txt. Individual" + , "directory components are joined with \"/\"." + ] , "options": [ "CMake options for the configuration phase." , "(e.g., [\"-GNinja\", \"-Ax64\"])" @@ -162,6 +167,7 @@ } } ] + , ["cmake_subdir", {"type": "FIELD", "name": "subdir"}] , ["cmake_options", {"type": "FIELD", "name": "options"}] , ["cmake_defines", {"type": "FIELD", "name": "defines"}] , ["cmake_jobs", {"type": "FIELD", "name": "jobs"}] @@ -218,7 +224,8 @@ { "doc": ["Library produced by CMake configure, build, and install."] , "target_fields": ["project", "deps"] , "string_fields": - [ "name" + [ "subdir" + , "name" , "version" , "stage" , "options" @@ -256,6 +263,10 @@ , "field_doc": { "project": ["The CMake project directory. It should contain a single tree artifact"] + , "subdir": + [ "The subdirectory that contains the entry CMakeLists.txt. Individual" + , "directory components are joined with \"/\"." + ] , "name": [ "The name of the library (without leading \"lib\" or trailing file name" , "extension), also used as name for pkg-config files." @@ -509,6 +520,7 @@ ] } ] + , ["cmake_subdir", {"type": "FIELD", "name": "subdir"}] , ["cmake_options", {"type": "FIELD", "name": "options"}] , ["cmake_defines", {"type": "FIELD", "name": "defines"}] , ["cmake_jobs", {"type": "FIELD", "name": "jobs"}] @@ -589,7 +601,7 @@ , "$1": {"type": "FIELD", "name": "stage"} } ] - , ["deps-fieldnames", ["deps"]] + , ["deps-fieldnames", ["deps", "defaults"]] ] , "body": {"type": "CALL_EXPRESSION", "name": "prebuilt result"} } diff --git a/rules/CC/foreign/make/EXPRESSIONS b/rules/CC/foreign/make/EXPRESSIONS index e853b29..df2f98f 100644 --- a/rules/CC/foreign/make/EXPRESSIONS +++ b/rules/CC/foreign/make/EXPRESSIONS @@ -1,7 +1,10 @@ { "make-build": { "vars": [ "source_dir" - , "make_target" + , "subdir" + , "configure" + , "configure_options" + , "make_targets" , "make_prefix" , "make_options" , "make_jobs" @@ -37,11 +40,24 @@ , "default-LDFLAGS": ["CC", "default-LDFLAGS"] , "default-AR": ["CC", "default-AR"] , "default-ENV": ["CC", "default-ENV"] + , "default-TOOLCHAIN": ["CC", "default-TOOLCHAIN"] + , "default-NON_SYSTEM_TOOLS": ["CC", "default-NON_SYSTEM_TOOLS"] } , "expression": { "type": "let*" , "bindings": - [ ["CC", {"type": "CALL_EXPRESSION", "name": "compiler-cc"}] + [ ["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"}] , ["CXX", {"type": "CALL_EXPRESSION", "name": "compiler-cxx"}] , [ "CFLAGS" , { "type": "join" @@ -61,7 +77,8 @@ , "$1": { "type": "++" , "$1": - [ { "type": "var" + [ ["-Wl,-rpath,$ORIGIN", "-Wl,-rpath,$ORIGIN/../lib"] + , { "type": "var" , "name": "LDFLAGS" , "default": {"type": "CALL_EXPRESSION", "name": "default-LDFLAGS"} @@ -74,123 +91,152 @@ , [ "AR" , { "type": "var" , "name": "AR" - , "default": {"type": "CALL_EXPRESSION", "name": "default-AR"} + , "default": + { "type": "join" + , "$1": + { "type": "++" + , "$1": + [ { "type": "if" + , "cond": + { "type": "lookup" + , "key": "AR" + , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"} + } + , "then": + ["./", {"type": "var", "name": "TOOLCHAIN_DIR"}, "/"] + } + , {"type": "CALL_EXPRESSION", "name": "default-AR"} + ] + } + } + } + ] + , [ "PREFIX" + , { "type": "if" + , "cond": {"type": "var", "name": "make_prefix"} + , "then": + { "type": "join" + , "separator": "/" + , "$1": + { "type": "++" + , "$1": [[""], {"type": "var", "name": "make_prefix"}] + } + } + , "else": {"type": "var", "name": "PREFIX", "default": "/"} } ] , [ "ENV" , { "type": "map_union" , "$1": - { "type": "++" - , "$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": "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"} } - ] - , [ { "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"} + , "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"} } - ] - , [ { "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"} + , "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"} } - ] - , [ { "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": "if" - , "cond": {"type": "var", "name": "make_prefix"} - , "then": - { "type": "join" - , "separator": "/" - , "$1": - { "type": "++" - , "$1": [[""], {"type": "var", "name": "make_prefix"}] - } - } - , "else": {"type": "var", "name": "PREFIX", "default": "/"} - } + , "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"} + } + ] + } + ] + , [ "SUBDIR" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "var", "name": "subdir", "default": []} + } + ] + , [ "configure_args" + , { "type": "if" + , "cond": {"type": "var", "name": "configure"} + , "then": + { "type": "++" + , "$1": + [ {"type": "var", "name": "configure_options", "default": []} + , [ { "type": "join" + , "$1": ["--prefix=", {"type": "var", "name": "PREFIX"}] } ] ] } } ] + , [ "make_targets" + , { "type": "if" + , "cond": {"type": "var", "name": "make_targets"} + , "then": {"type": "var", "name": "make_targets"} + , "else": ["install"] + } + ] , [ "script" , { "type": "singleton_map" , "key": "run_make.sh" @@ -217,12 +263,43 @@ ] } } - , [ "readonly VAR_DESTDIR=$1" - , "shift" - , "make \"$@\" -C source ${VAR_DESTDIR}=$(pwd)/install >build.log || (cat build.log && exit 1)" - , "find ./install -type l -delete" + , [ "readonly SUBDIR=\"$1\"" + , "readonly VAR_DESTDIR=$2" + , "shift 2" ] , { "type": "if" + , "cond": {"type": "var", "name": "configure_args"} + , "then": + [ "( readonly ROOT=\"$(pwd)\"" + , " cd \"source/${SUBDIR}\"" + , { "type": "join" + , "$1": + [ "./configure " + , { "type": "join_cmd" + , "$1": {"type": "var", "name": "configure_args"} + } + , " >\"${ROOT}/configure.log\" 2>&1 || (cat \"${ROOT}/configure.log\" && exit 1)" + ] + } + , ")" + ] + } + , { "type": "foreach" + , "range": {"type": "var", "name": "make_targets"} + , "var": "target" + , "body": + { "type": "join" + , "$1": + [ "make \"$@\" -C \"source/${SUBDIR}\" ${VAR_DESTDIR}=$(pwd)/install " + , { "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"} , "then": { "type": "++" @@ -245,7 +322,8 @@ , "inputs": { "type": "map_union" , "$1": - [ {"type": "var", "name": "source_dir"} + [ {"type": "var", "name": "TOOLCHAIN"} + , {"type": "var", "name": "source_dir"} , {"type": "var", "name": "script"} ] } @@ -253,6 +331,7 @@ { "type": "++" , "$1": [ ["/bin/sh", "run_make.sh"] + , [{"type": "var", "name": "SUBDIR"}] , { "type": "if" , "cond": {"type": "var", "name": "var_destdir"} , "then": @@ -260,12 +339,6 @@ , "else": ["DESTDIR"] } , {"type": "var", "name": "make_options"} - , { "type": "if" - , "cond": {"type": "var", "name": "make_target"} - , "then": - [{"type": "join", "$1": {"type": "var", "name": "make_target"}}] - , "else": ["install"] - } , [ { "type": "join" , "$1": { "type": "++" diff --git a/rules/CC/foreign/make/RULES b/rules/CC/foreign/make/RULES index 9c8c738..8278e3f 100644 --- a/rules/CC/foreign/make/RULES +++ b/rules/CC/foreign/make/RULES @@ -1,8 +1,11 @@ { "data": - { "doc": ["Data produced by Make build and install."] + { "doc": ["Data produced by Configure and Make build and install."] , "target_fields": ["project"] , "string_fields": - [ "target" + [ "subdir" + , "configure" + , "configure_options" + , "targets" , "prefix" , "options" , "jobs" @@ -37,7 +40,17 @@ , "field_doc": { "project": ["The Make project directory. It should contain a single tree artifact"] - , "target": ["The Make target to build (default: [\"install\"])."] + , "subdir": + [ "The subdirectory that contains the configure and Makefile. Individual" + , "directory components are joined with \"/\"." + ] + , "configure": ["Run ./configure if non-empty."] + , "configure_options": + ["The configure options (the \"--prefix\" option is automatically set."] + , "targets": + [ "The Make targets to build in the specified order" + , "(default: [\"install\"])." + ] , "prefix": [ "The prefix used for the Make target. The path will be made absolute" , "and individual directory components are joined with \"/\". If no" @@ -195,7 +208,10 @@ } } ] - , ["make_target", {"type": "FIELD", "name": "target"}] + , ["subdir", {"type": "FIELD", "name": "subdir"}] + , ["configure", {"type": "FIELD", "name": "configure"}] + , ["configure_options", {"type": "FIELD", "name": "configure_options"}] + , ["make_targets", {"type": "FIELD", "name": "targets"}] , ["make_prefix", {"type": "FIELD", "name": "prefix"}] , ["make_options", {"type": "FIELD", "name": "options"}] , ["make_jobs", {"type": "FIELD", "name": "jobs"}] @@ -255,13 +271,16 @@ } } , "library": - { "doc": ["Library produced by Make build and install."] + { "doc": ["Library produced by Configure and Make build and install."] , "target_fields": ["project", "deps"] , "string_fields": - [ "name" + [ "subdir" + , "name" , "version" , "stage" - , "target" + , "configure" + , "configure_options" + , "targets" , "prefix" , "options" , "jobs" @@ -306,6 +325,10 @@ , "field_doc": { "project": ["The Make project directory. It should contain a single tree artifact"] + , "subdir": + [ "The subdirectory that contains the configure and Makefile. Individual" + , "directory components are joined with \"/\"." + ] , "name": [ "The name of the library (without leading \"lib\" or trailing file name" , "extension), also used as name for pkg-config files." @@ -314,7 +337,13 @@ [ "The library version, used for pkg-config files. Individual version" , "components are joined with \".\"." ] - , "target": ["The Make target to build (default: [\"install\"])."] + , "configure": ["Run ./configure if non-empty."] + , "configure_options": + ["The configure options (the \"--prefix\" option is automatically set."] + , "targets": + [ "The Make targets to build in the specified order" + , "(default: [\"install\"])." + ] , "prefix": [ "The prefix used for the Make target. The path will be made absolute" , "and individual directory components are joined with \"/\". If no" @@ -581,7 +610,10 @@ ] } ] - , ["make_target", {"type": "FIELD", "name": "target"}] + , ["subdir", {"type": "FIELD", "name": "subdir"}] + , ["configure", {"type": "FIELD", "name": "configure"}] + , ["configure_options", {"type": "FIELD", "name": "configure_options"}] + , ["make_targets", {"type": "FIELD", "name": "targets"}] , ["make_prefix", {"type": "FIELD", "name": "prefix"}] , ["make_options", {"type": "FIELD", "name": "options"}] , ["make_jobs", {"type": "FIELD", "name": "jobs"}] @@ -668,7 +700,7 @@ , "$1": {"type": "FIELD", "name": "stage"} } ] - , ["deps-fieldnames", ["deps"]] + , ["deps-fieldnames", ["deps", "defaults"]] ] , "body": {"type": "CALL_EXPRESSION", "name": "prebuilt result"} } |