Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 205 lines (171 sloc) 6.586 kB
d863cc7 @Aqua-Ye [enhance] all: wip compilation
Aqua-Ye authored
1 #!/usr/bin/env make
fccc685 Initial open-source release
MLstate authored
2
3 # [ Warning ] don't use make to solve dependencies !!
4 #
5 # we rely on ocamlbuild which already handles them ; every rule should
6 # call it only once (more details below)
7
8 #
d863cc7 @Aqua-Ye [enhance] all: wip compilation
Aqua-Ye authored
9 # The Opa build system
fccc685 Initial open-source release
MLstate authored
10 # --------------------
11 #
12 # - it's based on ocamlbuild, the Makefiles are simple wrappers on top of it
13 #
14 # - you should include this Makefile to handle the automatic building of the myocamlbuild extensions
15 #
16 # - this Makefile uses build_rules.ml, build_libs, build_tools to:
17 # - generate the ocamlbuild plugin (target $(MYOCAMLBUILD), run with $(OCAMLBUILD))
18 # - generate Makefile targets:
19 # single tool/lib: <tool>, install-<tool>, <lib>, install-<lib>
20 # all tools/libs: tools, install-tools, libs, install-libs
21 # - generate Makefile variables:
22 # target-tool-<tool> (an ocamlbuild target)
23 # copy-tool-<tool>, install-<tool>, install-<lib> (commands)
24 # lib-cmi-<lib> (all exported modules within the lib)
25 # copy-tool puts the generated tool in its desired directory, under $(BUILD_DIR)
26 #
27 # - we want to call ocamlbuild only once, so you should always factorise your calls,
28 # with something like:
29 # .PHONY: my_final_rule
30 # my_final_rule: $(MYOCAMLBUILD)
31 # $(OCAMLBUILD) $(call target-tools,<my_tools>) $(call target-libs,<my_libs>) <my_other_targets>
32 # @$(call copy-tools,<my_tools>)
33 #
34 # - all targets in here are PHONY, we actually build to $(BUILD_DIR). That's what we
35 # want because it's ocamlbuild that will check if anything needs to be rebuilt.
36 #
37
38 BUILD_DIR ?= _build
d863cc7 @Aqua-Ye [enhance] all: wip compilation
Aqua-Ye authored
39 BLDDIR ?= tools/build
fccc685 Initial open-source release
MLstate authored
40 MYOCAMLBUILD = $(BUILD_DIR)/myocamlbuild
538524f @Aqua-Ye [enhance] ocamlbuild: ability to set OCAMLBUILD_OPT
Aqua-Ye authored
41 OCAMLBUILD = $(MYOCAMLBUILD) -no-plugin $(OCAMLBUILD_OPT) $(OCAMLBUILD_FLAGS)
fccc685 Initial open-source release
MLstate authored
42
43 INSTALL ?= cp -u
44
894a751 @delroth Support make DESTDIR=... install for easier packaging
delroth authored
45 DESTDIR ?=
46 INSTALL_DIR = $(DESTDIR)$(PREFIX)
47 LIB_INSTALL_DIR = $(INSTALL_DIR)/lib/opa/static
fccc685 Initial open-source release
MLstate authored
48
94ed07b @Aqua-Ye [enhance] build: moved config files in tools/build
Aqua-Ye authored
49 CONFIG_PATH = tools/build
50
fccc685 Initial open-source release
MLstate authored
51 .PHONY: clean
e42280b [fix] Makefile: fixed global target clean by introducing '::'
Mathieu Baudet authored
52 clean::
35f0d2e @Aqua-Ye [enhance] Makefile: just clean the content of _build when cleaning
Aqua-Ye authored
53 rm -rf _build/*
fccc685 Initial open-source release
MLstate authored
54
55 .PHONY: distclean
56 distclean: clean
ffa4eed @Aqua-Ye [enhance] Makefile.bld: optim on rm
Aqua-Ye authored
57 rm -f $(CONFIG_PATH)/config.{sh,ml,make,log}
fccc685 Initial open-source release
MLstate authored
58
59
60 -include $(BUILD_DIR)/build_libs.make
61 -include $(BUILD_DIR)/build_tools.make
62
63 ifdef private
64 BUILD_RULES := $(wildcard build_rules*.ml)
65 BUILD_LIBS := $(wildcard build_libs*)
66 BUILD_TOOLS := $(wildcard build_tools*)
67 else
e65d56e @Aqua-Ye [fix] compilation: fix compilation after move
Aqua-Ye authored
68 BUILD_RULES := $(BLDDIR)/build_rules.ml
69 BUILD_LIBS := $(BLDDIR)/build_libs
70 BUILD_TOOLS := $(BLDDIR)/build_tools
fccc685 Initial open-source release
MLstate authored
71 endif
72
94ed07b @Aqua-Ye [enhance] build: moved config files in tools/build
Aqua-Ye authored
73 MYOCAMLBUILD_SOURCES = $(BLDDIR)/gen_myocamlbuild.sh $(BLDDIR)/myocamlbuild_prefix.ml $(BLDDIR)/myocamlbuild_suffix.ml $(CONFIG_PATH)/config.ml $(BUILD_RULES) $(BUILD_LIBS) $(BUILD_TOOLS)
fccc685 Initial open-source release
MLstate authored
74
75 $(MYOCAMLBUILD): $(MYOCAMLBUILD_SOURCES)
76 @echo "Ocamlbuild plugin generation"
77 @$(BLDDIR)/gen_myocamlbuild.sh
78
ebb9f52 [feature] Database: making dblight compilation optional, depending on…
Louis Gesbert authored
79 # arguments: path to cmi file, lib name
80 cmi-in-lib = $(shell grep -si '^\(\([^\#].* \)\? *\|?[^: ]\+:\)$(1)\( \|$$\)' $(2).mllib*)
fccc685 Initial open-source release
MLstate authored
81
ebb9f52 [feature] Database: making dblight compilation optional, depending on…
Louis Gesbert authored
82 # arguments: lib name, directory
fccc685 Initial open-source release
MLstate authored
83 lib-cmi = \
84 $(foreach cmi,$(wildcard $(BUILD_DIR)/$(2)/*.cmi),\
cefbc7e @Aqua-Ye [fix] doc: fix html doc generation
Aqua-Ye authored
85 $(if $(call cmi-in-lib,$(2)/$(notdir $(basename $(cmi))),$(2)),\
fccc685 Initial open-source release
MLstate authored
86 $(cmi:$(BUILD_DIR)/%=%)))
87
88 # Generate a specialised Makefile from build_libs
89 $(BUILD_DIR)/build_libs.make: $(BUILD_LIBS)
90 @mkdir -p $(BUILD_DIR)
91 @awk '/^internal/ { \
92 lib = $$2; libs[i++] = $$2; \
93 dir = $$3 ? $$3 : lib; \
94 printf ".PHONY: %s\n",lib; \
95 printf "%s: $$(MYOCAMLBUILD)\n\t$$(OCAMLBUILD) $$@.cmxa\n",lib; \
96 printf "install-%s:\n\t@$$(install-%s)", lib, lib; \
97 printf "\n"; \
98 printf "lib-cmi-%s = $$(call lib-cmi,%s,%s)\n", lib, lib, dir; \
99 printf "install-%s = mkdir -p $$(LIB_INSTALL_DIR) && ", lib; \
100 printf "$$(INSTALL)"; \
101 printf " $$(addprefix $$(BUILD_DIR)/,%s.$(EXT_LIB) %s.cmxa $$(lib-cmi-%s))", lib, lib, lib; \
102 printf " $$(wildcard $$(BUILD_DIR)/%s/*.*a)", dir; \
103 printf " $$(LIB_INSTALL_DIR)/\n\n"; \
104 } \
105 END { \
106 printf "ALL_LIBS ="; for (i in libs) printf " %s",libs[i]; printf "\n"; \
107 }' \
06441bf @Aqua-Ye [fix] Makefile.bld: prevent awk warning and error on clean
Aqua-Ye authored
108 $(BUILD_LIBS) > $@
fccc685 Initial open-source release
MLstate authored
109
8a40e70 [feature] build: support for optional libraries, enabled libnattraver…
Louis Gesbert authored
110 ALL_LIBS := $(filter-out $(DISABLED_LIBS),$(ALL_LIBS))
111
fccc685 Initial open-source release
MLstate authored
112 target-libs = $(addsuffix .cmxa,$(1))
113
114 .PHONY: libs
115 libs: $(MYOCAMLBUILD)
d863cc7 @Aqua-Ye [enhance] all: wip compilation
Aqua-Ye authored
116 @echo $(ALL_LIBS)
fccc685 Initial open-source release
MLstate authored
117 $(OCAMLBUILD) $(call target-libs,$(ALL_LIBS))
118
119 .PHONY: install-libs
120 install-libs:
121 @$(foreach lib,$(ALL_LIBS),$(install-lib-$(lib));)
122
123 # Generate a specialised Makefile from build_tools
124 $(BUILD_DIR)/build_tools.make: $(BUILD_TOOLS)
125 @mkdir -p $(BUILD_DIR)
126 @awk '/^internal/ && ! /\.(cmx|cmo|o|xml|js)/ { \
127 tool = $$2; tools[i] = tool; \
128 target = $$3; targets[i] = target; \
129 dir = $$4 ? $$4 : "bin"; dirs[i++] = dir; \
130 printf ".PHONY: %s\n", tool; \
131 printf "%s: $$(MYOCAMLBUILD)\n", tool; \
132 printf "\t$$(OCAMLBUILD) %s\n", target; \
133 printf "\t@$$(copy-tool-%s)\n", tool; \
134 printf ".PHONY: install-%s\n", tool; \
135 printf "install-%s:\n\t@$$(install-%s)", tool, tool; \
136 printf "\n"; \
137 printf "target-tool-%s = %s\n", tool, target; \
138 printf "copy-tool-%s = ", tool; \
139 printf "mkdir -p $$(BUILD_DIR)/%s && $$(INSTALL) $$(BUILD_DIR)/%s $$(BUILD_DIR)/%s/%s", \
140 dir, target, dir, tool; \
141 if (dir=="bin") printf " && chmod a+x $$(BUILD_DIR)/%s/%s\n",dir,tool; \
142 else printf "\n"; \
143 printf "install-%s = ", tool; \
894a751 @delroth Support make DESTDIR=... install for easier packaging
delroth authored
144 printf "mkdir -p $$(PREFIX)/%s && $$(INSTALL) $$(BUILD_DIR)/%s/%s $$(INSTALL_DIR)/%s/%s\n", \
fccc685 Initial open-source release
MLstate authored
145 dir, dir, tool, dir, tool; \
146 printf "\n"; \
147 } \
148 END { \
149 printf "ALL_TOOLS ="; for (i in tools) printf " %s",tools[i]; printf "\n"; \
150 }' \
06441bf @Aqua-Ye [fix] Makefile.bld: prevent awk warning and error on clean
Aqua-Ye authored
151 $(BUILD_TOOLS) > $@
fccc685 Initial open-source release
MLstate authored
152
153 target-tools = $(foreach tool,$(1),$(target-tool-$(tool)))
154 copy-tools = $(foreach tool,$(1),$(copy-tool-$(tool));)
155
156 .PHONY: tools
157 tools: $(MYOCAMLBUILD)
d863cc7 @Aqua-Ye [enhance] all: wip compilation
Aqua-Ye authored
158 @echo $(ALL_TOOLS)
fccc685 Initial open-source release
MLstate authored
159 $(OCAMLBUILD) $(call target-tools,$(ALL_TOOLS))
160 @$(call copy-tools,$(ALL_TOOLS))
161
162 .PHONY: install-tools
163 install-tools:
164 $(foreach tool,$(ALL_TOOLS),$(install-tool-$(tool));)
165
166 # some helper bindings
167
168 .PHONY: *.stamp
169 %.stamp: $(MYOCAMLBUILD)
170 $(OCAMLBUILD) $@
171
eb43fc5 @BourgerieQuentin [enhance] build: Added *.oppf to Makefile
BourgerieQuentin authored
172 .PHONY: *.oppf
173 %.oppf: $(MYOCAMLBUILD)
174 $(OCAMLBUILD) $@
175
fccc685 Initial open-source release
MLstate authored
176 .PHONY: *.native
177 %.native: $(MYOCAMLBUILD)
178 $(OCAMLBUILD) $@
179
180 .PHONY: *.cmx
181 %.cmx: $(MYOCAMLBUILD)
182 $(OCAMLBUILD) $@
183
184 .PHONY: *.cma
185 %.cma: $(MYOCAMLBUILD)
186 $(OCAMLBUILD) $@
187
188 # from %.mltop
189 .PHONY: *.top
190 %.top: $(MYOCAMLBUILD)
191 $(OCAMLBUILD) $@
192
193 .PHONY: *.html
194 %.html: $(MYOCAMLBUILD) %.odocl
cefbc7e @Aqua-Ye [fix] doc: fix html doc generation
Aqua-Ye authored
195 $(OCAMLBUILD) $*.docdir/index.html
196 @rm -rf $(BUILD_DIR)/$@
197 @mv $(BUILD_DIR)/$*.docdir $(BUILD_DIR)/$@
fccc685 Initial open-source release
MLstate authored
198
199 .PHONY: *.man
200 %.man: $(MYOCAMLBUILD) %.odocl
201 $(OCAMLBUILD) -tag manpage $*.docdir/man
202 @rm -rf $(BUILD_DIR)/$@
203 @mkdir -p $(BUILD_DIR)/$@
204 @mv $(BUILD_DIR)/$*.docdir $(BUILD_DIR)/$@/man3
Something went wrong with that request. Please try again.