help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GNU Make parser and dependency generation.


From: Pierre Lindenbaum
Subject: Re: GNU Make parser and dependency generation.
Date: Fri, 18 Mar 2016 17:21:23 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.5.1

My problem statement is, I need to get all the rules information from Makefile 
in a separate data structure which will be latter used by our program.
I don't need to execute the project and create any executables. I just need 
Target, Dependency, Command information which will involve parsing Makefile, 
expanding all variables and predefined Makefile patterns.
I wrote a simple java-based parser that parse the output of 'make -dn ' , the output is a XML file with target,command,dependencies,...:


https://github.com/lindenb/j4make


I hope it helps.
Pierre


        <?xml version="1.0" encoding="UTF-8"?>
        <make>
          <target name="all">
            <prerequisites>
              <prerequisite ref="j4make"/>
            </prerequisites>
            <shell/>
          </target>
<target name="lib/org/slf4j/slf4j-api/1.7.13/slf4j-api-1.7.13.jar">
            <prerequisites/>
            <shell>
<p>mkdir -p lib/org/slf4j/slf4j-api/1.7.13/ &amp;&amp; wget -O "lib/org/slf4j/slf4j-api/1.7.13/slf4j-api-1.7.13.jar" "http://central.maven.org/maven2/org/slf4j/slf4j-api/1.7.13/slf4j-api-1.7.13.jar";</p>
            </shell>
          </target>
<target name="lib/commons-codec/commons-codec/1.10/commons-codec-1.10.jar">
            <prerequisites/>
            <shell>
<p>mkdir -p lib/commons-codec/commons-codec/1.10/ &amp;&amp; wget -O "lib/commons-codec/commons-codec/1.10/commons-codec-1.10.jar" "http://central.maven.org/maven2/commons-codec/commons-codec/1.10/commons-codec-1.10.jar";</p>
            </shell>
          </target>
          <target name="Makefile">
            <prerequisites/>
            <shell/>
          </target>
          <target name="j4make">
            <prerequisites>
<prerequisite ref="/home/lindenb/src/j4make/src/main/java/com/github/lindenb/j4make/J4Make.java"/> <prerequisite ref="lib/commons-codec/commons-codec/1.10/commons-codec-1.10.jar"/> <prerequisite ref="lib/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar"/> <prerequisite ref="lib/org/slf4j/slf4j-api/1.7.13/slf4j-api-1.7.13.jar"/>
            </prerequisites>
            <shell>
<p>mkdir -p /home/lindenb/src/j4make/_tmp/META-INF /home/lindenb/src/j4make/src/main/generated-sources/java/com/github/lindenb/j4make/ /home/lindenb/src/j4make/dist</p>
              <p>#compile</p>
<p>javac -d /home/lindenb/src/j4make/_tmp -g -classpath "lib/commons-codec/commons-codec/1.10/commons-codec-1.10.jar:lib/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar:lib/org/slf4j/slf4j-api/1.7.13/slf4j-api-1.7.13.jar" -sourcepath /home/lindenb/src/j4make/src/main/java:/home/lindenb/src/j4make/src/main/generated-sources/java /home/lindenb/src/j4make/src/main/java/com/github/lindenb/j4make/J4Make.java</p>
              <p>#create META-INF/MANIFEST.MF</p>
<p>echo "Manifest-Version: 1.0" &gt; /home/lindenb/src/j4make/_tmp/META-INF/MANIFEST.MF</p> <p>echo "Main-Class: com.github.lindenb.j4make.J4Make" &gt;&gt; /home/lindenb/src/j4make/_tmp/META-INF/MANIFEST.MF</p> <p>echo "Class-Path: /home/lindenb/src/j4make/lib/commons-codec/commons-codec/1.10/commons-codec-1.10.jar /home/lindenb/src/j4make/lib/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar /home/lindenb/src/j4make/lib/org/slf4j/slf4j-api/1.7.13/slf4j-api-1.7.13.jar /home/lindenb/src/j4make/dist/j4make.jar" | fold -w 71 | awk '{printf("%s%s\n",(NR==1?"": " "),$0);}' &gt;&gt; /home/lindenb/src/j4make/_tmp/META-INF/MANIFEST.MF</p> <p>echo -n "Git-Hash: " &gt;&gt; /home/lindenb/src/j4make/_tmp/META-INF/MANIFEST.MF</p> <p>cat /home/lindenb/src/j4make/.git/refs/heads/master &gt;&gt; /home/lindenb/src/j4make/_tmp/META-INF/MANIFEST.MF </p> <p>echo -n "Compile-Date: " &gt;&gt; /home/lindenb/src/j4make/_tmp/META-INF/MANIFEST.MF</p> <p>date +%Y-%m-%d:%H-%m-%S &gt;&gt; /home/lindenb/src/j4make/_tmp/META-INF/MANIFEST.MF</p>
              <p>#create jar</p>
<p>jar cfm /home/lindenb/src/j4make/dist/j4make.jar /home/lindenb/src/j4make/_tmp/META-INF/MANIFEST.MF -C /home/lindenb/src/j4make/_tmp .</p>
              <p>#create bash executable</p>
<p>echo '#!/bin/bash' &gt; /home/lindenb/src/j4make/dist/j4make</p> <p>echo 'java -Dfile.encoding=UTF8 -Xmx500m -cp "/home/lindenb/src/j4make/lib/commons-codec/commons-codec/1.10/commons-codec-1.10.jar:/home/lindenb/src/j4make/lib/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar:/home/lindenb/src/j4make/lib/org/slf4j/slf4j-api/1.7.13/slf4j-api-1.7.13.jar:/home/lindenb/src/j4make/dist/j4make.jar" com.github.lindenb.j4make.J4Make $*' &gt;&gt; /home/lindenb/src/j4make/dist/j4make</p>
              <p>chmod  ugo+rx /home/lindenb/src/j4make/dist/j4make</p>
              <p>#cleanup</p>
              <p>rm -rf /home/lindenb/src/j4make/_tmp</p>
            </shell>
          </target>
          <target name="&lt;ROOT&gt;">
            <prerequisites>
              <prerequisite ref="Makefile"/>
              <prerequisite ref="all"/>
            </prerequisites>
            <shell/>
          </target>
<target name="lib/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar">
            <prerequisites/>
            <shell>
<p>mkdir -p lib/commons-cli/commons-cli/1.3.1/ &amp;&amp; wget -O "lib/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar" "http://central.maven.org/maven2/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar";</p>
            </shell>
          </target>
<target name="/home/lindenb/src/j4make/src/main/java/com/github/lindenb/j4make/J4Make.java">
            <prerequisites/>
            <shell/>
          </target>
        </make>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]