aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 732fdf6f263c1d556f097c9e17b8611553e3666f (plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
BINARIES := \
	mendeleev-c \
	mendeleev-c-cpp \
	mendeleev-cpp \
	mendeleev-f \
	mendeleev-hs \
	mendeleev-py \
	mendeleev-rs \

LISP := \
	clisp:mendeleev.lisp \
	ecl:--shell:mendeleev.lisp \
	sbcl:--script:mendeleev.lisp \

PYTHON := \
	pypy:mendeleev.py \
	python2:mendeleev.py \
	python3:mendeleev.py \

SCRIPTS := $(LISP) $(PYTHON)

.PHONY: build
build: $(BINARIES)

RM := rm -f -v
MV := mv -f -v
.PHONY: clean
clean:
	$(RM) $(BINARIES)
	$(RM) prof-*


# Testing
TEST_FILE := test.txt
WORDS := $(shell awk -F: '/:/ {print "\""$$1"\""}' $(TEST_FILE))
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
.PHONY: test
define mktest
test: test-$(subst $(SPACE),-,$(1))
.PHONY: test-$(subst $(SPACE),-,$(1))
test-$(subst $(SPACE),-,$(1)): $(lastword $(1))
	$(wordlist 2, $(words $(1)), _ $(1)) ./$(lastword $(1)) $(WORDS) | diff -u $(TEST_FILE) -
endef
$(foreach t,$(SCRIPTS),$(eval $(call mktest,$(subst :, ,$(t)))))
$(foreach t,$(BINARIES),$(eval $(call mktest,$(t))))


# Profiling
PROF_TEST := hehehehehehehehehehehehehehehehe
.PHONY: prof
prof: \
	prof-mendeleev-c.txt \
	prof-mendeleev-f.txt \
	prof-mendeleev-hs.txt \
	prof-mendeleev-py.txt \

%.gmon: %
	$(RM) $<-gmon.*
	GMON_OUT_PREFIX=$<-gmon ./$< $(PROF_TEST) > /dev/null
	$(MV) $<-gmon.* $@


# C
CC = gcc
CFLAGS = -std=c99 -Wall -Wextra -O2
%-c: %.c
	$(CC) $(CFLAGS) $< -o $@

CFLAGS_PROF = -O0 -g -pg
prof-%-c: %.c
	$(CC) $(CFLAGS_PROF) $< -o $@

prof-%-c.txt: prof-%-c.gmon
	gprof --brief prof-$*-c $< > $@


# C++
CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -O2
%-c-cpp: %.c
	$(CXX) $(CXXFLAGS) $< -o $@

%-cpp: %.cpp
	$(CXX) $(CXXFLAGS) $< -o $@

CXXFLAGS_PROF = -O0 -g -pg
prof-%-cpp: %.cpp
	$(CXX) $(CXXFLAGS_PROF) $< -o $@

prof-mendeleev-cpp.txt: prof-mendeleev-cpp.gmon
	gprof --brief prof-mendeleev-cpp $< > $@


# Fortran
FC = gfortran
FFLAGS = -std=f2003 -Wall -Wextra -O2
mendeleev-f: mendeleev.f90
	$(FC) $(FFLAGS) $< -o $@

FFLAGS_PROF = -O0 -g -pg -fcheck=all
prof-mendeleev-f: mendeleev.f90
	$(FC) $(FFLAGS_PROF) $< -o $@

prof-mendeleev-f.txt: prof-mendeleev-f.gmon
	gprof --brief prof-mendeleev-f $< > $@


# Haskell
HC = ghc
HCFLAGS = -XHaskell98 -no-keep-hi-files -no-keep-o-files -Wall -O2
mendeleev-hs: mendeleev.hs
	$(HC) $(HCFLAGS) $< -o $@

HCFLAGS_PROF = -prof -fprof-auto -rtsopts -no-keep-hi-files -no-keep-o-files
prof-mendeleev-hs: mendeleev.hs
	$(HC) $(HCFLAGS_PROF) $< -o $@

prof-mendeleev-hs.txt: prof-mendeleev-hs
	./$< +RTS -p -RTS $(PROF_TEST) > /dev/null
	$(MV) $<.prof $@


# Python
NUITKA = nuitka3
NUITKA_FLAGS = --quiet --remove-output --follow-imports
mendeleev-py: mendeleev.py
	$(NUITKA) $(NUITKA_FLAGS) $< -o $@

prof-mendeleev-py.dat: mendeleev.py
	python3 -m cProfile -o $@ $< $(PROF_TEST) > /dev/null

prof-mendeleev-py.txt: prof-mendeleev-py.dat
	python3 -c 'import pstats; pstats.Stats("$<").sort_stats("tottime").print_stats()' > $@


# Rust
RUSTC = rustc
RUSTC_FLAGS = -C opt-level=2 -C strip=symbols
mendeleev-rs: mendeleev.rs
	$(RUSTC) $(RUSTC_FLAGS) $< -o $@