-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
128 lines (96 loc) · 3.92 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
128
# File : Makefile
# Author : Peter Schachte
# Purpose : Build and install the Wybe compiler
# Configure these to your preferred installation locations
INSTALLBIN=/usr/local/bin
INSTALLLIB=/usr/local/lib/wybe
# Configure any extra C library and include directories
EXTRALIBS=-L /usr/local/lib -L /opt/homebrew/lib
EXTRAINCLUDES=-I /usr/local/include -I /opt/homebrew/include
# You shouldn't need to edit anything below here
VERSION = 0.2
SRCDIR = src
LIBDIR = wybelibs
WYBELIBS = wybe.o command_line.o logging.o random.o benchmark.o
CLIBS = wybe/cbits.o
LIBS = $(WYBELIBS) $(CLIBS)
SHELL := /bin/bash
ifeq ($(shell uname), Darwin)
ISSYSROOT = -isysroot `xcrun --show-sdk-path`
# On Mac OS X, gtimeout is in homebrew coreutils package
TIMEOUT = gtimeout
endif
ifeq ($(shell uname), Linux)
ISSYSROOT =
TIMEOUT = timeout
endif
all: wybemk libs
install: wybemk
cp wybemk "$(INSTALLBIN)"
rm -rf "$(INSTALLLIB)"
mkdir -p "$(INSTALLLIB)"
cp -r "$(LIBDIR)/." "$(INSTALLLIB)"
"$(INSTALLBIN)/wybemk" --force-all $(addsuffix ", $(addprefix "$(INSTALLLIB)/,$(WYBELIBS)))
wybemk: $(SRCDIR)/*.hs $(SRCDIR)/CConfig.hs $(SRCDIR)/Version.lhs
stack -j3 build && cp "`stack path --local-install-root`/bin/$@" "$@"
libs: $(addprefix $(LIBDIR)/,$(LIBS))
$(LIBDIR)/%.o: $(LIBDIR)/%.wybe wybemk
./wybemk --force-all -L $(LIBDIR) $@
$(LIBDIR)/wybe.o: wybemk $(LIBDIR)/wybe/*.wybe
./wybemk --force-all -L $(LIBDIR) $@
$(LIBDIR)/wybe/cbits.o: $(LIBDIR)/wybe/cbits.c
clang $(ISSYSROOT) $(EXTRAINCLUDES) -c "$<" -o "$@"
$(SRCDIR)/Version.lhs: $(addprefix $(SRCDIR)/,*.hs)
@echo -e "Generating Version.lhs for version $(VERSION)"
@rm -f "$@"
@printf "Version.lhs automatically generated: DO NOT EDIT\n" > "$@"
@printf "\n" >> "$@"
@printf "> module Version (version,gitHash,buildDate,libDir,defaultTriple) where\n\n" >> "$@"
@printf "> version :: String\n> version = \"%s\"\n\n" "$(VERSION)" >> "$@"
@printf "> gitHash :: String\n> gitHash = \"%s\"\n\n" "`git rev-parse --short HEAD`" >> "$@"
@printf "> buildDate :: String\n> buildDate = \"%s\"\n\n" "`date`" >> "$@"
@printf "> libDir :: String\n> libDir = \"%s\"\n\n" "$(INSTALLLIB)" >> "$@"
@printf "> defaultTriple :: String\n> defaultTriple = \"" >> "$@"
@clang --version | sed -n 's/Target: *\(.*\)/\1\"/p' >> "$@"
@printf "\n\n" >> "$@"
$(SRCDIR)/CConfig.hs: $(SRCDIR)/c_config
$< > $@
$(SRCDIR)/c_config: $(SRCDIR)/c_config.c
clang $(ISSYSROOT) $(EXTRAINCLUDES) -o $@ $<
.PHONY: doc
doc: src/README.md
# Assemble README markdown source file automatically
src/README.md: src/*.hs Makefile src/README.md.intro src/README.md.outro \
src/Compiler.png src/Detail.png
cat src/README.md.intro > "$@"
printf "The source files in this directory and their purposes are:\n\n" >> "$@"
printf "| File | Purpose |\n" >> "$@"
printf "| ---- | -------------------------------------------- |\n" >> "$@"
for f in src/*.hs ; do \
b=`basename $$f` ; \
m=`basename $$f .hs` ; \
printf "| `printf '%-20s' [$$b]\(#$$m\)` | " ; \
sed -n "s/^-- *Purpose *: *\(.*\)/\1/p" $$f | tr -d '\n' ; \
printf " |\n" ; \
done >> "$@"
printf "\n\n# Modules in more detail\n\n" >> "$@"
for f in src/*.hs ; do \
m=`basename $$f .hs` ; \
echo -e ; \
echo -e "## $$m <a id="$$m"></a>" ; \
sed -E -e '/BEGIN MAJOR DOC/,/END MAJOR DOC/{//d ; s/^-- ? ?//p;}' -e 'd' <$$f ; \
done >> "$@"
printf "\n\n" >> "$@"
cat src/README.md.outro >> "$@"
test: wybemk
@rm -f ERRS ; printf "Testing run " > ERRS ; date >> ERRS
@rm -f $(LIBDIR)/*.o $(LIBDIR)/wybe/*.o
@echo -e "Building $(LIBDIR)/wybe/cbits.o"
@make $(LIBDIR)/wybe/cbits.o
@printf "Testing building wybe library ("
@$(TIMEOUT) 40 $(MAKE) libs
@printf ") done.\n"
@time ( cd test-cases/ && ./run-all-test.sh )
clean:
stack clean
rm -f $(SRCDIR)/*.o $(SRCDIR)/*.hi $(SRCDIR)/Version.lhs $(SRCDIR)/CConfig.hs documentation/*.pdf publications/*.pdf $(LIBDIR)/*.o $(LIBDIR)/wybe/*.o test-cases/*.o