--- a/src/main/java/de/unixwork/uwproj/PkgConfigPackage.java Sun Sep 10 13:12:54 2023 +0200 +++ b/src/main/java/de/unixwork/uwproj/PkgConfigPackage.java Sun Sep 10 14:29:20 2023 +0200 @@ -2,9 +2,15 @@ import org.w3c.dom.Element; +import java.util.ArrayList; +import java.util.stream.Collectors; + +import static de.unixwork.uwproj.Util.isNotNullOrBlank; + public class PkgConfigPackage { private String name; - private String atleast; + private String atLeastVersion; + private String exactVersion; private String maxVersion; public static PkgConfigPackage parse(Element e) throws Exception { @@ -15,6 +21,9 @@ } else { p.setName(name); } + p.setAtLeastVersion(e.getAttribute("atleast")); + p.setExactVersion(e.getAttribute("exact")); + p.setMaxVersion(e.getAttribute("max")); return p; } @@ -26,12 +35,12 @@ this.name = name; } - public String getAtleast() { - return atleast; + public String getAtLeastVersion() { + return atLeastVersion; } - public void setAtleast(String atleast) { - this.atleast = atleast; + public void setAtLeastVersion(String atLeastVersion) { + this.atLeastVersion = atLeastVersion; } public String getMaxVersion() { @@ -42,7 +51,36 @@ this.maxVersion = maxVersion; } - public String getPkgConfigParam() { - return name; + public String getExactVersion() { + return exactVersion; + } + + public void setExactVersion(String exactVersion) { + this.exactVersion = exactVersion; + } + + public String getPkgConfigTestQuery() { + // pkg-config is a more broken piece of software than we thought + // it is not possible to combine any flags + // e.g. --atleast-version and --max-version together will return true, + // even when the max-version is violated + // or other example: combining any version flag with --cflags or + // --libs does not print the flags + // therefore we have to execute multiple query first, and obtain the flags later + + final var commands = new ArrayList<String>(); + if (isNotNullOrBlank(atLeastVersion)) { + commands.add("$PKG_CONFIG --atleast-version="+atLeastVersion+" "+name); + } + if (isNotNullOrBlank(exactVersion)) { + commands.add("$PKG_CONFIG --exact-version="+exactVersion+" "+name); + } + if (isNotNullOrBlank(maxVersion)) { + commands.add("$PKG_CONFIG --max-version="+maxVersion+" "+name); + } + if (commands.isEmpty()) { + commands.add("$PKG_CONFIG "+name); + } + return String.join(" && ", commands); } }