# HG changeset patch # User Olaf Wintermann # Date 1549289379 -3600 # Node ID 38775db5fdf57769e5aa99bb4bb31adf4c25e37a add existing source diff -r 000000000000 -r 38775db5fdf5 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,2 @@ +^nbactions.xml$ +^target/.*$ diff -r 000000000000 -r 38775db5fdf5 dist/bin/uwproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dist/bin/uwproj Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,5 @@ +#!/bin/sh + +PREFIX=/usr + +java -jar $PREFIX/lib/uwproj/uwproj-0.1.jar "$@" diff -r 000000000000 -r 38775db5fdf5 dist/install.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dist/install.sh Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,11 @@ +#!/bin/sh + +echo "mkdir -p /usr/lib/uwproj" +mkdir -p /usr/lib/uwproj + +echo "cp ../target/uwproj-0.1-jar-with-dependencies.jar /usr/lib/uwproj/uwproj-0.1.jar" +cp ../target/uwproj-0.1-jar-with-dependencies.jar /usr/lib/uwproj/uwproj-0.1.jar + +echo "cp bin/uwproj /usr/bin" +cp bin/uwproj /usr/bin + diff -r 000000000000 -r 38775db5fdf5 pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pom.xml Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,48 @@ + + + 4.0.0 + de.unixwork + uwproj + 0.1 + jar + + UTF-8 + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + + + de.unixwork.uwproj.Main + + + + + jar-with-dependencies + + + + + + + + + + org.apache.velocity + velocity-engine-core + 2.0 + + + \ No newline at end of file diff -r 000000000000 -r 38775db5fdf5 src/main/java/de/unixwork/uwproj/Define.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/unixwork/uwproj/Define.java Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,51 @@ +package de.unixwork.uwproj; + +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author olaf + */ +public class Define { + private String name; + private String value; + + public Define() { + + } + + public Define(String name, String value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String toFlags() { + if(name == null) { + return ""; + } else if(value == null) { + return "-D"+name; + } else { + return "-D"+name + "=" + value; + } + } +} diff -r 000000000000 -r 38775db5fdf5 src/main/java/de/unixwork/uwproj/Dependency.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/unixwork/uwproj/Dependency.java Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,122 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package de.unixwork.uwproj; + +import java.util.LinkedList; +import java.util.List; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * + * @author olaf + */ +public class Dependency { + private String name; + private String platform; + + private List flags = new LinkedList<>(); + private List pkgconfig = new LinkedList<>(); + private List tests = new LinkedList<>(); + + private boolean abortOnError = false; + + private int num = 0; + + public static Dependency parse(Element element) throws Exception { + Dependency d = new Dependency(); + + String name = element.getAttribute("name"); + String platform = element.getAttribute("platform"); + if(name.length() > 0) { + d.setName(name); + } + if(platform.length() > 0) { + d.setPlatform(platform); + } + + NodeList nodes = element.getChildNodes(); + for(int i=0;i getFlags() { + return flags; + } + + public void addFlags(Flags flags) { + this.flags.add(flags); + } + + public List getPkgconfig() { + return pkgconfig; + } + + public void addPkgconfig(PkgConfigPackage pkgconfig) { + this.pkgconfig.add(pkgconfig); + } + + public boolean isAbortOnError() { + return abortOnError; + } + + public void setAbortOnError(boolean abortOnError) { + this.abortOnError = abortOnError; + } + + public int getNum() { + return num; + } + + public void setNum(int num) { + this.num = num; + } + + public List getTests() { + return tests; + } +} diff -r 000000000000 -r 38775db5fdf5 src/main/java/de/unixwork/uwproj/Feature.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/unixwork/uwproj/Feature.java Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,99 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package de.unixwork.uwproj; + +import java.util.LinkedList; +import java.util.List; +import org.w3c.dom.Element; + +/** + * + * @author olaf + */ +public class Feature { + private String name; + private String arg; + private boolean def; + + private TargetData targetData; + + public static Feature parse(Project project, Element e) throws Exception { + Feature feature = new Feature(); + String name = e.getAttribute("name"); + String arg = e.getAttribute("arg"); + String def = e.getAttribute("default"); + + if(name.length() == 0) { + throw new Exception("feature element requires name attribute"); + } + + String ld = def.toLowerCase(); + boolean on = ld.equals("on") || ld.equals("true"); + feature.setName(name); + feature.setDefault(on); + if(arg.length() == 0) { + feature.setArg(name); + } else { + feature.setArg(arg); + } + + feature.setTargetData(TargetData.parse(e)); + project.addFeature(feature); + return feature; + } + + public String getVarName() { + return "FEATURE_"+name.toUpperCase(); + } + + public List getDependencies() { + return getTargetData().getDependencies(); + } + + public List getDefines() { + return getTargetData().getDefines(); + } + + public String getMake() { + return targetData.getMake(); + } + + public boolean hasMake() { + return targetData.getMake().trim().length() > 0; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getArg() { + return arg; + } + + public void setArg(String arg) { + this.arg = arg; + } + + public boolean isDefault() { + return def; + } + + public void setDefault(boolean def) { + this.def = def; + } + + public TargetData getTargetData() { + return targetData; + } + + public void setTargetData(TargetData targetData) { + this.targetData = targetData; + } +} diff -r 000000000000 -r 38775db5fdf5 src/main/java/de/unixwork/uwproj/Flags.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/unixwork/uwproj/Flags.java Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,56 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package de.unixwork.uwproj; + +import org.w3c.dom.Element; + +/** + * + * @author olaf + */ +public class Flags { + private String varName; + private String value; + private boolean exec = false; + + public static Flags parse(Element e) { + Flags f = new Flags(); + f.varName = e.getNodeName().toUpperCase(); + String value = Xml.getContent(e); + f.value = value == null ? "" : value; + + String type = e.getAttribute("type"); + if(type != null && type.equals("exec")) { + f.exec = true; + } + + return f; + } + + public String getVarName() { + return varName; + } + + public void setVarName(String varName) { + this.varName = varName; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public boolean isExec() { + return exec; + } + + public void setExec(boolean exec) { + this.exec = exec; + } +} diff -r 000000000000 -r 38775db5fdf5 src/main/java/de/unixwork/uwproj/Main.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/unixwork/uwproj/Main.java Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,67 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package de.unixwork.uwproj; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.StringWriter; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; +import org.xml.sax.SAXException; + +/** + * + * @author olaf + */ +public class Main { + public static void main(String[] args){ + File f = new File("make/project.xml"); + Project p = null; + try { + p = new Project(f); + } catch (SAXException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } catch (Exception ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } + if(p == null) { + System.exit(1); + } + + VelocityEngine ve = new VelocityEngine(); + Template t = ve.getTemplate("make/configure.vm"); + VelocityContext context = new VelocityContext(); + context.put("targets", p.getTargets()); + context.put("namedDependencies", p.getNamedDependencies()); + context.put("dependencies", p.getDependencies()); + context.put("options", p.getOptions()); + context.put("features", p.getFeatures()); + + int ret = 1; + try { + FileOutputStream fout = new FileOutputStream(new File("configure")); + BufferedWriter out = new BufferedWriter(new OutputStreamWriter(fout)); + t.merge(context, out); + out.close(); + ret = 0; + System.out.println("Out: configure"); + } catch (FileNotFoundException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } catch (IOException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } + System.exit(ret); + } +} diff -r 000000000000 -r 38775db5fdf5 src/main/java/de/unixwork/uwproj/NamedDependency.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/unixwork/uwproj/NamedDependency.java Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,33 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package de.unixwork.uwproj; + +import java.util.List; + +/** + * + * @author olaf + */ +public class NamedDependency { + private String name; + private List subdependencies; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getSubdependencies() { + return subdependencies; + } + + public void setSubdependencies(List subdependency) { + this.subdependencies = subdependency; + } +} diff -r 000000000000 -r 38775db5fdf5 src/main/java/de/unixwork/uwproj/Option.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/unixwork/uwproj/Option.java Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,107 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package de.unixwork.uwproj; + +import java.util.LinkedList; +import java.util.List; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * + * @author olaf + */ +public class Option { + private String arg; + + LinkedList values = new LinkedList<>(); + LinkedList defaults = new LinkedList<>(); + + public static Option parse(Project project, Element element) throws Exception { + Option opt = new Option(); + String arg = element.getAttribute("arg"); + if(arg.length() == 0) { + throw new Exception("Option has no argument string"); + } + opt.setArgument(arg); + + NodeList nodes = element.getChildNodes(); + for(int i=0;i 0) { + def.setPlatform(defPlatform); + } + opt.defaults.add(def); + } + } + } + + return opt; + } + + public String getArgument() { + return arg; + } + + public void setArgument(String arg) { + this.arg = arg; + } + + public String getVarName() { + return "OPT_" + arg.toUpperCase(); + } + + public String getArgValue() { + return "${ARG:"+(3+arg.length())+"}"; + } + + public List getValues() { + return values; + } + + public List getDefaults() { + return defaults; + } + + public String getValueFunc(String value) { + return "checkopt_"+arg+"_"+value; + } + + public String getValuesString() { + if(values.size() == 0) { + return "()"; + } else if(values.size() == 1) { + return values.get(0).getValue(); + } else { + StringBuilder vs = new StringBuilder(); + vs.append('('); + for(int i=0;i getDependencies() { + return targetData.getDependencies(); + } + + public List getDefines() { + return targetData.getDefines(); + } + + public void setTargetData(TargetData data) { + targetData = data; + } + + public String getFunc() { + return option.getValueFunc(value); + } + + public String getMake() { + return targetData.getMake(); + } + + public boolean hasMake() { + return targetData.getMake().trim().length() > 0; + } +} diff -r 000000000000 -r 38775db5fdf5 src/main/java/de/unixwork/uwproj/PkgConfigPackage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/unixwork/uwproj/PkgConfigPackage.java Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,57 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package de.unixwork.uwproj; + +import org.w3c.dom.Element; + +/** + * + * @author olaf + */ +public class PkgConfigPackage { + private String name; + private String atleast; + private String maxVersion; + + public static PkgConfigPackage parse(Element e) throws Exception { + PkgConfigPackage p = new PkgConfigPackage(); + String name = Xml.getContent(e); + if(name != null) { + p.setName(name); + } else { + throw new Exception("pkgconfig element: value required"); + } + return p; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAtleast() { + return atleast; + } + + public void setAtleast(String atleast) { + this.atleast = atleast; + } + + public String getMaxVersion() { + return maxVersion; + } + + public void setMaxVersion(String maxVersion) { + this.maxVersion = maxVersion; + } + + public String getPkgConfigParam() { + return name; + } +} diff -r 000000000000 -r 38775db5fdf5 src/main/java/de/unixwork/uwproj/Project.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/unixwork/uwproj/Project.java Mon Feb 04 15:09:39 2019 +0100 @@ -0,0 +1,140 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package de.unixwork.uwproj; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +/** + * + * @author olaf + */ +public class Project { + private String path; + private Properties properties = new Properties(); + + private HashMap> namedDependencies = new HashMap<>(); + private List dependencies = new LinkedList<>(); + private List targets = new LinkedList<>(); + private List