Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > 03a94d8f913fd31140f11f39714fa79d > files > 54

ant-antlr3-20110110-8.mga3.noarch.rpm

<project name="polydiff" default="dist" basedir=".">
    <description>
        Build file for Anltr polydiff example.
    </description>

    <property name="project.name" value="polydiff" />

    <!-- program version -->
    <property name="version" value="1.1" />

    <!-- set global properties for this build -->
    <property name="build" location="."/>

    <!-- directory layout for this build:

         .
         +- src
         +- grammar
         +- classes
         +- dist
              +- javadoc

         Move the grammar files into the grammar directory and
         Main.java into the src directory before starting the build.
         The following properties reflect this hierarchy.
    -->

    <!-- the src directory in this example -->
    <property name="src" location="src"/>

    <!-- name of the package -->
    <property name="package" value=""/>

    <!-- where to write/find token files -->
    <property name="token.lib" location="${src}/${package}" />

    <!-- where to find the grammar files
         in this example the grammar file is placed in the source
         directory. Some people might prefer to locate it in a
         separate directory, e.g. grammar directory.
         To do so, just change

         location="${src}" into
         location="grammar"

         if you like.
    -->
    <property name="grammar" location="${src}"/>

    <!-- where to write compiled source -->
    <property name="classes" location="classes"/>

    <!-- distribution directory -->
    <property name="dist" location="dist" />

    <!-- where to write java doc files -->
    <property name="doc" location="${dist}/javadoc"/>

    <!-- Inquire environment variables -->
    <property environment="envList"/>

    <!-- Get environment variable ANTLR_HOME -->
    <property name="antlrHome" value="${envList.ANTLR_HOME}"/>

    <!-- antlr options -->
    <property name="report" value="true" />
    <property name="multithreaded" value="true" />
    <property name="debug" value="false" />

    <!-- A convenience macro which invokes antlr
         Be aware that JVM arguments can be specified via the jvmarg directive
    -->
    <macrodef name="antlr3">
        <attribute name="grammar.name"/>
        <attribute name="package" default="${package}"/>
        <sequential>
            <echo message="antlr ${grammar}/@{grammar.name}" />
            <antlr:ant-antlr3 xmlns:antlr="antlib:org/apache/tools/ant/antlr"
                          target="${grammar}/@{grammar.name}"
                          outputdirectory="${src}/@{package}"
                          libdirectory="${src}/@{package}"
                          multithreaded="${multithreaded}"
                          report="${report}"
                          debug="${debug}">
                <classpath>
                    <path refid="antlr.path"/>
                </classpath>
                <jvmarg value="-Xmx512M"/>
            </antlr:ant-antlr3>
        </sequential>
    </macrodef>

    <target name="init" depends="antlr_home">
        <!-- Create the time stamp -->
        <tstamp />
        <!-- Create the build directory structure used by compile -->
        <mkdir dir="${grammar}" />
        <mkdir dir="${src}/${package}" />
        <mkdir dir="${classes}/${package}" />
        <mkdir dir="${classes}/META-INF" />
        <mkdir dir="${dist}/javadoc" />

        <!-- Copy all files into the source directory -->
        <copy todir="${src}" includeEmptyDirs="false">
            <fileset dir=".">
                <patternset id="sourcefiles">
                    <include name="*.java"/>
                    <include name="*.g"/>
                </patternset>
            </fileset>
        </copy>
    </target>

    <!-- Inquire environment variables -->
    <property environment="envList"/>

    <!-- Get environment variable ANTLR_HOME -->
    <property name="antlrLibDir" value="${envList.ANTLR_HOME}"/>

    <!-- Check if ANTLR_HOME environment variable is set -->
    <condition property="antlrLibDir.isset">
        <isset property="envList.ANTLR_HOME"/>
    </condition>

    <target name="antlr_home">
        <fail message="ANTLR_HOME environment variable not defined">
            <condition>
                <not>
                    <isset property="antlrLibDir.isset"/>
                </not>
            </condition>
        </fail>
        
        <whichresource property="antlr.jar.location" class="org.antlr.Tool" classpathref="antlr.path"/>
        <fail message="Antlr library not found via ANTLR_HOME='${antlrLibDir}'">
            <condition>
                <not>
                    <isset property="antlr.jar.location"/>
                </not>
            </condition>
        </fail>
        <echo>ANTLR3 found via environment variable ANTLR_HOME: ${antlr.jar.location}</echo>
    </target>
    
    <!-- Use wildcards in pattern definition -->
    <!-- to be independent of antlr versions -->
    <patternset id="antlr.libs">
        <include name="antlr-*.jar" />
    </patternset>
	
    <!-- Looking for archives in ANTLR_HOME -->
    <path id="antlr.path">
        <fileset dir="${antlrLibDir}" casesensitive="yes">
            <patternset refid="antlr.libs" />
        </fileset>
    </path>

    <!-- Antlr is called here -->
    <!-- The antlr3 macro is doing the work -->
    <!-- The dependency among grammars has to be described -->
    <!-- The hierarchy in this example is:

         Poly.g
         - PolyDifferentiator.g
            - Simplifier.g
               - PolyPrinter.g

         The dependency is described from bottom to top:

         PolyPrinter.g depends from
         - Simplifier.g depends from
            - PolyDifferntiator.g depends from
               - Poly.g

         Note that Antlr is only invoked when necessary, e.g.
         changes in PolyDifferentiator.g do not result in
         Poly.g being recompiled. Only Simplifier.g and
         PolyPrinter.g might be affected.
         Call "ant" without parameters twice and you will
         notice that no compilation by Antlr is done.
     -->

    <target name="PolyPrinter" depends="Simplifier">
        <antlr3 grammar.name="PolyPrinter.g"/>
    </target>
    <target name="Simplifier" depends="PolyDifferentiator">
        <antlr3 grammar.name="Simplifier.g"/>
    </target>
    <target name="PolyDifferentiator" depends="Poly">
        <antlr3 grammar.name="PolyDifferentiator.g"/>
    </target>
    <target name="Poly">
        <antlr3 grammar.name="Poly.g"/>
    </target>

    <target name="compile" depends="init, PolyPrinter" description="compile">
        <!-- Compile the java code from ${src} into ${classes} -->
        <javac debug="true" srcdir="${src}" destdir="${classes}"
               listfiles="Yes" deprecation="Yes" includeantruntime="false">
            <compilerarg value="-Xlint:unchecked"/>
            <classpath>
                <path refid="antlr.path"/>
            </classpath>
        </javac>
    </target>

    <target name="manifest">
        <manifest file="${classes}/META-INF/MANIFEST.MF">
            <attribute name="Main-Class" value="Main" />
        </manifest>
    </target>

    <target name="dist" depends="compile, manifest"
            description="generate for distribution">
        <jar jarfile="${dist}/${project.name}.jar" basedir="${classes}"
             manifest="${classes}/META-INF/MANIFEST.MF"/>
    </target>

    <target name="doc" depends="init, compile" description="generate documentation">
        <javadoc destdir="${doc}"
                 author="true"
                 version="true"
                 use="true"
                 windowtitle="${project.name}"
                 source="${src}"
                 Protected="All"
                 Private="All"
                 Public="All"
                 linksource="yes"
                 breakiterator="Yes">
            <fileset dir="${src}" casesensitive="yes">
                <include name="**/*.java" />
            </fileset>
            <classpath>
                <path refid="antlr.path"/>
            </classpath>
        </javadoc>
    </target>

    <target name="run" depends="dist">
        <echo message="Differentiate 'input' and write it to 'output'"/>
        <java classname="Main"
              input="input"
              output="output"
              fork="true"
              failonerror="true"
              maxmemory="128m">
            <classpath>
                <pathelement location="${dist}/${project.name}.jar"/>
                <path refid="antlr.path"/>
            </classpath>
        </java>
    </target>

    <target name="clean" description="clean up">
        <delete>
            <fileset dir="${src}" includes="**/*.class,**/*.tokens" />
            <fileset dir="${classes}" />
            <fileset dir="${dist}" includes="**/*.jar" />
            <fileset dir="${doc}" />
        </delete>
    </target>

    <target name="all" depends="init, clean, compile, dist, doc, run" description="do all"/>

</project>