As part of my data collection, I have to run multiple kinds of coverage processing on multiple Java projects. Below is my main Makefile
intented only for gmake. Portability is not a requirement for me (for this project), but DRY and following make best practices are. Please comment on my code, and if there is any way to make this better.
.PHONY: checkout all clobber clean $(checkout.all)
.SECONDARY: $(addprefix projects/,$(names))
root:=$(CURDIR)
names=$(shell cat etc/projects.txt)
checkout.all=$(addprefix checkout-,$(names))
clean.all=$(addprefix clean-,$(names))
testgen.types=original randoop tpalus
all:
@echo use 'make <type>-<project>'
@echo projects = $(names)
@echo types = $(testgen.types)
checkout: $(checkout.all)
@echo $@ done.
checkout-%: projects/%/pom.xml
@echo $@ done.
projects build: ; mkdir -p $@
projects/%/pom.xml: | projects build
cd projects && $(root)/bin/checkout $*
touch $@
clean: $(clean.all)
@echo $@ done.
clean-%: | projects/%/pom.xml
cd projects/$* && git clean -xfd && git reset --hard
@echo $@ done.
clobber-%:
cd projects && rm -rf $*
#-----------------------------------------------------------------
root:=$(CURDIR)
define testgen =
$1 : $(addprefix $(1)-,$(names))
@echo $$(@) done.
$1-% : projects/%/.$(1).done
@echo $$(@) done.
%/.$1.done : | %/pom.xml
echo $$(MAKE) -C $$(*) root=$$(root) $(1)
endef
$(foreach var,$(testgen.types),$(eval $(call testgen,$(var))))
Some clarification about the intended purpose of this project. I am doing an analysis on a large number of projects from github. My method of action is to clone each project, run multiple tests on them. Before running any project, I do a git clean to make sure that the artifacts of previous tests are not present in the project directories. The types
of tests and projects names
vary frequently, and hence I have kept them outside the main Makefile.