# This is NOT a proper Makefile for a scala project,
# just a quick'n'dirty way to demo and play with the samples!

# How to use:
#
#   The tarball comes with jar files for scala 0.11.
#   You need to get other jars for other versions of scala,
#   and change the definitions just below.
#
#   Then look for XXX in this Makefile for the various things
#   to try.
#
#   The source code is in src/main/scala and src/test/scala.
#

# Library jar files
#
# You only need each jar for testing the corresponding tool!
# You will need other versions if you're not using scala 2.11.
# You can find these files online:
#   https://github.com/HairyFotr/linter
#   https://www.scalacheck.org/download.html
#   http://www.scalatest.org/download
#   http://www.scalastyle.org/command-line.html

STYLE_JAR=scalastyle_2.11-0.6.0-batch.jar
SCHECK=scalacheck_2.11-1.12.5.jar
STEST=scalatest_2.11-2.2.4.jar
LINTER_JAR=linter_2.11-0.1-SNAPSHOT.jar

# You should not need to change anything below this line

SCALAC=scalac -d classes

all: classes
	$(SCALAC) src/main/scala/*.scala

classes/Dices.class: classes src/main/scala/dice.scala
	$(SCALAC) src/main/scala/*.scala

classes:
	mkdir -p classes

clean:
	rm -f *.class classes/*.class

# XXX LINTER XXX

# Run scalac on various files with more and more static analysis:
#  - make OPTIONS="" bugs
#  - make LINTER="" bugs
#  - make bugs
# Then the same with bugs_dices and bugs_prog2.

LINTER=-Xplugin:$(LINTER_JAR)
OPTIONS=-Xlint -Ywarn-inaccessible -Ywarn-nullary-unit -Ywarn-value-discard $(LINTER)

bugs:
	$(SCALAC) -d classes $(OPTIONS) src/main/scala/bugs.scala

bugs_dices:
	$(SCALAC) -d classes $(OPTIONS) src/main/scala/dice.scala

bugs_prog2:
	$(SCALAC) -d classes $(OPTIONS) ~/teach/gl/code_and_test/guillaume/src/*scala

# XXX SCALASTYLE XXX

# Run 'make style' to see the sort of stuff a style checker checks.
# Note that the tool uses an XML config file that can be tweaked to
# your tastes.

STYLE_CONFIG=scalastyle_config.xml

style: $(STYLE_JAR) $(STYLE_CONFIG)
	java -jar $(STYLE_JAR) --config $(STYLE_CONFIG) src/main/scala

# XXX SCALA CHECK XXX

# Run "make check" to see scalacheck in action on a toy example,
# then "make dicecheck" to use it on the dice example.

check: classes
	$(SCALAC) -cp $(SCHECK) src/test/scala/check.scala
	scala -cp classes:$(SCHECK) StringSpecification

dicecheck: classes/Dices.class
	$(SCALAC) -cp classes:$(SCHECK) src/test/scala/dicecheck.scala
	scala -cp classes:$(SCHECK) Dice56Specification

# XXX SCALA TEST XXX

# Run "make test" to run scalatest unit tests from
# src/test/scala/dice.scala.

test: classes/Dices.class
	$(SCALAC) -cp classes:$(STEST) src/test/scala/dice.scala
	scala -cp classes:$(STEST) org.scalatest.run Dice34Spec
