forked from ManasJayanth/flow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
128 lines (106 loc) · 3.45 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
# Copyright (c) 2013-present, Facebook, Inc.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
TOP=$(DIR)/../..
REL_DIR=src/parser
OCB = ocamlbuild -use-ocamlfind
NATIVE_OBJECT_FILES=\
hack/utils/sys/files.o\
hack/utils/sys/getrusage.o\
hack/utils/sys/nproc.o\
hack/utils/sys/realpath.o\
hack/utils/sys/sysinfo.o\
hack/utils/sys/processor_info.o\
hack/utils/sys/priorities.o
RUNNER_DEPS=\
hack/heap\
hack/injection/default_injector\
hack/utils\
hack/utils/collections\
hack/utils/disk\
hack/utils/hh_json\
hack/utils/sys\
hack/third-party/core\
src/common/utils\
src/parser\
src/parser_utils
OCAML_PATH=$(shell ocamlc -where)
OCAML_HEADERS=\
$(sort $(patsubst $(OCAML_PATH)/%,dist/libflowparser/include/%, \
$(filter $(OCAML_PATH)/%,$(shell \
$(CC) -I $(OCAML_PATH) -MM -MT deps libflowparser.h \
))))
all: build-parser
clean:
$(OCB) -clean; \
cd $(TOP); \
$(OCB) -clean; \
rm -f $(REL_DIR)/flow_parser.js; \
rm -rf $(REL_DIR)/dist
build-parser:
cd $(TOP); \
$(OCB) -no-links $(REL_DIR)/parser_flow.cmxa
.PHONY: libflowparser.native.o
libflowparser.native.o:
cd $(TOP) && $(OCB) -no-links -tag "runtime_variant(_pic)" \
$(REL_DIR)/libflowparser.native.o
dist/libflowparser/lib/libflowparser.a: libflowparser.native.o
@mkdir -p "$(@D)"
if [ ! -e "$@" -o "$(OCAML_PATH)/libasmrun_pic.a" -nt "$@" -o "$(TOP)/_build/$(REL_DIR)/libflowparser.native.o" -nt "$@" ]; then \
echo "Rebuilding $@"; \
cp "$(OCAML_PATH)/libasmrun_pic.a" "$@"; \
ar rcs "$@" "$(TOP)/_build/$(REL_DIR)/libflowparser.native.o"; \
else \
echo "Not rebuilding $@, already up to date"; \
fi
test -e "$@" || exit 1
$(OCAML_HEADERS): dist/libflowparser/include/%: $(OCAML_PATH)/%
@mkdir -p "$(@D)"
cp "$<" "$@"
dist/libflowparser/include/flowparser/libflowparser.h: libflowparser.h
@mkdir -p "$(@D)"
cp "$<" "$@"
dist/libflowparser.zip: \
$(OCAML_HEADERS) \
dist/libflowparser/include/flowparser/libflowparser.h \
dist/libflowparser/lib/libflowparser.a
cd dist && zip -r $(@F) libflowparser
js:
cd $(TOP); \
$(OCB) -no-links -pkgs js_of_ocaml $(REL_DIR)/flow_parser_dot_js.byte; \
[ -e "$(REL_DIR)/flow_parser.js" -a "$(REL_DIR)/flow_parser.js" -nt "_build/$(REL_DIR)/flow_parser_dot_js.byte" ] || \
js_of_ocaml --opt 3 \
-o $(REL_DIR)/flow_parser.js \
_build/$(REL_DIR)/flow_parser_dot_js.byte
test-js: js
cd $(TOP)/packages/flow-parser; npm test
../../_build/$(REL_DIR)/test/run_tests.native: build-parser
cd $(TOP); \
$(OCB) -no-links \
-ocamlc "ocamlopt" \
$(NATIVE_OBJECT_FILES); \
$(OCB) -no-links \
$(foreach dir,$(RUNNER_DEPS),-I $(dir)) \
-lib unix -lib str \
-lflags "$(NATIVE_OBJECT_FILES)" \
$(REL_DIR)/test/run_tests.native
test-esprima-ocaml: ../../_build/$(REL_DIR)/test/run_tests.native
cd $(TOP); \
_build/$(REL_DIR)/test/run_tests.native $(REL_DIR)/test/esprima/
test-hardcoded-ocaml: ../../_build/$(REL_DIR)/test/run_tests.native
cd $(TOP); \
_build/$(REL_DIR)/test/run_tests.native $(REL_DIR)/test/flow/
test-ocaml: test-esprima-ocaml test-hardcoded-ocaml
test: test-js test-ocaml
ocamlfind-install:
cd $(TOP); \
$(OCB) $(REL_DIR)/parser_flow.cma $(REL_DIR)/parser_flow.cmxa; \
ocamlfind install flow_parser $(REL_DIR)/META \
_build/$(REL_DIR)/parser_flow.a \
_build/$(REL_DIR)/parser_flow.cma \
_build/$(REL_DIR)/parser_flow.cmxa \
_build/$(REL_DIR)/*.cmi
lexer.native: lexer.ml
$(OCB) $@