-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
127 lines (94 loc) · 4.35 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
##
## Copyright (c) 2018-2023 Stéphane Micheloud
##
## Licensed under the MIT License.
##
##############################################################################
include ../Makefile.inc
SOURCE_DIR = src
TARGET_DIR = target
CLASSES_DIR = $(TARGET_DIR)/classes
SCALAC_FLAGS = -deprecation -feature
SCALA_FLAGS = -classpath "$(CLASSES_DIR)"
##############################################################################
## main rules
SOURCES = $(shell $(FIND) "$(SOURCE_DIR)/main/scala" -type f -name "*.scala")
TARGET = $(TARGET_DIR)/.latest-build
OPTS_FILE = $(TARGET_DIR)/scalac_opts.txt
SOURCES_FILE = $(TARGET_DIR)/scalac_sources.txt
MAIN_CLASS = Planet
MAIN_ARGS ?= 1
all: build
build: $(TARGET)
$(TARGET): $(SOURCES)
[ -d "$(CLASSES_DIR)" ] || "$(MKDIR)" -p "$(CLASSES_DIR)"
@$(ECHO) $(SCALAC_FLAGS) -d "$(CLASSES_DIR)" > "$(OPTS_FILE)"
@$(ECHO) $(SOURCES) > "$(SOURCES_FILE)"
"$(SCALAC)" "@$(OPTS_FILE)" "@$(SOURCES_FILE)"
@$(TOUCH) "$(TARGET)"
clean:
"$(RM)" -rf "$(TARGET_DIR)"
run: build
"$(SCALA)" $(SCALA_FLAGS) $(MAIN_CLASS) $(MAIN_ARGS)
help:
@$(ECHO) "Usage: make all|build|clean|doc|help|lint|run|test"
@$(ECHO) ""
@$(ECHO) " Subcommands:"
@$(ECHO) " all alias for build"
@$(ECHO) " build compile Java/Scala source files"
@$(ECHO) " clean delete generated files"
@$(ECHO) " doc generate HTML documentation"
@$(ECHO) " help print this help message"
@$(ECHO) " lint analyze Scala source files with Scalafmt"
@$(ECHO) " run execute main program \"$(MAIN_CLASS)\""
@$(ECHO) " test execute unit tests with JUnit"
##############################################################################
## doc rules
DOC_TARGET_DIR = $(TARGET_DIR)/docs
DOC_SOURCES = $(shell [ -d "$(CLASSES_DIR)" ] && $(FIND) "$(CLASSES_DIR)" -type f -name "*.tasty" 2>/dev/null)
DOC_TARGET = $(DOC_TARGET_DIR)/.latest-build
PROJECT_NAME ?= $(shell basename "$(CURDIR)")
PROJECT_URL ?= https://github.com/$(USERNAME)/dotty-examples
PROJECT_VERSION ?= 1.0.0
DOC_OPTS_FILE = $(TARGET_DIR)/scaladoc_opts.txt
DOC_SOURCES_FILE = $(TARGET_DIR)/scaladoc_sources.txt
$(DOC_TARGET): $(TARGET) $(DOC_SOURCES)
[ -d "$(DOC_TARGET_DIR)" ] || "$(MKDIR)" -p "$(DOC_TARGET_DIR)"
@$(ECHO) -siteroot "$(DOC_TARGET_DIR)" -d "$(DOC_TARGET_DIR)" -project "$(PROJECT_NAME)" -project-version "$(PROJECT_VERSION)" > "$(DOC_OPTS_FILE)"
@$(ECHO) $(DOC_SOURCES) > "$(DOC_SOURCES_FILE)"
"$(SCALADOC)" "@$(DOC_OPTS_FILE)" "@$(DOC_SOURCES_FILE)"
@$(TOUCH) "$(DOC_TARGET)"
doc: build $(DOC_TARGET)
##############################################################################
## lint rules
LINT_SOURCES = $(shell $(FIND) "$(SOURCE_DIR)" -type f -name "*.scala")
LINT_TARGET = $(TARGET_DIR)/.latest-lint
SCALAFMT_CONFIG_FILE = $(shell dirname $(CURDIR))/.scalafmt.conf
SCALAFMT_OPTS = --test --config "$(SCALAFMT_CONFIG_FILE)"
lint: $(LINT_TARGET)
$(LINT_TARGET): $(LINT_SOURCES)
[ -d "$(TARGET_DIR)" ] || "$(MKDIR)" -p "$(TARGET_DIR)"
"$(SCALAFMT)" $(SCALAFMT_OPTS) $(SOURCE_DIR)
@$(TOUCH) "$(LINT_TARGET)"
##############################################################################
## test rules
TEST_SOURCES = $(shell $(FIND) "$(SOURCE_DIR)/test" -type f -name "*.scala")
TEST_CLASSES_DIR = $(TARGET_DIR)/test-classes
TEST_TARGET = $(TARGET_DIR)/.latest-test-build
TEST_OPTS_FILE = $(TARGET_DIR)/scalac_test_opts.txt
TEST_SOURCES_FILE = $(TARGET_DIR)/scalac_test_sources.txt
TEST_MAIN_CLASS = $(MAIN_CLASS)JUnitTest
TEST_CPATH = $(SCALA_LIB_JAR)$(PSEP)$(SCALA3_LIB_JAR)$(PSEP)$(HAMCREST_JAR)$(PSEP)$(JUNIT_JAR)$(PSEP)$(JUNIT_INTF_JAR)$(PSEP)$(SCALATEST_JAR)$(PSEP)$(SCALACTIC_JAR)$(PSEP)$(SPECS2_CORE_JAR)$(PSEP)$(SPECS2_JUNIT_JAR)$(PSEP)$(SPECS2_MATCHER_JAR)$(PSEP)$(CLASSES_DIR)$(PSEP)$(TEST_CLASSES_DIR)
$(TEST_TARGET): $(TEST_SOURCES)
[ -d "$(TEST_CLASSES_DIR)" ] || "$(MKDIR)" -p "$(TEST_CLASSES_DIR)"
@$(ECHO) $(SCALAC_FLAGS) -classpath "$(TEST_CPATH)" -d "$(TEST_CLASSES_DIR)" > "$(TEST_OPTS_FILE)"
@$(ECHO) $(TEST_SOURCES) > "$(TEST_SOURCES_FILE)"
"$(SCALAC)" "@$(TEST_OPTS_FILE)" "@$(TEST_SOURCES_FILE)"
@$(TOUCH) "$(TEST_TARGET)"
test: build $(TEST_TARGET)
"$(JAVA)" -classpath "$(TEST_CPATH)" org.junit.runner.JUnitCore $(TEST_MAIN_CLASS)
##############################################################################
## phony
.PHONY: all build clean doc help lint run test
.SUFFIXES:
.SUFFIXES: .class .jar .java .scala .tasty