Charj: overhaul and simplify/improve build system
authorAaron Becker <akbecker@gmail.com>
Wed, 6 Oct 2010 00:26:49 +0000 (19:26 -0500)
committerAaron Becker <akbecker@gmail.com>
Wed, 6 Oct 2010 00:26:49 +0000 (19:26 -0500)
Ditched the lousy ant task for antlr compilation in favor of make rules.
Advantages include: parallel compilation of grammars, no more
unnecessary recompilation of grammars, and automatic detection of new
grammar files. Whew, should have just done it in make in the first
place. The ant build file is still used for compiling java source,
generating jars, and creating javadocs.

src/langs/charj/Makefile
src/langs/charj/build.xml

index 2437ecb0ed20e6f0c8bb2940965e4a8fc6b606e7..2adbee7e8b462b9e42762a3ea049e188f9a412b3 100644 (file)
@@ -1,38 +1,41 @@
-ANT=ant -lib lib/ant-antlr3.jar
-# Ant does the actual building, just invoke it
-.DEFAULT_GOAL:dist
-dist:
+
+ANT := ant -lib lib/ant-antlr3.jar
+CLASSPATH := lib/antlr-3.2.jar:lib/JSAP-2.1.jar
+SRCDIR := src/charj/translator
+BUILDDIR := build/src/charj/translator
+ANTLR := java -classpath $(CLASSPATH) org.antlr.Tool -o $(BUILDDIR) -lib $(BUILDDIR)
+ANTLRFLAGS := -Xmultithreaded
+
+SRC_GRAMMARS := $(wildcard $(SRCDIR)/*.g)
+BUILD_GRAMMARS := $(subst $(SRCDIR),$(BUILDDIR),$(SRC_GRAMMARS:.g=.d))
+
+.PHONY: all build compile grammars clean doc
+all: build grammars
        $(ANT) dist
-compile:
+
+build:
+       @echo "\ninit:"
+       @mkdir -p $(BUILDDIR)
+       @cp -p $(SRCDIR)/* $(BUILDDIR)
+       @mkdir -p build/classes
+       @mkdir -p build/classes/META-INF
+       @mkdir -p build/lib
+       @mkdir -p docs
+       @echo "\nantlr:"
+
+compile: $(wildcard $(BUILDDIR)/*.java)
        $(ANT) compile
+
 clean:
        $(ANT) clean
+
 doc:
        $(ANT) doc
-all:
-       $(ANT) all
-
-# The lousy antlrv3 ant task won't give proper output from antlr errors, so
-# use these horrible direct invocations instead
-.PHONY: debug debug-charj debug-semantics debug-emitter
-debug: debug-charj debug-semantics debug-emitter
-
-CLASSPATH = lib/antlr-3.2.jar:lib/JSAP-2.1.jar
-debug-charj:
-       cp src/charj/translator/Charj.g build/src/charj/translator/Charj.g
-       java -classpath $(CLASSPATH) org.antlr.Tool \
-           -o build/src/charj/translator -lib build/src/charj/translator \
-           build/src/charj/translator/Charj.g
-debug-semantics:
-       cp src/charj/translator/CharjSemantics.g build/src/charj/translator/CharjSemantics.g    
-       java -classpath $(CLASSPATH) org.antlr.Tool \
-           -o build/src/charj/translator -lib build/src/charj/translator \
-           build/src/charj/translator/CharjSemantics.g
-debug-emitter:
-       cp src/charj/translator/CharjEmitter.g build/src/charj/translator/CharjEmitter.g
-       java -classpath $(CLASSPATH) org.antlr.Tool -o build/src/charj/translator \
-           -lib build/src/charj/translator build/src/charj/translator/CharjEmitter.g
-
-# For any unrecognized rules, try to compile a test program with that name
-%:
-       ./bin/charjc --debug --verbose --AST --stdout --translate-only tests/$@/$@.cj
+
+grammars: build $(BUILD_GRAMMARS)
+
+$(BUILDDIR)/%.d: $(SRCDIR)/%.g $(SRCDIR)/Charj.g
+       @echo "\n    [antlr] $(<F)"
+       $(ANTLR) $(ANTLRFLAGS) $(BUILDDIR)/$(<F)
+       @touch $@
+
index 653311127b287c2fcdf8620f1e5e843dcaca2ac2..3e49553dd7d65a2c349be88afd3c84a52c2257d8 100644 (file)
     </path>
     <property name="classpath" value="project.class.path.3.2"/>
 
-    <!-- antlr options -->
-    <property name="profile" value="false" />
-    <property name="report" value="false" />
-    <property name="multithreaded" value="true" />
-    <property name="debug" value="false" />
-
-    <target name="init">
-        <tstamp />
-        <!-- Create the build directory structure used by compile -->
-        <copy todir="${buildsrc}">
-            <fileset dir="${src}"/>
-        </copy>
-        <mkdir dir="${classes}" />
-        <mkdir dir="${classes}/META-INF" />
-        <mkdir dir="${buildlib}" />
-        <mkdir dir="${doc}" />
-    </target>
-
-    <macrodef name="antlr3">
-        <attribute name="grammar.name"/>
-        <attribute name="grammar.path"/>
-        <sequential>
-            <echo message="antlr @{grammar.name}" />
-            <antlr:antlr3 xmlns:antlr="antlib:org/apache/tools/ant/antlr"
-                target="@{grammar.path}/@{grammar.name}"
-                outputdirectory="@{grammar.path}"
-                libdirectory="@{grammar.path}"
-                multithreaded="${multithreaded}"
-                report="${report}"
-                debug="${debug}"
-                profile="${profile}">
-                <jvmarg value="-Xmx512M"/>
-                <classpath refid="${classpath}"/>
-            </antlr:antlr3>
-        </sequential>
-    </macrodef>
-
-    <target name="Charj" depends="init">
-        <antlr3 grammar.name="Charj.g"
-            grammar.path="${buildsrc}/charj/translator"/>
-    </target>
-
-    <target name="CharjASTModifier" depends="Charj">
-        <antlr3 grammar.name="CharjASTModifier.g"
-            grammar.path="${buildsrc}/charj/translator"/>
-    </target>
-
-    <target name="SymbolDefiner" depends="Charj">
-        <antlr3 grammar.name="SymbolDefiner.g"
-            grammar.path="${buildsrc}/charj/translator"/>
-    </target>
-    
-    <target name="SymbolResolver" depends="Charj">
-        <antlr3 grammar.name="SymbolResolver.g"
-            grammar.path="${buildsrc}/charj/translator"/>
-    </target>
-
-    <target name="InitPUPCollector" depends="Charj">
-        <antlr3 grammar.name="InitPUPCollector.g"
-            grammar.path="${buildsrc}/charj/translator"/>
-    </target>
-
-    <target name="CharjASTModifier2" depends="Charj">
-        <antlr3 grammar.name="CharjASTModifier2.g"
-            grammar.path="${buildsrc}/charj/translator"/>
-    </target>
-
-    <target name="CharjSemantics" depends="Charj">
-        <antlr3 grammar.name="CharjSemantics.g"
-            grammar.path="${buildsrc}/charj/translator"/>
-    </target>
-    
-    <target name="CharjEmitter" depends="Charj">
-        <antlr3 grammar.name="CharjEmitter.g"
-            grammar.path="${buildsrc}/charj/translator"/>
-    </target>
-
     <target name="compile"
-        depends="CharjASTModifier, SymbolDefiner, SymbolResolver, InitPUPCollector, CharjASTModifier2, CharjSemantics, CharjEmitter"
         description="compile">
         <javac debug="true" srcdir="${buildsrc}" destdir="${classes}"
                target="1.5" listfiles="Yes" deprecation="Yes">