Ensure found LZ4 is at least v1.7
[hiphop-php.git] / hphp / hack / src / Makefile
blobe3efcb27f03d5e36820df0f733fe68e9d0db5722
1 ################################################################################
2 # Variables to override #
3 ################################################################################
5 EXTRA_INCLUDE_PATHS=
6 EXTRA_LIB_PATHS=
7 EXTRA_LINK_OPTS=
8 EXTRA_CC_FLAGS=
9 BYTECODE=
11 ################################################################################
12 # OS-dependent stuff #
13 ################################################################################
15 OS=$(shell uname -s)
16 ROOT=$(shell pwd)
18 ifeq ($(OS), Linux)
19 INOTIFY=third-party/inotify
20 FSNOTIFY=fsnotify_linux
21 ELF=elf
22 RT=rt
23 FRAMEWORKS=
24 SECTCREATE=
25 endif
26 ifeq ($(OS), Darwin)
27 INOTIFY=fsevents
28 FSNOTIFY=fsnotify_darwin
29 ELF=
30 RT=
31 FRAMEWORKS=CoreServices CoreFoundation
32 SECTCREATE=-cclib -sectcreate -cclib __text -cclib hhi -cclib $(ROOT)/../bin/hhi.tar.gz
33 endif
35 ifeq ($(BYTECODE), 1)
36 TARGET_EXT=byte
37 else
38 TARGET_EXT=native
39 endif
41 ################################################################################
42 # Definitions #
43 ################################################################################
45 MODULES=\
46 ast\
47 client\
48 decl\
49 deps\
50 dfind\
51 diff\
52 debug\
53 find\
54 format\
55 hackfmt/debug\
56 hackfmt/line_splitter\
57 hackfmt\
58 globals\
59 hackfmt/error\
60 heap\
61 hhbc\
62 hhi\
63 ide_rpc\
64 injection/default_injector\
65 libancillary\
66 naming\
67 options\
68 parser\
69 parser/schema\
70 procs\
71 recorder\
72 search\
73 server\
74 socket\
75 stubs\
76 third-party/avl\
77 third-party/core\
78 typing\
79 utils\
80 utils/collections\
81 utils/errors\
82 utils/lint\
83 utils/disk\
84 utils/process\
85 utils/hg\
86 utils/hh_json\
87 monitor\
88 watchman\
89 $(FSNOTIFY)\
90 $(INOTIFY)
92 NATIVE_C_FILES=\
93 heap/hh_shared.c\
94 hhi/hhi_elf.c\
95 hhi/hhi_win32res_stubs.c\
96 libancillary/libancillary-stubs.c\
97 third-party/libancillary/fd_recv.c\
98 third-party/libancillary/fd_send.c\
99 utils/files.c\
100 utils/get_build_id.c\
101 utils/handle_stubs.c\
102 utils/nproc.c\
103 utils/priorities.c\
104 utils/realpath.c\
105 utils/sysinfo.c\
106 $(INOTIFY)/$(notdir $(INOTIFY))_stubs.c
108 OCAML_LIBRARIES=\
109 str\
110 unix\
111 bigarray
113 NATIVE_LIBRARIES=\
114 pthread\
115 $(ELF)\
116 $(RT)
118 TARGETS_BASE=_build/hh_server _build/hh_client \
119 _build/hh_single_type_check \
120 _build/hh_format \
121 _build/hackfmt
123 TARGETS=$(foreach target,$(TARGETS_BASE),$(target).$(TARGET_EXT))
125 # Find all source files (all files not in _build dir)
126 ALL_SRC_FILES=$(call rwildcard,$(patsubst _build,,$(wildcard *)),*.*)
128 ################################################################################
129 # Rules #
130 ################################################################################
132 OBJECT_FILES_TO_BUILD=$(patsubst %.c,%.o,$(NATIVE_C_FILES))
133 NATIVE_OBJECT_FILES=$(OBJECT_FILES_TO_BUILD) utils/get_build_id.gen.o
134 INCLUDE_OPTS=$(foreach dir,$(MODULES),-I $(dir))
135 LIB_OPTS=$(foreach lib,$(OCAML_LIBRARIES),-lib $(lib))
136 NATIVE_LIB_OPTS=$(foreach lib, $(NATIVE_LIBRARIES),-cclib -l$(lib))
137 EXTRA_NATIVE_LIB_OPTS=$(foreach lib, $(EXTRA_NATIVE_LIBRARIES),-cclib -l$(lib))
138 EXTRA_INCLUDE_OPTS=$(foreach dir, $(EXTRA_INCLUDE_PATHS),-ccopt -I$(dir))
139 EXTRA_CC_OPTS=$(foreach opt, $(EXTRA_CC_FLAGS),-ccopt $(opt))
140 EXTRA_LINK=$(EXTRA_LINK_OPTS) $(foreach dir, $(EXTRA_LIB_PATHS),-cclib -L$(dir))
141 FRAMEWORK_OPTS=$(foreach framework, $(FRAMEWORKS),-cclib -framework -cclib $(framework))
143 LINKER_FLAGS=$(NATIVE_OBJECT_FILES) $(NATIVE_LIB_OPTS) $(EXTRA_LINK) \
144 $(EXTRA_NATIVE_LIB_OPTS) $(FRAMEWORK_OPTS) $(SECTCREATE)
145 # Function to recursively find files, eg: $(call rwildcard,dir/to/look/in/,*.c)
146 rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
148 all: build-hhi-archive build-hack copy-hack-files
149 all-ocp: build-hhi-archive build-hack-with-ocp copy-hack-files-ocp
151 clean:
152 $(OCAMLBUILD) -clean
153 find ../bin -mindepth 1 -not -path ../bin/README -delete
154 rm -f utils/get_build_id.gen.c
156 build-hack: $(TARGETS) build-hhi-archive
158 build-hack-with-ocp: build-hhi-archive _build/utils/get_build_id.gen.o
159 [ -d ${ROOT}/../_obuild ] || ( cd ${ROOT}/.. && ocp-build init )
160 ocp-build build
162 # These are needed so we can turn OCAMLBUILD from 'a,b,c' into 'a b c' below
163 comma := ,
164 space :=
165 space +=
167 # All targets are built in one time, so no parallelization is necessary
168 .NOTPARALLEL: $(TARGETS)
169 # As there is no efficient way to calculate the dependencies of
170 # the targets, we make them dependent on all files. In doing this
171 # we ensure that no rebuild is necessary if nothing has changed
172 $(TARGETS): $(ALL_SRC_FILES)
173 # build-hack-native-deps is a dependency of $(TARGETS) but as it is phony
174 # we place it here to avoid unnecessary rebuilds
175 $(MAKE) build-hack-native-deps build-hhi-archive
176 $(OCAMLBUILD) $(subst $(comma),$(space),$(OCAMLBUILD_FLAGS)) -no-links -cflag -g $(INCLUDE_OPTS) $(LIB_OPTS) \
177 -lflags "-g $(LINKER_FLAGS)" -tag custom \
178 $(patsubst _build/%,%,$(TARGETS))
179 # Touching the targets is necessary because the ocaml build
180 # doesn't change the modification dates of the targets if
181 # the new binaries are exactly the same as the old ones
182 touch $(TARGETS)
184 build-hack-native-deps: $(NATIVE_C_FILES) _build/utils/get_build_id.gen.o
185 $(OCAMLBUILD) $(subst $(comma),$(space),$(OCAMLBUILD_FLAGS)) -cflags "-g $(EXTRA_INCLUDE_OPTS) $(EXTRA_CC_OPTS)" $(OBJECT_FILES_TO_BUILD)
187 .PHONY: _build/utils/get_build_id.gen.c # run every time, depends on git commit
188 _build/utils/get_build_id.gen.c:
189 mkdir -p $(dir $@)
190 cd $(ROOT)/.. && \
191 $(OCAML) -I scripts -w -3 unix.cma scripts/gen_build_id.ml src/_build/utils/get_build_id.gen.c
193 _build/utils/get_build_id.gen.o: _build/utils/get_build_id.gen.c
194 cd $(dir $@) && $(OCAMLC) $(EXTRA_INCLUDE_OPTS) $(EXTRA_CC_OPTS) -c $(notdir $<)
196 build-hhi-archive:
197 mkdir -p ../bin
198 $(MAKE) -C ../hhi
200 copy-hack-files: build-hack
201 mkdir -p ../bin
202 ifeq ($(OS)$(BYTECODE), Linux)
203 objcopy --add-section hhi=../bin/hhi.tar.gz _build/hh_server.$(TARGET_EXT) ../bin/hh_server
204 else
205 cp _build/hh_server.$(TARGET_EXT) ../bin/hh_server
206 endif
207 cp _build/hh_client.$(TARGET_EXT) ../bin/hh_client
208 cp _build/hh_single_type_check.$(TARGET_EXT) ../bin/hh_single_type_check
209 cp _build/hackfmt.$(TARGET_EXT) ../bin/hackfmt
210 cp _build/hh_format.$(TARGET_EXT) ../bin/hh_format
212 copy-hack-files-ocp: build-hack-with-ocp
213 mkdir -p ../bin
214 ifeq ($(OS), Linux)
215 objcopy --add-section hhi=../bin/hhi.tar.gz ../_obuild/hh_server/hh_server.asm ../bin/hh_server
216 else
217 cp ../_obuild/hh_server/hh_server.asm ../bin/hh_server
218 endif
219 cp ../_obuild/hh_client/hh_client.asm ../bin/hh_client
220 cp ../_obuild/hh_single_type_check/hh_single_type_check.asm ../bin/hh_single_type_check
221 cp ../_obuild/hh_format/hackfmt.asm ../bin/hackfmt
222 cp ../_obuild/hh_format/hh_format.asm ../bin/hh_format
224 .PHONY: test test-ocp do-test
225 test: build-hack copy-hack-files
226 ${MAKE} do-test
228 test-ocp: build-hack-with-ocp copy-hack-files-ocp
229 ${MAKE} do-test
231 do-test:
232 python3 ../test/verify.py --program ../bin/hh_single_type_check ../test/autocomplete
233 python3 ../test/verify.py --program ../bin/hh_single_type_check ../test/color
234 python3 ../test/verify.py --program ../bin/hh_single_type_check ../test/colour
235 python3 ../test/verify.py --program ../bin/hh_single_type_check ../test/coverage
236 python3 ../test/verify.py --program ../bin/hh_single_type_check ../test/dumpsymbolinfo
237 python3 ../test/verify.py --program ../bin/hh_single_type_check ../test/dump_inheritance
238 python3 ../test/verify.py --program ../bin/hh_format ../test/format
239 python3 ../test/verify.py --program ../bin/hh_single_type_check ../test/suggest
240 python3 ../test/verify.py --program ../bin/hh_single_type_check ../test/typecheck
241 python3 ../test/verify.py --program ../bin/hh_format ../test/typecheck \
242 --disabled-extension .no_format \
243 --out-extension .format_out \
244 --expect-extension '' \
245 --flags --root .
246 python3 ../test/integration/runner.py ../bin/hh_server ../bin/hh_client