Makefile 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. # Top-level Makefile for Agda 2
  2. # Authors: Ulf Norell, Nils Anders Danielsson, Francesco Mazzoli
  3. SHELL=bash
  4. # Profiling verbosity for library-test
  5. PROFVERB=7
  6. # Various paths and commands
  7. TOP=.
  8. # mk/path.mk uses TOP, so include after the definition of TOP.
  9. include ./mk/paths.mk
  10. CABAL_CMD=cabal
  11. # Run in interactive and parallel mode by default
  12. # You can use the $(PARALLEL_TESTS_FILE) file for setting the number of
  13. # parallel tests, e.g.
  14. # PARALLEL_TESTS = 123
  15. PARALLEL_TESTS_FILE = mk/parallel-tests.mk
  16. ifeq ($(wildcard $(PARALLEL_TESTS_FILE)),)
  17. # Setting the default value.
  18. PARALLEL_TESTS = $(shell getconf _NPROCESSORS_ONLN)
  19. else
  20. # Getting the value from the $(PARALLEL_TESTS_FILE) file.
  21. include $(PARALLEL_TESTS_FILE)
  22. endif
  23. AGDA_TESTS_OPTIONS ?=-i -j$(PARALLEL_TESTS)
  24. ## Default target #########################################################
  25. .PHONY : default
  26. default: install-bin
  27. ## Cabal-based installation ###############################################
  28. .PHONY : install
  29. install: install-bin compile-emacs-mode setup-emacs-mode
  30. .PHONY : prof
  31. prof : install-prof-bin
  32. CABAL_INSTALL_HELPER = $(CABAL_CMD) install --disable-documentation
  33. # 2016-07-15. We use a different build directory in the quick
  34. # installation for avoiding recompilation (see Issue #2083 and
  35. # https://github.com/haskell/cabal/issues/1893).
  36. QUICK_CABAL_INSTALL = $(CABAL_INSTALL_HELPER) --builddir=$(BUILD_DIR)-quick
  37. SLOW_CABAL_INSTALL_OPTS = --builddir=$(BUILD_DIR) --enable-tests
  38. CABAL_INSTALL = $(CABAL_INSTALL_HELPER) \
  39. $(SLOW_CABAL_INSTALL_OPTS)
  40. # The following options are used in several invocations of cabal
  41. # install/configure below. They are always the last options given to
  42. # the command.
  43. CABAL_INSTALL_OPTS = -fenable-cluster-counting $(CABAL_OPTS)
  44. CABAL_INSTALL_BIN_OPTS = --disable-library-profiling \
  45. $(CABAL_INSTALL_OPTS)
  46. CABAL_CONFIGURE_OPTS = $(SLOW_CABAL_INSTALL_OPTS) \
  47. $(CABAL_INSTALL_BIN_OPTS)
  48. # Ensures that the Git hash that is sometimes displayed by --version
  49. # is correct (#2988).
  50. .PHONY : ensure-hash-is-correct
  51. ensure-hash-is-correct :
  52. touch src/full/Agda/VersionCommit.hs
  53. .PHONY : quick-install-bin
  54. quick-install-bin : ensure-hash-is-correct
  55. $(QUICK_CABAL_INSTALL) $(CABAL_INSTALL_BIN_OPTS)
  56. # Install Agda using Stack
  57. .PHONY : stack-install-bin
  58. stack-install-bin :
  59. stack build Agda:exe:agda \
  60. --flag Agda:enable-cluster-counting \
  61. --no-haddock \
  62. --no-library-profiling
  63. # The Stack version of `Cabal install --enable-test`
  64. .PHONY : stack-install-test
  65. stack-install-test :
  66. stack build Agda:test:agda-tests \
  67. --no-run-tests \
  68. --flag Agda:enable-cluster-counting \
  69. --no-haddock \
  70. --no-library-profiling
  71. # Copy the artefacts built by Stack as if they were build by Cabal.
  72. .PHONY : stack-copy-artefacts
  73. stack-copy-artefacts : stack-install-bin stack-install-test
  74. mkdir -p $(BUILD_DIR)/build/
  75. cp -r $(shell stack path --dist-dir)/build $(BUILD_DIR)
  76. .PHONY : install-bin
  77. install-bin : ensure-hash-is-correct
  78. ifneq ("$(wildcard stack.yaml)","") # if `stack.yaml` exists
  79. @echo ""===================== Installing using Stack =============================""
  80. $(MAKE) stack-install-bin
  81. $(MAKE) stack-install-test
  82. $(MAKE) stack-copy-artefacts
  83. else
  84. $(CABAL_INSTALL) $(CABAL_INSTALL_BIN_OPTS)
  85. endif
  86. .PHONY : install-prof-bin
  87. install-prof-bin : ensure-hash-is-correct
  88. $(CABAL_INSTALL) --enable-library-profiling --enable-profiling \
  89. --program-suffix=_p $(CABAL_INSTALL_OPTS)
  90. # --program-suffix is not for the executable name in
  91. # $(BUILD_DIR)/build/, only for installing it into .cabal/bin
  92. # Builds Agda with the debug flag enabled. A separate build directory
  93. # is used. The suffix "-debug" is used for the binaries.
  94. .PHONY : install-debug
  95. install-debug : ensure-hash-is-correct
  96. $(CABAL_INSTALL) --disable-library-profiling \
  97. -fdebug --program-suffix=-debug --builddir=$(BUILD_DIR)-debug \
  98. $(CABAL_INSTALL_OPTS)
  99. .PHONY : compile-emacs-mode
  100. compile-emacs-mode: install-bin
  101. $(AGDA_MODE) compile
  102. .PHONY : setup-emacs-mode
  103. setup-emacs-mode : install-bin
  104. @echo
  105. @echo "If the agda-mode command is not found, make sure that the directory"
  106. @echo "in which it was installed is located on your shell's search path."
  107. @echo
  108. $(AGDA_MODE) setup
  109. ## Making and testing the Haddock documentation ##############################
  110. .PHONY : haddock
  111. haddock :
  112. $(CABAL_CMD) configure $(CABAL_CONFIGURE_OPTS)
  113. $(CABAL_CMD) haddock --builddir=$(BUILD_DIR)
  114. ## Making the user manual ####################################################
  115. .PHONY : user-manual-html
  116. user-manual-html :
  117. @echo "======================================================================"
  118. @echo "===================== User Manual (html) ============================="
  119. @echo "======================================================================"
  120. $(MAKE) -C doc/user-manual html
  121. .PHONY : user-manual-pdf
  122. user-manual-pdf :
  123. @echo "======================================================================"
  124. @echo "====================== User Manual (pdf) ============================="
  125. @echo "======================================================================"
  126. $(MAKE) -C doc/user-manual PDFLATEX='latexmk -xelatex -latexoption=-interaction=nonstopmode -latexoption=-halt-on-error' latexpdf
  127. cp doc/user-manual/_build/latex/Agda.pdf doc/user-manual.pdf
  128. .PHONY : user-manual-linkcheck
  129. user-manual-linkcheck :
  130. @echo "======================================================================"
  131. @echo "================== User Manual (linkcheck) ==========================="
  132. @echo "======================================================================"
  133. $(MAKE) -C doc/user-manual linkcheck
  134. ## Making the full language ###############################################
  135. $(AGDA_BIN): ensure-hash-is-correct
  136. $(CABAL_CMD) build $(CABAL_OPTS)
  137. .PHONY : full
  138. full : $(AGDA_BIN)
  139. ## Making the source distribution #########################################
  140. .PHONY : tags
  141. tags :
  142. $(MAKE) -C $(FULL_SRC_DIR) tags
  143. .PHONY : TAGS
  144. TAGS :
  145. @echo "======================================================================"
  146. @echo "================================ TAGS ================================"
  147. @echo "======================================================================"
  148. $(MAKE) -C $(FULL_SRC_DIR) TAGS
  149. ## Testing ################################################################
  150. .PHONY : quick
  151. quick : install-O0-bin quicktest
  152. .PHONY : test
  153. test : check-whitespace succeed fail interaction examples library-test interactive latex-html-test api-test internal-tests benchmark-without-logs compiler-test lib-succeed lib-interaction user-manual-test test-size-solver
  154. .PHONY : quicktest
  155. quicktest : succeed fail
  156. .PHONY : internal-tests
  157. internal-tests :
  158. @echo "======================================================================"
  159. @echo "======================== Internal test suite ========================="
  160. @echo "======================================================================"
  161. @AGDA_BIN=$(AGDA_BIN) $(AGDA_TESTS_BIN) $(AGDA_TESTS_OPTIONS) --regex-include all/Internal
  162. .PHONY : succeed
  163. succeed :
  164. @echo "======================================================================"
  165. @echo "===================== Suite of successfull tests ====================="
  166. @echo "======================================================================"
  167. @$(MAKE) -C test/Common
  168. @AGDA_BIN=$(AGDA_BIN) $(AGDA_TESTS_BIN) $(AGDA_TESTS_OPTIONS) --regex-include all/Succeed
  169. .PHONY : interaction
  170. interaction :
  171. @echo "======================================================================"
  172. @echo "===================== Suite of interaction tests ====================="
  173. @echo "======================================================================"
  174. @$(MAKE) -C test/interaction
  175. .PHONY : interactive
  176. interactive :
  177. @echo "======================================================================"
  178. @echo "===================== Suite of interactive tests ====================="
  179. @echo "======================================================================"
  180. @AGDA_BIN=$(AGDA_BIN) $(AGDA_TESTS_BIN) $(AGDA_TESTS_OPTIONS) --regex-include all/Interactive
  181. .PHONY : examples
  182. examples :
  183. @echo "======================================================================"
  184. @echo "========================= Suite of examples =========================="
  185. @echo "======================================================================"
  186. @$(MAKE) -C examples
  187. .PHONY : fail
  188. fail :
  189. @echo "======================================================================"
  190. @echo "======================= Suite of failing tests ======================="
  191. @echo "======================================================================"
  192. @AGDA_BIN=$(AGDA_BIN) $(AGDA_TESTS_BIN) $(AGDA_TESTS_OPTIONS) --regex-include all/Fail
  193. .PHONY : latex-html-test
  194. latex-html-test :
  195. @echo "======================================================================"
  196. @echo "=========== Suite of tests for the LaTeX and HTML backends ==========="
  197. @echo "======================================================================"
  198. @AGDA_BIN=$(AGDA_BIN) $(AGDA_TESTS_BIN) $(AGDA_TESTS_OPTIONS) --regex-include all/LaTeXAndHTML
  199. .PHONY : html-test
  200. html-test :
  201. @echo "======================================================================"
  202. @echo "================ Suite of tests for the HTML backend ================="
  203. @echo "======================================================================"
  204. @AGDA_BIN=$(AGDA_BIN) $(AGDA_TESTS_BIN) $(AGDA_TESTS_OPTIONS) --regex-include all/HTMLOnly
  205. .PHONY : latex-test
  206. latex-test :
  207. @echo "======================================================================"
  208. @echo "================ Suite of tests for the LaTeX backend ================"
  209. @echo "======================================================================"
  210. @AGDA_BIN=$(AGDA_BIN) $(AGDA_TESTS_BIN) $(AGDA_TESTS_OPTIONS) --regex-include all/LaTeXOnly
  211. .PHONY : quicklatex-test
  212. quicklatex-test :
  213. @echo "======================================================================"
  214. @echo "============= Suite of tests for the QuickLaTeX backend =============="
  215. @echo "======================================================================"
  216. @AGDA_BIN=$(AGDA_BIN) $(AGDA_TESTS_BIN) $(AGDA_TESTS_OPTIONS) --regex-include all/QuickLaTeXOnly
  217. .PHONY : std-lib
  218. std-lib :
  219. git submodule update --init std-lib
  220. .PHONY : up-to-date-std-lib
  221. up-to-date-std-lib :
  222. git submodule update --init std-lib
  223. @(cd std-lib && make setup)
  224. .PHONY : fast-forward-std-lib
  225. fast-forward-std-lib :
  226. git submodule update --init --remote std-lib
  227. @(cd std-lib && make setup)
  228. .PHONY : library-test
  229. library-test : # up-to-date-std-lib
  230. @echo "======================================================================"
  231. @echo "========================== Standard library =========================="
  232. @echo "======================================================================"
  233. (cd std-lib && runhaskell GenerateEverything.hs && \
  234. time $(AGDA_BIN) --ignore-interfaces --no-default-libraries -v profile:$(PROFVERB) \
  235. -i. -isrc README.agda \
  236. +RTS -s -H1G -M1.5G)
  237. .PHONY : continue-library-test
  238. continue-library-test :
  239. @(cd std-lib && \
  240. time $(AGDA_BIN) -v profile:$(PROFVERB) --no-default-libraries -i. -isrc README.agda +RTS -s -H1G -M1.5G)
  241. .PHONY : lib-succeed
  242. lib-succeed :
  243. @echo "======================================================================"
  244. @echo "========== Successfull tests using the standard library =============="
  245. @echo "======================================================================"
  246. @find test/LibSucceed -type f -name '*.agdai' -delete
  247. @AGDA_BIN=$(AGDA_BIN) $(AGDA_TESTS_BIN) $(AGDA_TESTS_OPTIONS) --regex-include all/LibSucceed
  248. .PHONY : lib-interaction
  249. lib-interaction :
  250. @echo "======================================================================"
  251. @echo "========== Interaction tests using the standard library =============="
  252. @echo "======================================================================"
  253. @$(MAKE) -C test/$@
  254. .PHONY : compiler-test
  255. compiler-test :
  256. @echo "======================================================================"
  257. @echo "========================== Compiler tests ============================"
  258. @echo "======================================================================"
  259. @AGDA_BIN=$(AGDA_BIN) $(AGDA_TESTS_BIN) $(AGDA_TESTS_OPTIONS) --regex-include all/Compiler
  260. .PHONY : api-test
  261. api-test :
  262. @echo "======================================================================"
  263. @echo "======== Successfull tests using Agda as a Haskell library ==========="
  264. @echo "======================================================================"
  265. @$(MAKE) -C test/api
  266. .PHONY : benchmark
  267. benchmark :
  268. @echo "======================================================================"
  269. @echo "========================= Benchmark suite ============================"
  270. @echo "======================================================================"
  271. @$(MAKE) -C benchmark
  272. .PHONY : benchmark-without-logs
  273. benchmark-without-logs :
  274. @echo "======================================================================"
  275. @echo "============ Benchmark suite without creating logs ==================="
  276. @echo "======================================================================"
  277. @$(MAKE) -C benchmark without-creating-logs
  278. .PHONY : user-manual-test
  279. user-manual-test :
  280. @echo "======================================================================"
  281. @echo "=========================== User manual =============================="
  282. @echo "======================================================================"
  283. @find doc/user-manual -type f -name '*.agdai' -delete
  284. @AGDA_BIN=$(AGDA_BIN) $(AGDA_TESTS_BIN) $(AGDA_TESTS_OPTIONS) --regex-include all/UserManual
  285. .PHONY : testing-emacs-mode
  286. testing-emacs-mode:
  287. @echo "======================================================================"
  288. @echo "===================== Testing the Emacs mode ========================="
  289. @echo "======================================================================"
  290. $(AGDA_MODE) compile
  291. ## Clean ##################################################################
  292. clean_helper = if [ -d $(1) ]; then $(CABAL_CMD) clean --builddir=$(1); fi;
  293. .PHONY : clean
  294. clean :
  295. $(call clean_helper,$(BUILD_DIR))
  296. $(call clean_helper,$(BUILD_DIR)-quick)
  297. ## Whitespace-related #####################################################
  298. # Agda can fail to compile on Windows if files which are CPP-processed
  299. # don't end with a newline character (because we use -Werror).
  300. FAW_PATH = src/fix-agda-whitespace
  301. FAW_BIN = $(FAW_PATH)/dist/build/fix-agda-whitespace/fix-agda-whitespace
  302. .PHONY : fix-whitespace
  303. fix-whitespace : build-fix-agda-whitespace
  304. $(FAW_BIN)
  305. .PHONY : check-whitespace
  306. check-whitespace : build-fix-agda-whitespace
  307. $(FAW_BIN) --check
  308. .PHONY : build-fix-agda-whitespace
  309. build-fix-agda-whitespace :
  310. ifneq ("$(wildcard stack.yaml)","") # if `stack.yaml` exists
  311. stack build fix-agda-whitespace
  312. mkdir -p $(FAW_PATH)/dist/build/fix-agda-whitespace/
  313. cp $(shell stack path --local-install-root)/bin/fix-agda-whitespace $(FAW_BIN)
  314. else
  315. cd $(FAW_PATH) && $(CABAL_CMD) clean && $(CABAL_CMD) build
  316. endif
  317. ## size-solver standalone program #########################################
  318. # NB. It is necessary to install the Agda library (i.e run `make install-bin`)
  319. # before installing the `size-solver` program.
  320. .PHONY : install-size-solver
  321. install-size-solver :
  322. @echo "======================================================================"
  323. @echo "============== Installing the size-solver program ===================="
  324. @echo "======================================================================"
  325. $(MAKE) -C src/size-solver install-bin
  326. .PHONY : test-size-solver
  327. test-size-solver : install-size-solver
  328. @echo "======================================================================"
  329. @echo "=============== Testing the size-solver program ======================"
  330. @echo "======================================================================"
  331. $(MAKE) -C src/size-solver test
  332. ## agda-bisect standalone program #########################################
  333. .PHONY : install-agda-bisect
  334. install-agda-bisect :
  335. @echo "======================================================================"
  336. @echo "============== Installing the agda-bisect program ===================="
  337. @echo "======================================================================"
  338. cd src/agda-bisect && $(CABAL_CMD) install
  339. ###########################################################################
  340. # HPC
  341. .PHONY: hpc-build
  342. hpc-build: ensure-hash-is-correct
  343. $(CABAL_CMD) clean $(CABAL_OPTS)
  344. $(CABAL_CMD) configure --enable-library-coverage $(CABAL_INSTALL_OPTS)
  345. $(CABAL_CMD) build $(CABAL_OPTS)
  346. agda.tix: ./examples/agda.tix ./test/Succeed/agda.tix ./test/compiler/agda.tix ./test/api/agda.tix ./test/interaction/agda.tix ./test/fail/agda.tix ./test/lib-succeed/agda.tix ./std-lib/agda.tix
  347. hpc sum --output=$@ $^
  348. .PHONY: hpc
  349. hpc: hpc-build test agda.tix
  350. hpc report --hpcdir=$(BUILD_DIR)/hpc/mix/Agda-$(VERSION) agda.tix
  351. hpc markup --hpcdir=$(BUILD_DIR)/hpc/mix/Agda-$(VERSION) agda --destdir=hpc-report
  352. ## Lines of Code ##########################################################
  353. agdalocfiles=$(shell find . \( \( -name '*.agda' -o -name '*.in' \) ! -name '.*' \) )
  354. # Agda files (tests) in this project
  355. agda-loc :
  356. @wc $(agdalocfiles)
  357. # Source code of Agda
  358. loc :
  359. make -C src/full loc
  360. ###########################################################################
  361. # Module dependency graph
  362. mod-dep : module-dependency-graph.pdf
  363. mod-dot : module-dependency-graph.dot
  364. module-dependency-graph.pdf : %.pdf : %.dot
  365. dot -Tpdf $< > $@
  366. module-dependency-graph.dot : Agda.cabal Makefile
  367. graphmod --no-cluster --prune-edges > $@
  368. ###########################################################################
  369. # HLint
  370. hlint : $(BUILD_DIR)/build/autogen/cabal_macros.h
  371. hlint --cpp-file=$< \
  372. --cpp-include=$(FULL_SRC_DIR) \
  373. --report=hlint-report.html \
  374. $(FULL_SRC_DIR)/Agda
  375. ###########################################################################
  376. # Debug
  377. debug :
  378. @echo "AGDA_BIN = $(AGDA_BIN)"
  379. @echo "AGDA_TESTS_BIN = $(AGDA_TESTS_BIN)"
  380. @echo "AGDA_TESTS_OPTIONS = $(AGDA_TESTS_OPTIONS)"
  381. @echo "BUILD_DIR = $(BUILD_DIR)"
  382. @echo "CABAL_CMD = $(CABAL_CMD)"
  383. @echo "CABAL_OPTS = $(CABAL_OPTS)"
  384. @echo "GHC_VERSION = $(GHC_VERSION)"
  385. @echo "PARALLEL_TESTS = $(PARALLEL_TESTS)"
  386. # EOF