Makefile:不重新编译未更新的文件(单独的目录) [英] Makefile : do not recompile files not updated (separate directories)
问题描述
我想知道makefile怎么可能只编译带有更改的类(Java,Scala).
I wonder how it's possible for a makefile, to compile only classes (Java, Scala) with changes.
我的.scala
在src
目录中.当我编译时,输出(.class
)进入bin
目录.
My .scala
are in the src
directory. And when I compile, the output (.class
) go to the bin
directory.
在一个项目中,当您有约50个类时,每次都编译所有类太长了.
In a project, when you have ~50 classes it's too long to compile all classes each time.
您知道如何解决我的问题吗?
Do you know how to solve my problem ?
我尝试过Maven,但似乎也有同样的问题.
I tried maven but it seems to have the same problem.
我的makefile(用于Scala):
My makefile (for Scala) :
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的创建日期.这是我的文件: https://gist.github.com/Dnomyar/d01d886731ccc88d3c63 >
EDIT : I've found a solution : compare date of creation of .java and .bin. Here is my 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*"`
推荐答案
我找到了一个解决方案 https: //gist.github.com/Dnomyar/d01d886731ccc88d3c63 这有点难看,但似乎可以正常工作.
I've found a solution https://gist.github.com/Dnomyar/d01d886731ccc88d3c63 It's a little bit ugly but it seems to work.
这篇关于Makefile:不重新编译未更新的文件(单独的目录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!