Skip to content
This repository
tag: v3581
Fetching contributors…

Cannot retrieve contributors at this time

file 322 lines (258 sloc) 11.762 kb
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
#!/usr/bin/env make

# [ Warning ] don't use make to solve dependencies !!
#
# we rely on ocamlbuild which already handles them ; every rule should
# call it only once (no recursion)
#
# More info in tools/build/Makefile.bld and tools/build/README

.PHONY: default
default: node

CONFIG_PATH = tools/build

include $(CONFIG_PATH)/config.make

MAKE ?= $_
OCAMLBUILD_OPT ?= -j 6

ifndef NO_REBUILD_OPA_PACKAGES
OPAOPT += --rebuild
endif

ifneq ($(HAS_CAMLIDL)$(HAS_LIBNATPMP)$(HAS_MINIUPNPC),111)
DISABLED_LIBS = libnattraversal
endif

export

include tools/build/Makefile.bld

##
## STANDARD TARGETS
##

.PHONY: node
node: $(MYOCAMLBUILD)
$(OCAMLBUILD) $(call target-tools,$(ALL_TOOLS)) opa-node-packages.stamp
@$(call copy-tools,$(ALL_TOOLS))
$(MAKE) manpages
$(MAKE) $(OPA_TOOLS)

.PHONY: all
all: $(MYOCAMLBUILD)
$(OCAMLBUILD) $(call target-tools,$(ALL_TOOLS)) opa-both-packages.stamp
@$(call copy-tools,$(ALL_TOOLS))
$(MAKE) manpages
$(MAKE) $(OPA_TOOLS)

.PHONY: build
build: all

.PHONY: runtime-libs
runtime-libs: $(MYOCAMLBUILD)
$(OCAMLBUILD) runtime-libs.stamp

.PHONY: $(BUILD_DIR)/bin/opa
$(BUILD_DIR)/bin/opa: $(MYOCAMLBUILD)
$(OCAMLBUILD) opa-node-packages.stamp $(target-tool-opa-bin)
@$(copy-tool-opa-bin)
@tools/utils/install.sh --quiet --dir $(realpath $(BUILD_DIR)) --ocaml-prefix $(OCAMLLIB)/../../..

.PHONY: opa
opa: $(BUILD_DIR)/bin/opa

.PHONY: opa-flat-packages opa-node-packages opa-both-packages
opa-flat-packages: $(MYOCAMLBUILD)
$(OCAMLBUILD) opa-packages.stamp
opa-node-packages: $(MYOCAMLBUILD)
$(OCAMLBUILD) opa-node-packages.stamp
opa-both-packages: $(MYOCAMLBUILD)
$(OCAMLBUILD) opa-both-packages.stamp

.PHONY: stdlib stdlib-flat stdlib-node
stdlib: opa-both-packages
stdlib-flat: opa-flat-packages
stdlib-node: opa-node-packages

DISTRIB_TOOLS = opa-bin opa-plugin-builder-bin opa-plugin-browser-bin bslServerLib.ml # opa-cloud opa-db-server opa-db-tool opatop opa-translate

OPA_TOOLS = opa-create

.PHONY: distrib
distrib: $(MYOCAMLBUILD)
$(OCAMLBUILD) $(call target-tools,$(DISTRIB_TOOLS)) opa-node-packages.stamp
@$(call copy-tools,$(DISTRIB_TOOLS))
@tools/utils/install.sh --quiet --dir $(realpath $(BUILD_DIR)) --ocaml-prefix $(OCAMLLIB)/../../.. --prefix $(realpath $(BUILD_DIR))
$(MAKE) manpages
$(MAKE) $(OPA_TOOLS)

.PHONY: distrib-all
distrib-all: $(MYOCAMLBUILD)
$(OCAMLBUILD) $(call target-tools,$(DISTRIB_TOOLS)) opa-both-packages.stamp
@$(call copy-tools,$(DISTRIB_TOOLS))
$(MAKE) manpages
$(MAKE) $(OPA_TOOLS)

##
## MANPAGES
##

.PHONY: manpages
manpages: $(MYOCAMLBUILD)
ifndef NO_MANPAGES
$(MAKE) -C tools/manpages OCAMLBUILD="$(OCAMLBUILD)" BLDDIR=../../$(BUILD_DIR)
else
@echo "Not building manpages"
endif

##
## OPA-CREATE
##

target-tool-opa-create = tools/opa-create/src/opa-create.exe

