add configureable make variables

Sat, 03 Aug 2019 13:46:43 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 03 Aug 2019 13:46:43 +0200
changeset 7
686991ae6e2f
parent 6
d4363f69fd97
child 8
82cd9f1d94cb

add configureable make variables

src/main/java/de/unixwork/uwproj/ConfigVar.java file | annotate | diff | comparison | revisions
src/main/java/de/unixwork/uwproj/Main.java file | annotate | diff | comparison | revisions
src/main/java/de/unixwork/uwproj/Project.java file | annotate | diff | comparison | revisions
test/config.mk file | annotate | diff | comparison | revisions
test/configure file | annotate | diff | comparison | revisions
test/make/configure.vm file | annotate | diff | comparison | revisions
test/make/project.xml file | annotate | diff | comparison | revisions
test/make/toolchain.sh file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/unixwork/uwproj/ConfigVar.java	Sat Aug 03 13:46:43 2019 +0200
@@ -0,0 +1,59 @@
+/*
+ * 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 ConfigVar {
+    String name;
+    String value;
+    private boolean exec = false;
+    
+    public static ConfigVar parse(Element e) {
+        ConfigVar var = new ConfigVar();
+        
+        String name = e.getAttribute("name");
+        if(name == null || name.length() == 0) {
+            System.err.println("<var>-element: name attribute required");
+            return null;
+        }
+        var.name = name;
+        
+        String value = Xml.getContent(e);
+        var.value = value == null ? "" : value;
+        
+        String type = e.getAttribute("type");
+        if(type != null && type.equals("exec")) {
+            var.exec = true;
+        }
+        
+        return var;
+    }
+    
+    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 boolean isExec() {
+        return exec;
+    }
+}
--- a/src/main/java/de/unixwork/uwproj/Main.java	Sat Aug 03 11:20:29 2019 +0200
+++ b/src/main/java/de/unixwork/uwproj/Main.java	Sat Aug 03 13:46:43 2019 +0200
@@ -48,6 +48,8 @@
         context.put("dependencies", p.getDependencies());
         context.put("options", p.getOptions());
         context.put("features", p.getFeatures());
+        context.put("project", p);
+        context.put("vars", p.getVars());
         
         int ret = 1;
         try {
--- a/src/main/java/de/unixwork/uwproj/Project.java	Sat Aug 03 11:20:29 2019 +0200
+++ b/src/main/java/de/unixwork/uwproj/Project.java	Sat Aug 03 13:46:43 2019 +0200
@@ -19,6 +19,7 @@
 import javax.xml.parsers.ParserConfigurationException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
 
@@ -36,6 +37,9 @@
     private List<Option> options = new LinkedList<>();
     private List<Feature> features = new LinkedList<>();
     
+    private HashMap<String,ConfigVar> configVars = new HashMap<>();
+    private List<ConfigVar> configVarsList = new LinkedList<>();
+    
     public Project(File file) throws ParserConfigurationException, SAXException, IOException, Exception {
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         factory.setNamespaceAware(true);
@@ -47,6 +51,24 @@
         NodeList target_nodes = root.getElementsByTagName("target");
         NodeList property_nodes = root.getElementsByTagName("property");
         
+        NodeList config_nodes = root.getElementsByTagName("config");
+        for(int i=0;i<config_nodes.getLength();i++) {
+            Element p = (Element)config_nodes.item(i);
+            NodeList cfgs = p.getChildNodes();
+            for(int c=0;c<cfgs.getLength();c++) {
+                Node node = cfgs.item(c);
+                if (node.getNodeType() == Node.ELEMENT_NODE) {
+                    if(node.getNodeName().equals("var")) {
+                        ConfigVar var = ConfigVar.parse((Element)node);
+                        if(var != null) {
+                            configVarsList.add(var);
+                            configVars.put(var.getName(), var);
+                        }
+                    }
+                }
+            }
+        }
+        
         for(int i=0;i<dependency_nodes.getLength();i++) {
             addDependency(Dependency.parse((Element)dependency_nodes.item(i)));
         }
@@ -137,4 +159,12 @@
     public List<Feature> getFeatures() {
         return features;
     }
+    
+    public List<ConfigVar> getVars() {
+        return configVarsList;
+    }
+    
+    public boolean hasVar(String varName) {
+        return configVars.containsKey(varName);
+    }
 }
--- a/test/config.mk	Sat Aug 03 11:20:29 2019 +0200
+++ b/test/config.mk	Sat Aug 03 13:46:43 2019 +0200
@@ -1,6 +1,27 @@
 #
 # config.mk generated by configure
 #
+
+# general vars
+HOST=xxx
+INSTALL_DIR=yyy
+PREFIX=/export/home/olaf/Projekte/uwproj/test
+
+EPREFIX=/export/home/olaf/Projekte/uwproj/test
+
+BINDIR=/export/home/olaf/Projekte/uwproj/test/bin
+SBINDIR=/export/home/olaf/Projekte/uwproj/test/sbin
+LIBDIR=/export/home/olaf/Projekte/uwproj/test/lib
+LIBEXECDIR=/export/home/olaf/Projekte/uwproj/test/libexec
+DATADIR=/export/home/olaf/Projekte/uwproj/test/share
+SYSCONFDIR=/export/home/olaf/Projekte/uwproj/test/etc
+SHAREDSTATEDIR=/export/home/olaf/Projekte/uwproj/test/com
+LOCALSTATEDIR=/export/home/olaf/Projekte/uwproj/test/var
+INCLUDEDIR=/export/home/olaf/Projekte/uwproj/test/include
+INFODIR=/export/home/olaf/Projekte/uwproj/test/info
+MANDIR=/export/home/olaf/Projekte/uwproj/test/man
+
+# toolchain
 CC = cc
 LD = cc
 include $(BUILD_ROOT)make/gcc.mk
--- a/test/configure	Sat Aug 03 11:20:29 2019 +0200
+++ b/test/configure	Sat Aug 03 13:46:43 2019 +0200
@@ -1,6 +1,9 @@
 #!/bin/sh
 
-PREFIX=/usr
+HOST=xxx
+INSTALL_DIR=yyy
+PREFIX=`pwd`
+
 EPREFIX=$PREFIX
 
 BINDIR=
@@ -108,10 +111,10 @@
 	SBINDIR=$EPREFIX/sbin
 fi
 if [ -z $LIBDIR ]; then
-	LIBDIRDIR=$EPREFIX/lib
+	LIBDIR=$EPREFIX/lib
 fi
 if [ -z $LIBEXEC ]; then
-	LIBExECDIR=$EPREFIX/libexec
+	LIBEXECDIR=$EPREFIX/libexec
 fi
 if [ -z $DATADIR ]; then
 	DATADIR=$PREFIX/share
@@ -189,6 +192,26 @@
 #
 # config.mk generated by configure
 #
+
+# general vars
+HOST=$HOST
+INSTALL_DIR=$INSTALL_DIR
+PREFIX=$PREFIX
+
+EPREFIX=$EPREFIX
+
+BINDIR=$BINDIR
+SBINDIR=$SBINDIR
+LIBDIR=$LIBDIR
+LIBEXECDIR=$LIBEXECDIR
+DATADIR=$DATADIR
+SYSCONFDIR=$SYSCONFDIR
+SHAREDSTATEDIR=$SHAREDSTATEDIR
+LOCALSTATEDIR=$LOCALSTATEDIR
+INCLUDEDIR=$INCLUDEDIR
+INFODIR=$INFODIR
+MANDIR=$MANDIR
+
 __EOF__
 
 echo > $TEMP_DIR/make.mk
--- a/test/make/configure.vm	Sat Aug 03 11:20:29 2019 +0200
+++ b/test/make/configure.vm	Sat Aug 03 13:46:43 2019 +0200
@@ -1,19 +1,53 @@
 #!/bin/sh
 
-PREFIX=/usr
-EPREFIX=$PREFIX
+#foreach( $var in $vars )
+#if( $var.exec )
+${var.name}=`${var.value}`
+#else
+${var.name}=${var.value}
+#end
+#end
 
+#if ( ! $project.hasVar("PREFIX") )
+PREFIX=/usr
+#end
+#if ( ! $project.hasVar("EPREFIX") )
+EPREFIX=$PREFIX
+#end
+
+#if ( ! $project.hasVar("BINDIR") )
 BINDIR=
+#end
+#if ( ! $project.hasVar("SBINDIR") )
 SBINDIR=
+#end
+#if ( ! $project.hasVar("LIBDIR") )
 LIBDIR=
+#end
+#if ( ! $project.hasVar("LIBEXECDIR") )
 LIBEXECDIR=
+#end
+#if ( ! $project.hasVar("DATADIR") )
 DATADIR=
+#end
+#if ( ! $project.hasVar("SYSCONFDIR") )
 SYSCONFDIR=
+#end
+#if ( ! $project.hasVar("SHAREDSTATEDIR") )
 SHAREDSTATEDIR=
+#end
+#if ( ! $project.hasVar("LOCALSTATEDIR") )
 LOCALSTATEDIR=
+#end
+#if ( ! $project.hasVar("INCLUDEDIR") )
 INCLUDEDIR=
+#end
+#if ( ! $project.hasVar("INFODIR") )
 INFODIR=
+#end
+#if ( ! $project.hasVar("MANDIR") )
 MANDIR=
+#end
 
 OS=`uname -s`
 OS_VERSION=`uname -r`
@@ -135,10 +169,10 @@
 	SBINDIR=$EPREFIX/sbin
 fi
 if [ -z $LIBDIR ]; then
-	LIBDIRDIR=$EPREFIX/lib
+	LIBDIR=$EPREFIX/lib
 fi
 if [ -z $LIBEXEC ]; then
-	LIBExECDIR=$EPREFIX/libexec
+	LIBEXECDIR=$EPREFIX/libexec
 fi
 if [ -z $DATADIR ]; then
 	DATADIR=$PREFIX/share
@@ -216,6 +250,53 @@
 #
 # config.mk generated by configure
 #
+
+# general vars
+#foreach( $var in $vars )
+${var.name}=$${var.name}
+#end
+
+#if ( ! $project.hasVar("PREFIX") )
+PREFIX=$PREFIX
+#end
+#if ( ! $project.hasVar("EPREFIX") )
+EPREFIX=$EPREFIX
+#end
+
+#if ( ! $project.hasVar("BINDIR") )
+BINDIR=$BINDIR
+#end
+#if ( ! $project.hasVar("SBINDIR") )
+SBINDIR=$SBINDIR
+#end
+#if ( ! $project.hasVar("LIBDIR") )
+LIBDIR=$LIBDIR
+#end
+#if ( ! $project.hasVar("LIBEXECDIR") )
+LIBEXECDIR=$LIBEXECDIR
+#end
+#if ( ! $project.hasVar("DATADIR") )
+DATADIR=$DATADIR
+#end
+#if ( ! $project.hasVar("SYSCONFDIR") )
+SYSCONFDIR=$SYSCONFDIR
+#end
+#if ( ! $project.hasVar("SHAREDSTATEDIR") )
+SHAREDSTATEDIR=$SHAREDSTATEDIR
+#end
+#if ( ! $project.hasVar("LOCALSTATEDIR") )
+LOCALSTATEDIR=$LOCALSTATEDIR
+#end
+#if ( ! $project.hasVar("INCLUDEDIR") )
+INCLUDEDIR=$INCLUDEDIR
+#end
+#if ( ! $project.hasVar("INFODIR") )
+INFODIR=$INFODIR
+#end
+#if ( ! $project.hasVar("MANDIR") )
+MANDIR=$MANDIR
+#end
+
 __EOF__
 
 echo > $TEMP_DIR/make.mk
--- a/test/make/project.xml	Sat Aug 03 11:20:29 2019 +0200
+++ b/test/make/project.xml	Sat Aug 03 13:46:43 2019 +0200
@@ -1,5 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project>
+	<!-- makefile config -->
+	<config>
+		<var name="HOST">xxx</var>
+		<var name="INSTALL_DIR">yyy</var>
+		<var name="PREFIX" type="exec">pwd</var>
+	</config>
+	
 	<!-- platform specific settings -->
 	<dependency platform="linux">
 		<cflags>-DLINUX</cflags>
--- a/test/make/toolchain.sh	Sat Aug 03 11:20:29 2019 +0200
+++ b/test/make/toolchain.sh	Sat Aug 03 13:46:43 2019 +0200
@@ -59,7 +59,10 @@
 if [ -z TOOLCHAIN_NAME ]; then
     TOOLCHAIN_DETECTION_ERROR="error"
 else
-    echo "CC = ${TOOLCHAIN_CC}" >> $TEMP_DIR/config.mk
+    cat >> $TEMP_DIR/config.mk << __EOF__
+# toolchain
+__EOF__
+	echo "CC = ${TOOLCHAIN_CC}" >> $TEMP_DIR/config.mk
     echo "LD = ${TOOLCHAIN_LD}" >> $TEMP_DIR/config.mk
     
     if [ -e "make/${TOOLCHAIN_NAME}.mk" ]; then 

mercurial