1
# This -*- makefile -*- is part of our build system for OCaml projects
2
# Copyright (C) 2022 Jean-Vincent Loddo
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation, either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
# Makefiles (this one as those in other parts) use extensively the bash shell
26
make -C lib main-no-build
28
find ./lib/_build/ -maxdepth 1 -type f -exec cp -lf {} _build/ \;
32
dune build --always-show-command-line
35
make -C lib/ clean && make all
37
# The main target. Its implementation is entirely project-dependant:
38
main: manually_pre_actions c-modules
42
# The main target. Its implementation is entirely project-dependant:
43
main-dev: manually_pre_actions c-modules
47
#main-no-build: manually_pre_actions c-modules
54
EXCLUDE_FROM_EDITING=-o -name "meta.ml" -o -name "version.ml" -o -name "gui.ml"
55
INCLUDE_FOR_EDITING=-o -name "dune-project" -o -name "Makefile" -o -name "dune"
57
# Edit all ml/mli files and other interesting source files with your $EDITOR
59
test -n "$$EDITOR" && \
60
eval $$EDITOR $$(find . \( -name "_build*" $(EXCLUDE_FROM_EDITING) \) -prune -o -type f -a \( -name "*.ml" -o -name "*.mli" $(INCLUDE_FOR_EDITING) \) -print) &
75
@(dune clean && rm -rf _build/; \
79
# Transmit the information about the compiler version in order to
80
# activate conditional compilation:
81
PP_OPTION = camlp4of -DOCAML4_OR_LATER -DOCAML4_02_OR_LATER -DOCAML4_03_OR_LATER -DOCAML4_04_OR_LATER -DOCAML4_07_OR_LATER
84
C_OBJECTS_TO_LINK = gettext-c-wrapper does-process-exist-c-wrapper waitpid-c-wrapper
85
OTHER_LIBRARY_FILES_TO_INSTALL = _build/{gettext-c-wrapper.o,does-process-exist-c-wrapper.o,gettext_extract_pot_p4.cmo,waitpid-c-wrapper.o,include_type_definitions_p4.cmo,include_as_string_p4.cmo,where_p4.cmo,option_extract_p4.cmo,raise_p4.cmo,log_module_loading_p4.cmo}
87
# Build C modules (no one, by default):
89
@(mkdir _build &> /dev/null || true) && \
90
for x in $(C_OBJECTS_TO_LINK); do \
94
##################################
95
# Manually generated files #
96
# (i.e. not generated with dune) #
97
##################################
101
# foo.byte : manually_pre_actions
102
# foo.native : manually_pre_actions
104
# MANUALLY_PRE_COPY_IN_build = include_as_string_p4.ml USAGE.txt
105
# MANUALLY_PRE_MAKE_IN_build = include_as_string_p4.cmo
107
# _build/include_as_string_p4.cmo: include_as_string_p4.ml
108
# ocamlc -c -I +camlp4 camlp4lib.cma -pp camlp4of -o $@ $<
110
.PHONY : manually_pre_actions
112
################################# PRE-ACTIONS support
114
# Files that must be copied in _build/ *before* the dune processing:
115
MANUALLY_PRE_COPY_IN_build = \
116
GETTEXT/gettext_extract_pot_p4.ml{,i} \
117
GETTEXT/gettext-c-wrapper.c \
118
EXTRA/does-process-exist-c-wrapper.c \
119
EXTRA/waitpid-c-wrapper.c \
120
CAMLP4/include_type_definitions_p4.ml{,i} \
121
CAMLP4/include_as_string_p4.ml{,i} \
122
CAMLP4/where_p4.ml{,i} \
123
CAMLP4/option_extract_p4.ml{,i} \
124
CAMLP4/common_tools_for_preprocessors.ml{,i} \
125
CAMLP4/raise_p4.ml{,i} \
126
CAMLP4/log_module_loading_p4.ml{,i}
128
# Targets that must be created in _build/ *before* the dune processing.
129
# For each foo.bar that appears in this list, you have to write a rule
130
# _build/foo.bar in this Makefile
131
MANUALLY_PRE_MAKE_IN_build = \
132
gettext_extract_pot_p4.cm{i,o} \
133
include_type_definitions_p4.cm{i,o} \
134
include_as_string_p4.cm{i,o} \
136
option_extract_p4.cm{i,o} \
138
log_module_loading_p4.cm{i,o} \
139
libocamlbricks_stubs.a
142
# include_type_definitions_p4
143
_build/include_type_definitions_p4.cmi: CAMLP4/include_type_definitions_p4.mli
144
ocamlc -c -I +camlp4 -pp '$(PP_OPTION)' -o $@ $<
146
_build/include_type_definitions_p4.cmo: CAMLP4/include_type_definitions_p4.ml
147
ocamlc -c -I +camlp4 -I _build/ -pp '$(PP_OPTION)' -o $@ $<
149
# include_as_string_p4
150
_build/include_as_string_p4.cmi: CAMLP4/include_as_string_p4.mli
151
ocamlc -c -I +camlp4 -pp '$(PP_OPTION)' -o $@ $<
153
_build/include_as_string_p4.cmo: CAMLP4/include_as_string_p4.ml
154
ocamlc -c -I +camlp4 -I _build/ -pp '$(PP_OPTION)' -o $@ $<
157
_build/where_p4.cmi: CAMLP4/where_p4.mli
158
ocamlc -c -I +camlp4 -pp camlp4of -o $@ $<
160
_build/where_p4.cmo: CAMLP4/where_p4.ml
161
ocamlc -c -I +camlp4 -I _build/ -pp camlp4of -o $@ $<
164
_build/option_extract_p4.cmi: CAMLP4/option_extract_p4.mli
165
ocamlc -c -I +camlp4 -I _build/ -pp camlp4of -o $@ $<
167
_build/option_extract_p4.cmo: CAMLP4/option_extract_p4.ml
168
ocamlc -c -I +camlp4 -I _build/ -pp camlp4of -o $@ $<
171
_build/raise_p4.cmi: CAMLP4/raise_p4.mli
172
ocamlc -c -I +camlp4 -I _build/ -pp camlp4of -o $@ $<
174
_build/raise_p4.cmo: CAMLP4/raise_p4.ml
175
ocamlc -c -I +camlp4 -I _build/ -pp camlp4of -o $@ $<
177
# log_module_loading_p4
178
_build/log_module_loading_p4.cmi: CAMLP4/log_module_loading_p4.mli
179
ocamlc -c -I +camlp4 -I _build/ -pp camlp4of -o $@ $<
181
_build/log_module_loading_p4.cmo: CAMLP4/log_module_loading_p4.ml
182
ocamlc -c -I +camlp4 -I _build/ -pp camlp4of -o $@ $<
184
# gettext_extract_pot_p4
185
_build/gettext_extract_pot_p4.cmi: $(GETTEXT)/gettext_extract_pot_p4.mli
186
ocamlc -c -I +camlp4 -pp camlp4of camlp4lib.cma -o $@ $<
188
_build/gettext_extract_pot_p4.cmo: $(GETTEXT)/gettext_extract_pot_p4.ml
189
ocamlc -c -I +camlp4 -I _build/ -pp camlp4of camlp4lib.cma -o $@ $<
191
# Compile gettext-c-wrapper.c according to the OCaml version:
192
ccopt_OCAML4_07_OR_LATER := -verbose -ccopt -DOCAML4_07_OR_LATER
195
_build/libocamlbricks_stubs.a: $(GETTEXT)/gettext-c-wrapper.c EXTRA/does-process-exist-c-wrapper.c EXTRA/waitpid-c-wrapper.c
196
@(mkdir _build &> /dev/null || true); \
198
ocamlc -c $(ccopt_OCAML4_07_OR_LATER) $(GETTEXT)/gettext-c-wrapper.c; \
199
ocamlc -c -verbose EXTRA/does-process-exist-c-wrapper.c; \
200
ocamlc -c -verbose EXTRA/waitpid-c-wrapper.c; \
201
ocamlmklib -verbose -oc ocamlbricks_stubs gettext-c-wrapper.o does-process-exist-c-wrapper.o waitpid-c-wrapper.o
204
manually_pre_actions:
205
$(call PERFORM_MANUALLY_PRE_ACTIONS, $(MANUALLY_PRE_COPY_IN_build),$(MANUALLY_PRE_MAKE_IN_build))
207
# Detect if "make clean" is required or copy and build manually targets
208
# specified in MANUALLY_PRE_COPY_IN_build and MANUALLY_PRE_MAKE_IN_build
209
PERFORM_MANUALLY_PRE_ACTIONS = \
211
if test -d _build/; \
213
echo "Checking if files manually copied in _build/ have been modified..."; \
215
echo "Checking \"$$x\"..."; \
216
test ! -f _build/$$x || \
217
diff -q $$x _build/$$x 2>/dev/null || \
218
{ echo -e "********************\nmake clean required!\n********************"; exit 1; } ;\
223
for x in $(1); do echo "Manually pre-copying \"$$x\"..."; cp --parent -f $$x _build/; done; \
224
for y in $(2); do echo "Manually pre-building \"$$y\"..."; make _build/$$y || exit 1; done; \