2015-01-15 38 views
0

我想知道如何使用makefile編譯僅包含具有更改的類(Java,Scala)。Makefile:請勿重新編譯未更新的文件(單獨的目錄)

我的.scala位於src目錄中。當我編譯時,輸出(.class)轉到bin目錄。

在一個項目中,當你有50個類時,每次編譯所有類都太長了。

你知道如何解決我的問題嗎?

我試過maven,但它似乎有同樣的問題。

我的makefile(斯卡拉):

SRC = src 
SOURCES = $(shell find . -name *.scala) 
S = scala 
SC = scalac 
TARGET = bin 
CP = bin 

run: compile 
    @echo ":: Executing..." 
    @$(S) -cp $(CP) -encoding utf8 App -feature 


compile: $(SOURCES:.scala=.class) 

%.class: %.scala 
    clear 
    @echo ":: Compiling..." 
    @echo "Compiling $*.scala.." 
    @$(SC) -sourcepath $(SRC) -cp $(CP) -d $(TARGET) -encoding utf8 $*.scala 

編輯:我已經找到了解決辦法:建立比較的.java和.bin文件的日期。這是我的makefile:https://gist.github.com/Dnomyar/d01d886731ccc88d3c63

SRC = src 
SOURCES = $(shell find ./src/ -name *.java) 
S = java 
SC = javac 
TARGET = bin 
CP = bin 
VPATH=bin 

run: compile 
@echo ":: Executing..." 
@$(S) -cp $(CP) App 

compile: $(SOURCES:.%.java=.%.class) 

%.class: %.java 
clear 
@echo ":: Compiling..." 
@echo "Compiling $*.java.." 
@if [ $(shell stat -c %Y $*.java) -lt $(shell stat -c %Y $(shell echo "$*.class" | sed 's/src/bin/g')) ]; then echo ; else $(SC) -sourcepath $(SRC) -cp $(CP) -d $(TARGET) -encoding utf-8 $*.java; fi 




clean: 
@rm -R bin/* 

# Pour supprimer les fichier .fuse* créés par sublime text 
fuse: 
@rm `find -name "*fuse*"` 
+3

總之:不要使用Makefiles for Java或Scala。您將永遠無法正確處理您的依賴項:.scala可能會有多個.class。 .class可能依賴於其他的.class文件。使用Maven或SBT。 –

+0

感謝您的回答。你知道Maren的清晰教程嗎?在Apache網站上,目前尚不清楚。他們沒有解釋如何運行一個項目。 – Dnomyar

回答

0

你可以指定化妝到搜索使用VPATH變量的相關性。對於您的情況,您可以指定VPATH=bin,其中make比較bin文件夾下文件的時間戳。

例子:

VPATH= obj 
all: hello 
     @echo "Makeing - all" 
     touch all 
hello: 
     @echo "Making - hello" 
     touch obj/hello 

輸出:

[email protected]:~/learning/makefiles/VPATH$ ls 
Makefile obj 
[email protected]:~/learning/makefiles/VPATH$ make 
Making - hello 
touch obj/hello 
Makeing - all 
touch all 
[email protected]:~/learning/makefiles/VPATH$ ls 
all Makefile obj 
[email protected]:~/learning/makefiles/VPATH$ make 
make: 'all' is up to date. 
[email protected]:~/learning/makefiles/VPATH$ touch obj/hello 
[email protected]:~/learning/makefiles/VPATH$ make 
Makeing - all 
touch all 
[email protected]:~/learning/makefiles/VPATH$ 
+0

它不適用於我的makefile,但我找到了另一種解決方案。謝謝。 – Dnomyar

+0

發佈您的答案並接受它,它會幫助他人 –

相關問題