.PHONY: opa-create
opa-create: $(MYOCAMLBUILD)
$(OCAMLBUILD) $(target-tool-opa-create)
@mkdir -p $(BUILD_DIR)/bin
$(INSTALL) $(BUILD_DIR)/$(target-tool-opa-create) $(BUILD_DIR)/bin/opa-create
@chmod 755 $(BUILD_DIR)/bin/opa-create

.PHONY: install-opa-create
install-opa-create:
@mkdir -p $(PREFIX)/bin
$(INSTALL) $(BUILD_DIR)/bin/opa-create $(INSTALL_DIR)/bin/opa-create
@chmod 755 $(INSTALL_DIR)/bin/opa-create

##
## INSTALLATION
##

.PHONY: install*

STDLIB_DIR = $(INSTALL_DIR)/lib/opa/stdlib

FLAT_STDLIB_SUFFIX_DIR=stdlib.qmlflat
STDLIB_FLAT_DIR=$(STDLIB_DIR)/$(FLAT_STDLIB_SUFFIX_DIR)
BUILD_FLAT_DIR=$(BUILD_DIR)/$(FLAT_STDLIB_SUFFIX_DIR)
define install-package
@printf "Installing into $(STDLIB_FLAT_DIR)/$*.opx\r"
@mkdir -p "$(STDLIB_FLAT_DIR)/$*.opx/_build"
@find "$(BUILD_FLAT_DIR)/$*.opx" -maxdepth 1 ! -type d -exec $(INSTALL) {} "$(STDLIB_FLAT_DIR)/$*.opx/" \;
@$(INSTALL) $(BUILD_FLAT_DIR)/$*.opx/_build/*.a "$(STDLIB_FLAT_DIR)/$*.opx/_build/"
@$(INSTALL) $(BUILD_FLAT_DIR)/$*.opx/_build/*.cmi "$(STDLIB_FLAT_DIR)/$*.opx/_build/"
@$(INSTALL) $(BUILD_FLAT_DIR)/$*.opx/_build/*.cmxa "$(STDLIB_FLAT_DIR)/$*.opx/_build/"
endef

NODE_STDLIB_SUFFIX_DIR=stdlib.qmljs
STDLIB_NODE_DIR=$(STDLIB_DIR)/$(NODE_STDLIB_SUFFIX_DIR)
BUILD_NODE_DIR=$(BUILD_DIR)/$(NODE_STDLIB_SUFFIX_DIR)
define install-node-package
@printf "Installing into $(STDLIB_NODE_DIR)/$*.opx\r"
@mkdir -p "$(STDLIB_NODE_DIR)/$*.opx/_build"
@find "$(BUILD_NODE_DIR)/$*.opx" -maxdepth 1 ! -type d -exec $(INSTALL) {} "$(STDLIB_NODE_DIR)/$*.opx/" \;
@$(INSTALL) $(BUILD_NODE_DIR)/$*.opx/*.js "$(STDLIB_NODE_DIR)/$*.opx/"
endef

PLUGINS_DIR=lib/plugins
define install-plugin
@printf "Installing into $(STDLIB_DIR)/$*.opp^[[K\r"
@mkdir -p "$(STDLIB_DIR)/$*.opp"
@$(INSTALL) $(BUILD_DIR)/$(PLUGINS_DIR)/$*.opp/*.bypass "$(STDLIB_DIR)/$*.opp/";
@$(if $(wildcard $(BUILD_DIR)/$(PLUGINS_DIR)/$*.opp/*NodeJsPackage.js), $(INSTALL) $(BUILD_DIR)/$(PLUGINS_DIR)/$*.opp/*NodeJsPackage.js "$(STDLIB_DIR)/$*.opp/")
@$(if $(wildcard $(BUILD_DIR)/$(PLUGINS_DIR)/$*.opp/package.json), $(INSTALL) $(BUILD_DIR)/$(PLUGINS_DIR)/$*.opp/package.json "$(STDLIB_DIR)/$*.opp/")
@$(if $(wildcard $(BUILD_DIR)/$(PLUGINS_DIR)/$*.opp/*MLRuntime.*), $(INSTALL) $(BUILD_DIR)/$(PLUGINS_DIR)/$*.opp/*MLRuntime.* "$(STDLIB_DIR)/$*.opp/")
endef


# List all packages and plugins in stdlib
OPA_PACKAGES := $(shell cd lib/stdlib && ./all_packages.sh)
OPA_PLUGINS := $(shell cd lib/stdlib && ./all_plugins.sh && echo "opabsl")

# Rules installing everything that has been compiled
#
# This doesn't rely on install rules generated by Makefile.bld ;
# instead it assumes that what you want to install has been properly
# put in $(BUILD_DIR)/{bin,lib/opa,share/opa,share/man}.
#
# This is the case of tools (because of Makefile.bld),
# and of opa runtime libs (because build rules copy them
# to $(BUILD_DIR)/lib/opa/static).
# This doesn't install the other libs though, use target install-libs
# for that

install-packageopt-%:
$(if $(wildcard $(BUILD_FLAT_DIR)/$*.opx/_build/*),$(install-package))

install-node-packageopt-%:
$(if $(wildcard $(BUILD_NODE_DIR)/$*.opx/*.js),$(install-node-package))

install-package-%:
$(install-package)

install-node-package-%:
$(install-node-package)

install-packages: $(addprefix install-packageopt-,$(OPA_PACKAGES))
@printf "Installation to $(STDLIB_FLAT_DIR) done.\n"

install-node-packages: $(addprefix install-node-packageopt-,$(OPA_PACKAGES))
@printf "Installation to $(STDLIB_NODE_DIR) done.\n"

install-all-packages: $(addprefix install-package-,$(OPA_PACKAGES))
@printf "Installation to $(STDLIB_FLAT_DIR) done.\n"

install-pluginopt-%:
$(if $(wildcard $(BUILD_DIR)/$(PLUGINS_DIR)/$*.opp/),$(install-plugin))

install-plugin-%:
$(install-plugin)

install-plugins: $(addprefix install-pluginopt-,$(OPA_PLUGINS))
@printf "Installation to $(STDLIB_DIR) done.\n"

install-all-plugins: $(addprefix install-plugin-,$(OPA_PLUGINS))
@printf "Installation to $(STDLIB_DIR) done.\n"



install-bin:
@printf "Installing into $(INSTALL_DIR)/bin\r"
@mkdir -p $(INSTALL_DIR)/bin
@$(if $(wildcard $(BUILD_DIR)/bin/*),$(INSTALL) -r $(BUILD_DIR)/bin/* $(INSTALL_DIR)/bin)
@tools/utils/install.sh --quiet --dir $(INSTALL_DIR) --ocamllib $(OCAMLLIB) --ocamlopt $(OCAMLOPT)
@printf "Installation to $(INSTALL_DIR)/bin done.\n"

install-lib:
@printf "Installing into $(INSTALL_DIR)/lib/opa\r"
@rm -f $(BUILD_DIR)/lib/opa/static/opabslMLRuntime.cmi
@mkdir -p $(INSTALL_DIR)/lib/opa
@$(if $(wildcard $(BUILD_DIR)/lib/opa/*),$(INSTALL) -r $(BUILD_DIR)/lib/opa/* $(INSTALL_DIR)/lib/opa/)
@printf "Installation to $(INSTALL_DIR)/lib/opa done.\n"

install-share:
@printf "Installing into $(INSTALL_DIR)/share/opa\r"
@mkdir -p $(INSTALL_DIR)/share/opa
@$(if $(wildcard $(BUILD_DIR)/share/opa/*),$(INSTALL) -r $(BUILD_DIR)/share/opa/* $(INSTALL_DIR)/share/opa/)
@printf "Installation to $(INSTALL_DIR)/share/opa done.\n"

install-man:
@printf "Installing into $(INSTALL_DIR)/share/man\r"
@if [ -d $(BUILD_DIR)/man/man1 ]; then \
mkdir -p $(INSTALL_DIR)/share/man/man1; \
fi
@$(if $(wildcard $(BUILD_DIR)/man/man1/*.1.gz),$(INSTALL) -r $(BUILD_DIR)/man/man1/*.1.gz $(INSTALL_DIR)/share/man/man1)
@printf "Installation to $(INSTALL_DIR)/share/man done.\n"

install: install-bin install-lib install-share install-plugins install-packages install-node-packages install-man
@printf "Installation into $(INSTALL_DIR) done.\n"

install-node: install-bin install-lib install-share install-plugins install-node-packages install-man
@printf "Installation into $(INSTALL_DIR) done.\n"

.PHONY: uninstall
uninstall:
rm -rf $(INSTALL_DIR)/lib/opa
@[ ! -d $(INSTALL_DIR)/lib ] || [ -n "`ls -A $(INSTALL_DIR)/lib`" ] || rmdir $(INSTALL_DIR)/lib
rm -rf $(INSTALL_DIR)/share/opa
rm -rf $(INSTALL_DIR)/share/doc/opa
# TODO: remove all installed opa manpages
# rm -rf $(INSTALL_DIR)/share/man/man1/opa*
@[ ! -d $(INSTALL_DIR)/share ] || [ -n "`ls -A $(INSTALL_DIR)/share`" ] || rmdir $(INSTALL_DIR)/share
$(foreach file,$(wildcard $(BUILD_DIR)/bin/*),rm -f $(INSTALL_DIR)/bin/$(notdir $(file));)
@tools/utils/install.sh --uninstall --dir $(INSTALL_DIR)
@[ ! -d $(INSTALL_DIR)/bin ] || [ -n "`ls -A $(INSTALL_DIR)/bin`" ] || rmdir $(INSTALL_DIR)/bin
@printf "Uninstall done.\n"

# Install our ocamlbuild-generation engine
install-bld:
@mkdir -p $(INSTALL_DIR)/bin
@echo "#!/usr/bin/env bash" > $(INSTALL_DIR)/bin/bld
@echo "set -e" >> $(INSTALL_DIR)/bin/bld
@echo "set -u" >> $(INSTALL_DIR)/bin/bld
@chmod 755 $(INSTALL_DIR)/bin/bld
@echo "BLDDIR=$(PREFIX)/share/opa/bld $(PREFIX)/share/opa/bld/gen_myocamlbuild.sh" >> $(INSTALL_DIR)/bin/bld
@echo "_build/myocamlbuild -no-plugin $(OCAMLBUILD_OPT) \"\$$@\"" >> $(INSTALL_DIR)/bin/bld
@mkdir -p $(INSTALL_DIR)/share/opa/bld
@$(INSTALL) tools/build/gen_myocamlbuild.sh tools/build/myocamlbuild_*fix.ml $(CONFIG_PATH)/config.sh $(CONFIG_PATH)/config.mli $(CONFIG_PATH)/config.ml\
$(INSTALL_DIR)/share/opa/bld

# Install an opa wrapper with different stdlib and options (for some backwards-compatibility)
install-qmlflat: # depends on opabsl_for_compiler, but we don't want to run ocamlbuild twice
@mkdir -p $(INSTALL_DIR)/bin $(INSTALL_DIR)/share/opa/mlstatebsl
@$(INSTALL) $(BUILD_DIR)/$(PLUGINS_DIR)/opabsl.opp/lib/plugins/opabsl/mlstatebsl/opabsl_*.opa $(INSTALL_DIR)/share/opa/mlstatebsl
@echo "#!/usr/bin/env bash" > $(INSTALL_DIR)/bin/qmlflat
@echo "set -e" >> $(INSTALL_DIR)/bin/qmlflat
@echo "set -u" >> $(INSTALL_DIR)/bin/qmlflat
@chmod 755 $(INSTALL_DIR)/bin/qmlflat
@echo 'exec opa --parser classic --no-stdlib --no-server --no-cps --no-closure --no-ei --no-constant-sharing --no-undot --separated off --value-restriction disabled --no-warn duplicateL0 --no-warn typer.warncoerce --no-warn unused --no-discard-of-unused-stdlib --no-warn pattern $(STDLIB_DIR)/opabsl.opp $$(if ! grep -qE "(^| )--no-stdlib( |$$)" <<<"$$*"; then echo $(INSTALL_DIR)/share/opa/mlstatebsl/*.opa; fi) "$$@"' \
>> $(INSTALL_DIR)/bin/qmlflat

# installs some dev tools on top of the normal install; these should not change often
install-all: install install-bld install-qmlflat tools/maxmem
@$(INSTALL) tools/platform_helper.sh $(INSTALL_DIR)/bin/
@$(INSTALL) tools/maxmem $(INSTALL_DIR)/bin/
@rm tools/maxmem
@$(INSTALL) tools/plotmem $(INSTALL_DIR)/bin/

##
## DOCUMENTATION
##
# (in this section, multiple calls to ocamlbuild are tolerated)

.PHONY: doc.jsbsl
doc.jsbsl: $(MYOCAMLBUILD)
$(OCAMLBUILD) $@/index.html

# this rules provides the doc.html target (from Makefile.bld)
# the sed are just there to help sorting by filename-within-directory
.PHONY: doc.odocl
doc.odocl:
echo $(foreach lib,$(ALL_LIBS),$(lib-cmi-$(lib):%.cmi=%)) \
| sed 's# \+#\n#g' \
| sed 's#\(.*\)/\([^/]*\)#\1 \2#' \
| sort -k 2 -u \
| sed 's#\(.*\) \([^ ]*\)#\1/\2#' \
>$@

.PHONY: packages-api
packages-api: $(MYOCAMLBUILD)
OPAOPT="$(OPAOPT) --api --parser classic" $(OCAMLBUILD) opa-node-packages.stamp
Something went wrong with that request. Please try again.