2009年12月1日星期二

Makefile sample for java

今日開始Compiler project,需要面對一堆.java
於是搞了個for java的Makefile,雖然之前一直都有用Makefile
但今次這個sample寫得足夠簡單和通用,很方便的就可以拿去其他Project裏用


BIN = bin/
JFLAGS = -g -d ./$(BIN)
JC = javac

#
# CLASSES is a macro consisting of 4 words (one for each java source file)
#

CLASSES = \
TAM/Disassembler.java \
TAM/Instruction.java \
TAM/Interpreter.java \
TAM/Machine.java \
Triangle/Compiler.java \
Triangle/ErrorReporter.java \
Triangle/StdEnvironment.java \
Triangle/SyntacticAnalyzer/Parser.java \
Triangle/SyntacticAnalyzer/Scanner.java \
Triangle/SyntacticAnalyzer/SourceFile.java \
Triangle/SyntacticAnalyzer/SourcePosition.java \
Triangle/SyntacticAnalyzer/SyntaxError.java \
Triangle/SyntacticAnalyzer/Token.java \
Triangle/AbstractSyntaxTrees/ErrorTypeDenoter.java \
Triangle/AbstractSyntaxTrees/EmptyExpression.java \
Triangle/AbstractSyntaxTrees/EmptyFormalParameterSequence.java \
Triangle/AbstractSyntaxTrees/ActualParameter.java \
Triangle/AbstractSyntaxTrees/ActualParameterSequence.java \
Triangle/AbstractSyntaxTrees/AnyTypeDenoter.java \
Triangle/AbstractSyntaxTrees/ArrayAggregate.java \
Triangle/AbstractSyntaxTrees/ArrayExpression.java \
Triangle/AbstractSyntaxTrees/ArrayTypeDenoter.java \
Triangle/AbstractSyntaxTrees/AssignCommand.java \
Triangle/AbstractSyntaxTrees/AST.java \
Triangle/AbstractSyntaxTrees/BinaryExpression.java \
Triangle/AbstractSyntaxTrees/BinaryOperatorDeclaration.java \
Triangle/AbstractSyntaxTrees/BoolTypeDenoter.java \
Triangle/AbstractSyntaxTrees/CallCommand.java \
Triangle/AbstractSyntaxTrees/CallExpression.java \
Triangle/AbstractSyntaxTrees/CharacterExpression.java \
Triangle/AbstractSyntaxTrees/CharacterLiteral.java \
Triangle/AbstractSyntaxTrees/Vname.java \
Triangle/AbstractSyntaxTrees/CharTypeDenoter.java \
Triangle/AbstractSyntaxTrees/Command.java \
Triangle/AbstractSyntaxTrees/ConstActualParameter.java \
Triangle/AbstractSyntaxTrees/ConstDeclaration.java \
Triangle/AbstractSyntaxTrees/ConstFormalParameter.java \
Triangle/AbstractSyntaxTrees/Declaration.java \
Triangle/AbstractSyntaxTrees/DotVname.java \
Triangle/AbstractSyntaxTrees/EmptyActualParameterSequence.java \
Triangle/AbstractSyntaxTrees/EmptyCommand.java \
Triangle/AbstractSyntaxTrees/Expression.java \
Triangle/AbstractSyntaxTrees/FieldTypeDenoter.java \
Triangle/AbstractSyntaxTrees/FormalParameter.java \
Triangle/AbstractSyntaxTrees/FormalParameterSequence.java \
Triangle/AbstractSyntaxTrees/FuncActualParameter.java \
Triangle/AbstractSyntaxTrees/FuncFormalParameter.java \
Triangle/AbstractSyntaxTrees/Identifier.java \
Triangle/AbstractSyntaxTrees/IfCommand.java \
Triangle/AbstractSyntaxTrees/IfExpression.java \
Triangle/AbstractSyntaxTrees/IntegerExpression.java \
Triangle/AbstractSyntaxTrees/IntegerLiteral.java \
Triangle/AbstractSyntaxTrees/IntTypeDenoter.java \
Triangle/AbstractSyntaxTrees/LetCommand.java \
Triangle/AbstractSyntaxTrees/LetExpression.java \
Triangle/AbstractSyntaxTrees/MultipleActualParameterSequence.java \
Triangle/AbstractSyntaxTrees/MultipleArrayAggregate.java \
Triangle/AbstractSyntaxTrees/MultipleFieldTypeDenoter.java \
Triangle/AbstractSyntaxTrees/MultipleFormalParameterSequence.java \
Triangle/AbstractSyntaxTrees/MultipleRecordAggregate.java \
Triangle/AbstractSyntaxTrees/Operator.java \
Triangle/AbstractSyntaxTrees/ProcActualParameter.java \
Triangle/AbstractSyntaxTrees/ProcDeclaration.java \
Triangle/AbstractSyntaxTrees/ProcFormalParameter.java \
Triangle/AbstractSyntaxTrees/Program.java \
Triangle/AbstractSyntaxTrees/RecordAggregate.java \
Triangle/AbstractSyntaxTrees/RecordExpression.java \
Triangle/AbstractSyntaxTrees/RecordTypeDenoter.java \
Triangle/AbstractSyntaxTrees/SequentialCommand.java \
Triangle/AbstractSyntaxTrees/SequentialDeclaration.java \
Triangle/AbstractSyntaxTrees/SimpleTypeDenoter.java \
Triangle/AbstractSyntaxTrees/SimpleVname.java \
Triangle/AbstractSyntaxTrees/SingleActualParameterSequence.java \
Triangle/AbstractSyntaxTrees/SingleArrayAggregate.java \
Triangle/AbstractSyntaxTrees/SingleFieldTypeDenoter.java \
Triangle/AbstractSyntaxTrees/SingleFormalParameterSequence.java \
Triangle/AbstractSyntaxTrees/SingleRecordAggregate.java \
Triangle/AbstractSyntaxTrees/SubscriptVname.java \
Triangle/AbstractSyntaxTrees/Terminal.java \
Triangle/AbstractSyntaxTrees/TypeDeclaration.java \
Triangle/AbstractSyntaxTrees/TypeDenoter.java \
Triangle/AbstractSyntaxTrees/UnaryExpression.java \
Triangle/AbstractSyntaxTrees/UnaryOperatorDeclaration.java \
Triangle/AbstractSyntaxTrees/VarActualParameter.java \
Triangle/AbstractSyntaxTrees/VarDeclaration.java \
Triangle/AbstractSyntaxTrees/VarFormalParameter.java \
Triangle/AbstractSyntaxTrees/Visitor.java \
Triangle/AbstractSyntaxTrees/VnameExpression.java \
Triangle/AbstractSyntaxTrees/WhileCommand.java \
Triangle/AbstractSyntaxTrees/FuncDeclaration.java \
Triangle/TreeDrawer/Drawer.java \
Triangle/TreeDrawer/DrawerFrame.java \
Triangle/TreeDrawer/DrawerPanel.java \
Triangle/TreeDrawer/DrawingTree.java \
Triangle/TreeDrawer/LayoutVisitor.java \
Triangle/TreeDrawer/Polygon.java \
Triangle/TreeDrawer/Polyline.java \
Triangle/CodeGenerator/Encoder.java \
Triangle/CodeGenerator/EqualityRoutine.java \
Triangle/CodeGenerator/Field.java \
Triangle/CodeGenerator/Frame.java \
Triangle/CodeGenerator/KnownAddress.java \
Triangle/CodeGenerator/KnownRoutine.java \
Triangle/CodeGenerator/KnownValue.java \
Triangle/CodeGenerator/ObjectAddress.java \
Triangle/CodeGenerator/PrimitiveRoutine.java \
Triangle/CodeGenerator/RuntimeEntity.java \
Triangle/CodeGenerator/TypeRepresentation.java \
Triangle/CodeGenerator/UnknownAddress.java \
Triangle/CodeGenerator/UnknownRoutine.java \
Triangle/CodeGenerator/UnknownValue.java \
Triangle/ContextualAnalyzer/Checker.java \
Triangle/ContextualAnalyzer/IdentificationTable.java \
Triangle/ContextualAnalyzer/IdEntry.java



# the default make target entry
all: classes

classes: $(CLASSES:%.java=$(BIN)%.class)
$(BIN)%.class: %.java
$(JC) $(JFLAGS) $<

clean:
@find ./$(BIN) -iname '*.class' -delete


只要把上面的classes填上所有.java
然後打make就會把所有.class都放到bin下面,目錄結构和.java的都一樣
因為makefile本身的功能會檢測依賴,所以.class比.java新的話就不會compile
而且所有.class都是和.java分開擺放的,好看又易修改
一句make clean就會把所有.class消滅
好,繼續工作
發佈留言

熱門文章