For college, I have to use Java. However, I do not want to use an IDE. I like vim.
So I'm trying to create a Makefile to build my java projects. My requirements are :
No hardcoding of classes. The Makefile shall find all
.java
files in thesrc
directory and any subdirectories, and compile the resulting classes to theclasses
directory.Multiple
mains
: Files containingmain
functions shall have an executable.jar
file built with a correspondingMANIFEST.MF
. Listing them explicitly is acceptable, although I'm pretty sure something could be done withgrep
here to find them automatically (but I suck atgrep
)A source jar for the whole project shall be created, containing unaltered
.java
files and noMANIFEST.MF
or other extraneous files.
My best attempt so far (currently broken) follows :
include gmsltargets := Client Server# Folders binDir := ./binclsDir := ./classessrcDir := ./srctestDir := ./test# Flagsversion := 11# FilesmainSrc := $(targets:%=$(srcDir)/tp1/%.java)src := $(shell find $(srcDir) -name *\.java -type f)cls := $(src:%.java=%.class)# Rules# Baseall : $(targets)again : clean allclasses : $(cls)# For debuginfo: $(info mainSrc : $(mainSrc)) $(info srcJar : $(srcJar)) $(info exeJar : $(exeJar)) $(info src : $(src)) $(info cls : $(cls))# Executables$(targets): $(cls) $(shell cd $(srcDir)) $(eval mainCls := $(shell find . -name *$@\.java -type f) ) $(info mainCls = $(mainCls)) jar --verbose --create --file=$(call lc,$@)-exe.jar --main-class=tp1/$@ -C $(clsDir) .# Source$(srcJar) : $(cls) jar --verbose --create --file=$@ --no-manifest -C $(srcDir) .# Classes$(cls): javac --release $(version) --source-path $(srcDir) -d $(clsDir) $(mainSrc)# Cleanupclean: -rm $(targets) -cd $(clsDir) && rm -rf ./*