forked from ocaml-batteries-team/batteries-included
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
172 lines (139 loc) · 4.55 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# A basic Makefile for building and installing Batteries Included
# It punts to ocamlbuild for all the heavy lifting.
NAME = batteries
VERSION := $(shell cat VERSION)
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
# Define variables and export them for mkconf.ml
DOCROOT ?= /usr/share/doc/ocaml-batteries
export DOCROOT
BROWSER_COMMAND ?= x-www-browser %s
export BROWSER_COMMAND
ifdef DESTDIR
OCAMLFIND_DEST += -destdir $(DESTDIR)
endif
OCAMLBUILD ?= ocamlbuild
ifeq ($(uname_S),Darwin)
BATTERIES_NATIVE ?= yes
BATTERIES_NATIVE_SHLIB ?= no
else
BATTERIES_NATIVE ?= yes
BATTERIES_NATIVE_SHLIB ?= $(BATTERIES_NATIVE)
endif
INSTALL_FILES = _build/META _build/src/*.cma \
battop.ml _build/src/*.cmi _build/src/*.mli \
_build/src/batteries_help.cmo \
_build/src/syntax/pa_comprehension/pa_comprehension.cmo \
_build/src/syntax/pa_strings/pa_strings.cma
NATIVE_INSTALL_FILES = _build/src/*.cmx _build/src/*.a _build/src/*.cmxa
# What to build
TARGETS = syntax.otarget byte.otarget src/batteries_help.cmo META
TEST_TARGETS = testsuite/main.byte qtest/test_runner.byte
TEST_TARGETS = testsuite/main.byte
BENCH_TARGETS = benchsuite/bench_int.native benchsuite/bench_map.native
ifeq ($(BATTERIES_NATIVE_SHLIB), yes)
EXT = native
MODE = shared
TARGETS += shared.otarget
TEST_TARGETS += testsuite/main.native qtest/test_runner.native
INSTALL_FILES += $(NATIVE_INSTALL_FILES) _build/src/*.cmxs
else ifeq ($(BATTERIES_NATIVE), yes)
EXT = native
MODE = native
TARGETS += native.otarget
TEST_TARGETS += testsuite/main.native qtest/test_runner.native
INSTALL_FILES += $(NATIVE_INSTALL_FILES)
else
EXT = byte
MODE = bytecode
endif
.PHONY: all clean doc install uninstall reinstall test qtest camfail camfailunk
all: src/batCamomile.ml
@echo "Build mode:" $(MODE)
${RM} src/batteries_config.ml
$(OCAMLBUILD) $(TARGETS)
clean:
${RM} apidocs
${RM} qtest/*_t.ml qtest/test_mods.mllib
${RM} src/batCamomile.ml
$(OCAMLBUILD) -clean
doc:
$(OCAMLBUILD) batteries.docdir/index.html
test -e apidocs || ln -s _build/batteries.docdir apidocs
install: all uninstall_packages
ocamlfind install $(OCAMLFIND_DEST) estring \
libs/estring/META \
_build/libs/estring/*.cmo \
_build/libs/estring/*.cmi \
_build/libs/estring/*.mli
ocamlfind install $(OCAMLFIND_DEST) $(NAME) $(INSTALL_FILES)
uninstall_packages:
ocamlfind remove $(OCAMLFIND_DEST) estring
ocamlfind remove $(OCAMLFIND_DEST) $(NAME)
uninstall: uninstall_packages
${RM} -r $(DOCROOT)
install-doc: doc
mkdir -p $(DOCROOT)
cp -r doc/batteries/* $(DOCROOT)
# deal with symlink that will break
${RM} $(DOCROOT)/html/batteries_large.png
cp -f doc/batteries_large.png $(DOCROOT)/html
mkdir -p $(DOCROOT)/html/api
cp apidocs/* $(DOCROOT)/html/api
cp LICENSE README FAQ VERSION $(DOCROOT)
reinstall:
$(MAKE) uninstall
$(MAKE) install
#List of source files that it's okay to try to test
DONTTEST=$(wildcard src/batCamomile-*.ml) src/batteries_help.ml
TESTABLE=$(filter-out $(DONTTEST), $(wildcard src/*.ml))
test: src/batCamomile.ml $(patsubst src/%.ml,qtest/%_t.ml, $(TESTABLE)) qtest/test_mods.mllib
$(OCAMLBUILD) $(TARGETS) $(TEST_TARGETS)
$(foreach TEST, $(TEST_TARGETS), echo "Running $(TEST)"; _build/$(TEST); echo; )
bench:
$(OCAMLBUILD) $(TARGETS) $(BENCH_TARGETS)
$(foreach BENCH, $(BENCH_TARGETS), _build/$(BENCH); )
release: test
git archive --format=tar --prefix=batteries-$(VERSION)/ HEAD \
| gzip > batteries-$(VERSION).tar.gz
##
## Magic to detect which version of camomile is installed
##
CAMVER=$(shell sh -c 'ocamlfind query -format %v camomile')
ifeq ($(CAMVER),0.8.2)
CAMFIX=src/batCamomile-0.8.2.ml
endif
ifeq ($(CAMVER),0.8.1)
CAMFIX=src/batCamomile-0.8.1.ml
endif
ifeq ($(CAMVER),0.7.2)
CAMFIX=src/batCamomile-0.7.ml
endif
ifeq ($(CAMVER),0.7.1)
CAMFIX=src/batCamomile-0.7.ml
endif
ifeq ($(CAMVER),)
CAMFIX=camfail
endif
ifeq ($(CAMFIX),)
CAMFIX=camfailunk
endif
src/batCamomile.ml: $(CAMFIX)
cp -f $< $@
camfail:
echo "Camomile not detected, cannot compile batteries"
exit 1
camfailunk:
echo "Unknown build of camomile detected ( $(CAMVER) ), cannot auto-config batcamomile"
exit 1
##
## Magic for test target - auto-generated test files from source comments
##
_build/build/make_suite.$(EXT): build/make_suite.mll
$(OCAMLBUILD) -no-links make_suite.$(EXT)
#convert a source file to a test suite by filtering special comments
qtest/%_t.ml: src/%.ml _build/build/make_suite.$(EXT)
_build/build/make_suite.$(EXT) $< > $@
#put all the testing modules in a library
qtest/test_mods.mllib: $(TESTABLE)
/bin/echo -n "Quickcheck Tests " > $@
echo $(patsubst src/%.ml,%_t, $(TESTABLE)) >> $@