summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rules/CC/EXPRESSIONS132
-rw-r--r--rules/CC/RULES103
-rw-r--r--rules/EXPRESSIONS16
3 files changed, 249 insertions, 2 deletions
diff --git a/rules/CC/EXPRESSIONS b/rules/CC/EXPRESSIONS
index 57418d6..c1c11f3 100644
--- a/rules/CC/EXPRESSIONS
+++ b/rules/CC/EXPRESSIONS
@@ -333,6 +333,114 @@
}
}
}
+, "pkg-config":
+ { "vars":
+ [ "pkg-name"
+ , "pkg-prefix"
+ , "pkg-version"
+ , "pkg-cflags"
+ , "pkg-ldflags"
+ , "pkg-libs"
+ , "flat-libs"
+ ]
+ , "imports": {"contains": ["", "contains"]}
+ , "expression":
+ { "type": "singleton_map"
+ , "key":
+ {"type": "join", "$1": [{"type": "var", "name": "pkg-name"}, ".pc"]}
+ , "value":
+ { "type": "BLOB"
+ , "data":
+ { "type": "join"
+ , "separator": "\n"
+ , "$1":
+ [ { "type": "join"
+ , "$1":
+ [ "prefix="
+ , {"type": "var", "name": "pkg-prefix", "default": "/"}
+ ]
+ }
+ , "libdir=${prefix}/lib"
+ , "includedir=${prefix}/include"
+ , { "type": "join"
+ , "$1": ["Name: ", {"type": "var", "name": "pkg-name"}]
+ }
+ , { "type": "join"
+ , "$1":
+ [ "Version: "
+ , {"type": "var", "name": "pkg-version", "default": "unknown"}
+ ]
+ }
+ , { "type": "join"
+ , "$1":
+ [ "Description: Pkg-config for "
+ , {"type": "var", "name": "pkg-name"}
+ , ", generated by JustBuild"
+ ]
+ }
+ , "URL: unknown"
+ , { "type": "join"
+ , "separator": " "
+ , "$1":
+ { "type": "++"
+ , "$1":
+ [ ["Cflags:", "-I${includedir}"]
+ , {"type": "var", "name": "pkg-cflags"}
+ ]
+ }
+ }
+ , { "type": "join"
+ , "separator": " "
+ , "$1":
+ { "type": "++"
+ , "$1":
+ [ ["Libs:"]
+ , { "type": "if"
+ , "cond": {"type": "var", "name": "flat-libs"}
+ , "then": ["-L${libdir}"]
+ }
+ , { "type": "let*"
+ , "bindings":
+ [ [ "list"
+ , { "type": "keys"
+ , "$1": {"type": "var", "name": "pkg-libs"}
+ }
+ ]
+ ]
+ , "body":
+ { "type": "foreach"
+ , "var": "item"
+ , "range": {"type": "var", "name": "pkg-ldflags"}
+ , "body":
+ { "type": "if"
+ , "cond": {"type": "CALL_EXPRESSION", "name": "contains"}
+ , "then":
+ { "type": "join"
+ , "$1":
+ { "type": "if"
+ , "cond": {"type": "var", "name": "flat-libs"}
+ , "then":
+ [ "-l:"
+ , { "type": "basename"
+ , "$1": {"type": "var", "name": "item"}
+ }
+ ]
+ , "else":
+ ["${libdir}/", {"type": "var", "name": "item"}]
+ }
+ }
+ , "else": {"type": "var", "name": "item"}
+ }
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
, "objects":
{ "vars":
[ "COMPILER"
@@ -684,6 +792,7 @@
, "ldflags"
, "private-ldflags"
, "stage"
+ , "pkg-name"
, "extra-provides"
, "public-fieldnames"
, "private-fieldnames"
@@ -748,6 +857,12 @@
}
}
]
+ , [ "package"
+ , { "type": "singleton_map"
+ , "key": "name"
+ , "value": {"type": "var", "name": "pkg-name"}
+ }
+ ]
]
, "body":
{ "type": "RESULT"
@@ -764,6 +879,7 @@
, "link-args"
, "run-libs"
, "run-libs-args"
+ , "package"
]
}
, { "type": "var"
@@ -941,6 +1057,7 @@
, "ldflags"
, "private-ldflags"
, "soversion"
+ , "pkg-name"
, "extra-provides"
, "deps-transition"
, "public-fieldnames"
@@ -1023,6 +1140,20 @@
}
}
]
+ , [ "package"
+ , { "type": "let*"
+ , "bindings":
+ [ ["name", {"type": "var", "name": "pkg-name"}]
+ , [ "version"
+ , { "type": "join"
+ , "separator": "."
+ , "$1": {"type": "var", "name": "soversion"}
+ }
+ ]
+ ]
+ , "body": {"type": "env", "vars": ["name", "version"]}
+ }
+ ]
]
, "body":
{ "type": "RESULT"
@@ -1039,6 +1170,7 @@
, "link-args"
, "run-libs"
, "run-libs-args"
+ , "package"
]
}
, { "type": "var"
diff --git a/rules/CC/RULES b/rules/CC/RULES
index 00f3da6..91fcf3d 100644
--- a/rules/CC/RULES
+++ b/rules/CC/RULES
@@ -142,6 +142,7 @@
, "ldflags"
, "private-ldflags"
, "soversion"
+ , "pkg-name"
]
, "config_fields": ["shared"]
, "config_vars":
@@ -222,6 +223,10 @@
[ "The SOVERSION for shared libraries. Individual version components are"
, "joined with \".\"."
]
+ , "pkg-name":
+ [ "Name to use for pkg-config files. If this field is empty, the field"
+ , "\"name\" is used instead."
+ ]
}
, "config_doc":
{ "CC":
@@ -393,6 +398,14 @@
, ["ldflags", {"type": "FIELD", "name": "ldflags"}]
, ["private-ldflags", {"type": "FIELD", "name": "private-ldflags"}]
, ["soversion", {"type": "FIELD", "name": "soversion"}]
+ , [ "pkg-name"
+ , { "type": "if"
+ , "cond": {"type": "FIELD", "name": "pkg-name"}
+ , "then":
+ {"type": "join", "$1": {"type": "FIELD", "name": "pkg-name"}}
+ , "else": {"type": "var", "name": "name"}
+ }
+ ]
, [ "deps-transition"
, {"type": "CALL_EXPRESSION", "name": "fPIC transition"}
]
@@ -570,10 +583,12 @@
{ "doc":
[ "Install target's artifacts with transitive dependencies. Depending on"
, "the target, artifacts and dependencies will be installed to"
- , "subdirectories \"bin\", \"include\", and \"lib\"."
+ , "subdirectories \"bin\", \"include\", and \"lib\". For library targets,"
+ , "a pkg-config file is generated and provided in \"share/pkgconfig\"."
]
+ , "config_vars": ["PREFIX"]
, "target_fields": ["targets"]
- , "string_fields": ["flat-libs"]
+ , "string_fields": ["flat-libs", "prefix"]
, "imports":
{ "compile-deps": "compile-deps"
, "compile-args-deps": "compile-args-deps"
@@ -581,6 +596,7 @@
, "link-args-deps": "link-args-deps"
, "run-libs-deps": "run-libs-deps"
, "run-libs-args-deps": "run-libs-args-deps"
+ , "pkg-config": "pkg-config"
}
, "field_doc":
{ "targets": ["Targets to install artifacts from."]
@@ -589,6 +605,19 @@
, "conflicts may occur if any of the (transitive) libraries happen to"
, "have the same base name."
]
+ , "prefix":
+ [ "The prefix used for pkg-config files. The path will be made absolute"
+ , "and individual directory components are joined with \"/\". If no"
+ , "prefix is specified, the value from the config variable \"PREFIX\" is"
+ , "taken, with the default value being \"/\"."
+ ]
+ }
+ , "config_doc":
+ { "PREFIX":
+ [ "The absolute path that is used as prefix inside generated pkg-config"
+ , "files. The default value for this variable is \"/\". This variable"
+ , "is ignored if the field \"prefix\" is set."
+ ]
}
, "artifacts_doc":
["Installed artifacts in subdirectories (\"bin\"/\"include\"/\"lib\")."]
@@ -684,6 +713,72 @@
}
}
]
+ , [ "pkg-name"
+ , { "type": "lookup"
+ , "key": "name"
+ , "map": {"type": "var", "name": "package"}
+ }
+ ]
+ , [ "pkg-config"
+ , { "type": "if"
+ , "cond": {"type": "var", "name": "pkg-name"}
+ , "then":
+ { "type": "let*"
+ , "bindings":
+ [ [ "pkg-prefix"
+ , { "type": "if"
+ , "cond": {"type": "FIELD", "name": "prefix"}
+ , "then":
+ { "type": "join"
+ , "separator": "/"
+ , "$1":
+ { "type": "++"
+ , "$1":
+ [[""], {"type": "FIELD", "name": "prefix"}]
+ }
+ }
+ , "else":
+ {"type": "var", "name": "PREFIX", "default": "/"}
+ }
+ ]
+ , [ "pkg-version"
+ , { "type": "lookup"
+ , "key": "version"
+ , "map": {"type": "var", "name": "package"}
+ }
+ ]
+ , [ "pkg-cflags"
+ , { "type": "DEP_PROVIDES"
+ , "dep": {"type": "var", "name": "target"}
+ , "provider": "compile-args"
+ , "default": []
+ }
+ ]
+ , [ "pkg-ldflags"
+ , { "type": "++"
+ , "$1":
+ [ { "type": "DEP_PROVIDES"
+ , "dep": {"type": "var", "name": "target"}
+ , "provider": "link-args"
+ , "default": []
+ }
+ , { "type": "DEP_PROVIDES"
+ , "dep": {"type": "var", "name": "target"}
+ , "provider": "run-libs-args"
+ , "default": []
+ }
+ ]
+ }
+ ]
+ , ["pkg-libs", {"type": "var", "name": "libraries"}]
+ , ["flat-libs", {"type": "FIELD", "name": "flat-libs"}]
+ ]
+ , "body":
+ {"type": "CALL_EXPRESSION", "name": "pkg-config"}
+ }
+ , "else": {"type": "empty_map"}
+ }
+ ]
]
, "body":
{ "type": "map_union"
@@ -704,6 +799,10 @@
, "msg": "install libraries may not overlap"
, "$1": {"type": "var", "name": "libraries"}
}
+ , { "type": "to_subdir"
+ , "subdir": "share/pkgconfig"
+ , "$1": {"type": "var", "name": "pkg-config"}
+ }
]
}
}
diff --git a/rules/EXPRESSIONS b/rules/EXPRESSIONS
index b974026..55976f4 100644
--- a/rules/EXPRESSIONS
+++ b/rules/EXPRESSIONS
@@ -226,4 +226,20 @@
}
}
}
+, "contains":
+ { "vars": ["list", "item"]
+ , "expression":
+ { "type": "or"
+ , "$1":
+ { "type": "foreach"
+ , "var": "entry"
+ , "range": {"type": "var", "name": "list"}
+ , "body":
+ { "type": "=="
+ , "$1": {"type": "var", "name": "entry"}
+ , "$2": {"type": "var", "name": "item"}
+ }
+ }
+ }
+ }
}