Debian Codegraph @

Makefile

raw symbols ◀ ▶ SCIP
3 Debian patches touch this file
1 ifneq ($(MAKECMDGOALS),clean)
2 ifneq ($(MAKECMDGOALS),distclean)
3 ifeq ($(wildcard Makefile.config),)
4 ifeq ($(wildcard configure),)
5 $(error To make coccinelle, please run ./autogen and ./configure first)
6 else
7 $(error To make coccinelle, please run ./configure first)
8 endif
9 else
10 include Makefile.libs
11 include Makefile.config
12 endif
13 endif
14 endif
15 -include Makefile.local
16
17 CORE_LIBRARIES := \
18 commons globals parsing_cocci parsing_c
19 LIBRARIES := \
20 $(CORE_LIBRARIES) ctl ocaml python engine popl09 extra
21
22 TOOLS := spatch spgen
23
24 DEPEND_METHOD := multifile
25
26 SOURCES_commons := \
27 ocamlextra/dumper.ml commands.ml common.ml ograph_simple.ml \
28 ograph_extended.ml
29 SOURCES_globals := \
30 cocciconfig.ml flag.ml iteration.ml $(REGEXP_FILE) regexp.ml
31 CLEAN_globals := regexp_pcre.ml regexp_str.ml
32 SOURCES_ctl := \
33 flag_ctl.ml ast_ctl.ml pretty_print_ctl.ml ctl_engine.ml wrapper_ctl.ml
34 SOURCES_parsing_cocci := \
35 flag_parsing_cocci.ml ast_cocci.ml ast0_cocci.ml \
36 pretty_print_cocci.ml visitor_ast0_types.ml \
37 visitor_ast.ml visitor_ast0.ml ast0toast.ml unparse_ast0.ml \
38 unify_ast.ml compute_lines.ml iso_pattern.ml comm_assoc.ml \
39 iso_compile.ml single_statement.ml simple_assignments.ml \
40 get_metas.ml stmtlist.ml top_level.ml \
41 type_infer.ml test_exps.ml unitary_ast0.ml arity.ml index.ml \
42 context_neg.ml adjust_pragmas.ml insert_plus.ml function_prototypes.ml \
43 semantic_cocci.ml data.ml free_vars.ml check_meta.ml safe_for_multi_decls.ml \
44 parse_printf.ml parse_aux.ml cleanup_rules.ml disjdistr.ml \
45 parser_cocci_menhir.mly lexer_cocci.mll \
46 lexer_cli.mll lexer_script.mll \
47 cocci_grep.ml dpll.ml get_constants2.ml id_utils.ml git_grep.ml patch_diff.ml \
48 adjacency.ml commas_on_lists.ml re_constraints.ml parse_cocci.ml \
49 command_line.ml cocci_args.ml
50 SOURCES_parsing_c := \
51 token_annot.ml flag_parsing_c.ml parsing_stat.ml \
52 token_c.ml ast_c.ml includes.ml control_flow_c.ml \
53 visitor_c.ml lib_parsing_c.ml includes_cache.ml pretty_print_c.ml \
54 control_flow_c_build.ml semantic_c.ml lexer_parser.ml parser_c.mly \
55 lexer_c.mll parse_string_c.ml token_helpers.ml token_views_c.ml \
56 cpp_token_c.ml parsing_hacks.ml cpp_analysis_c.ml \
57 unparse_cocci.ml parsing_recovery_c.ml parsing_consistency_c.ml \
58 danger.ml parse_c.ml unparse_c.ml unparse_hrule.ml \
59 type_c.ml cpp_ast_c.ml \
60 type_annoter_c.ml comment_annotater_c.ml \
61 compare_c.ml test_parsing_c.ml
62 SOURCES_ocaml := \
63 externalanalysis.ml \
64 exposed_modules.ml coccilib.ml ocamlcocci_aux.ml $(OCAMLCOCCI_FILE) \
65 prepare_ocamlcocci.ml run_ocamlcocci.ml
66 CLEAN_ocaml := yes_prepare_ocamlcocci.ml no_prepare_ocamlcocci.ml
67 SOURCES_python := \
68 pycocci_aux.ml $(PYCOCCI_FILE) pycocci.ml
69 CLEAN_python := yes_pycocci.ml no_pycocci.ml
70 SOURCES_engine := \
71 flag_matcher.ml lib_engine.ml pretty_print_engine.ml \
72 check_exhaustive_pattern.ml \
73 check_reachability.ml \
74 c_vs_c.ml isomorphisms_c_c.ml \
75 cocci_vs_c.ml pattern_c.ml transformation_c.ml \
76 asttomember.ml asttoctl2.ml ctltotex.ml \
77 postprocess_transinfo.ml ctlcocci_integration.ml
78 SOURCES_popl09 := \
79 ast_popl.ml asttopopl.ml insert_quantifiers.ml \
80 pretty_print_popl.ml flag_popl.ml popltoctl.ml popl.ml
81 SOURCES_extra := \
82 classic_patch.ml kbuild.ml maintainers.ml
83
84 SOURCES_library := \
85 flag_cocci.ml cocci.ml testing.ml read_options.ml enter.ml
86
87 SOURCES_spatch := \
88 $(SOURCES_library) main.ml
89
90 SOURCES_spgen := \
91 globals.ml ast_tostring.ml detect_patch.ml meta_variable.ml \
92 snapshot.ml user_input.ml position_generator.ml disj_generator.ml \
93 rule_body.ml rule_header.ml context_rule.ml script_rule.ml \
94 file_transform.ml spgen_interactive.ml spgen_lexer.mll spgen_config.ml \
95 spgen.ml spgen_test.ml main.ml
96
97 PREFIX_spatch :=
98
99 PREFIX_spgen := tools/spgen/source/
100
101 CORE_LIBS := unix str ocamlcommon \
102 $(STDCOMPATDIR)/stdcompat \
103 $(patsubst %,bytes,$(BYTESDIR)) \
104 $(patsubst %,pcre,$(filter %/pcre.cma,$(LNKLIBS)))
105
106 ifeq ($(OCAMLATLEAST50),no)
107 CORE_LIBS += bigarray
108 endif
109
110 ifeq ($(FEATURE_OCAML),1)
111 CORE_LIBS += dynlink
112 endif
113
114 LIBS_spatch := $(CORE_LIBS) \
115 $(patsubst %,pyml,$(filter %/pyml.cma,$(LNKLIBS)))\
116 $(patsubst %,parmap,$(filter %/parmap.cma,$(LNKLIBS)))
117
118 LIBS_spgen := $(CORE_LIBS)
119
120 LIBRARIES_spatch := $(LIBRARIES)
121
122 LIBRARIES_spgen := $(CORE_LIBRARIES)
123
124 CORE_BUNDLES=stdcompat menhirLib pcre
125
•126 ALL_BUNDLES=
127
128 BUNDLES_spatch=$(ALL_BUNDLES)
129
130 BUNDLES_spgen=$(CORE_BUNDLES)
131
132 SOURCEFILES :=
133
134 define foreach_library
135 SOURCEFILES_$(library) := $(addprefix $(library)/, $(SOURCES_$(library)))
136 CLEANFILES_$(library) := $(addprefix $(library)/, $(CLEAN_$(library)))
137 SOURCEFILES+=$$(SOURCEFILES_$(library))
138 endef
139 $(foreach library,$(LIBRARIES),$(eval $(foreach_library)))
140
141 define foreach_tool
142 SOURCEFILES_$(tool) := $(addprefix $(PREFIX_$(tool)), $(SOURCES_$(tool)))
143 SOURCEFILES+=$$(SOURCEFILES_$(tool))
144 endef
145 $(foreach tool,$(TOOLS),$(eval $(foreach_tool)))
146
147 ifeq ($(MAKECMDGOALS),opt)
148 NATIVE := yes
149 else
150 ifeq ($(MAKECMDGOALS),opt-only)
151 NATIVE := yes
152 else
153 ifeq ($(MAKECMDGOALS),all.opt)
154 NATIVE := yes
155 else
156 ifeq ($(TARGET_SPATCH),byte-only)
157 NATIVE := no
158 else
159 NATIVE := yes
160 endif
161 endif
162 endif
163 endif
164
165 ifeq ($(NATIVE),yes)
166 LIBSUFFIX := .cmxa
167 else
168 LIBSUFFIX := .cma
169 endif
170
171 ifeq ($(NATIVE),yes)
172 TOOLS_SUFFIX := .opt
173 ALL_OBJECTS := cmo cmx
174 else
175 TOOLS_SUFFIX :=
176 ALL_OBJECTS := cmo
177 endif
178
179 EXPOSED_MODULES := \
180 $(shell sed -n 's/^.*(\* \(.*\) \*).*$$/\1/p' ocaml/exposed_modules.ml)
181
182 COMPILED_EXPOSED_MODULES := \
183 $(foreach EXT,cmi $(ALL_OBJECTS),\
184 $(patsubst %,ocaml/%.$(EXT), \
185 $(notdir $(basename $(EXPOSED_MODULES)))))
186
187 SEARCH_PATHS := \
188 commons/ocamlextra $(LIBRARIES) $(PREFIX_spgen) $(PCREDIR) $(PYMLDIR) \
189 $(PARMAPDIR) $(BYTESDIR) $(STDCOMPATDIR)
190
191 ifneq ($(OCAMLATLEAST50),no)
192 SEARCH_PATHS += +str +unix +dynlink
193 endif
194 SEARCH_PATHS += +compiler-libs
195
196 SEARCH_PATH_FLAGS := $(addprefix -I ,$(SEARCH_PATHS))
197
198 CCLIB := $(patsubst %,-cclib -lparmap_stubs,$(filter %/parmap.cma,$(LNKLIBS))) \
199 -cclib -L.
200
201 OCAMLC_CMD := $(OCAMLC) $(SEARCH_PATH_FLAGS) $(CCLIB) $(EXTRA_OCAML_FLAGS)
202
203 OCAMLOPT_CMD := $(OCAMLOPT) $(SEARCH_PATH_FLAGS) $(CCLIB) $(EXTRA_OCAML_FLAGS)
204
205 OCAMLDEP_CMD := $(OCAMLDEP) $(SEARCH_PATH_FLAGS) \
206 $(addprefix -ml-synonym ,.mll .mly) \
207 $(addprefix -mli-synonym ,.ml .mll .mly)
208
209 MENHIR_DEP_CMD := $(MENHIR) --ocamldep "$(OCAMLDEP_CMD)" --depend
210
211 MENHIR_CMD := $(MENHIR) $(MENHIR_FLAGS) --ocamlc "$(OCAMLC_CMD)" --explain --infer
212
213 MENHIR_LIB := \
214 $(addsuffix /menhirLib$(LIBSUFFIX),$(filter %/menhirLib,$(MAKELIBS)))
215 PARMAP_LIB := $(addsuffix /parmap$(LIBSUFFIX),$(filter %/parmap,$(MAKELIBS)))
216 PYML_LIB := $(addsuffix /pyml$(LIBSUFFIX),$(filter %/pyml,$(MAKELIBS)))
217 PCRE_LIB := $(addsuffix /pcre$(LIBSUFFIX),$(filter %/pcre,$(MAKELIBS)))
218 STDCOMPAT_LIB := $(STDCOMPATDIR)/stdcompat$(LIBSUFFIX)
219
220 STDCOMPAT_USERS := parsing_c/type_annoter_c cocci parsing_cocci/check_meta \
221 parsing_cocci/id_utils parsing_cocci/insert_plus \
222 parsing_cocci/lexer_cocci ocaml/yes_prepare_ocamlcocci \
223 tools/spgen/source/user_input tools/spgen/source/spgen_interactive \
224 parsing_c/flag_parsing_c commons/common parsing_cocci/cocci_args
225
226 SHOW_CLEAN := @echo "CLEAN "
227 SHOW_OCAMLC := @echo "OCAMLC "
228 SHOW_OCAMLOPT := @echo "OCAMLOPT "
229
230 ifeq ($(VERBOSE),yes)
231 RUN_OCAMLDEP = $(OCAMLDEP_CMD)
232 RUN_OCAMLC = $(OCAMLC_CMD)
233 RUN_OCAMLC_O = $(OCAMLC_CMD)
234 RUN_OCAMLOPT = $(OCAMLOPT_CMD)
235 RUN_OCAMLOPT_O = $(OCAMLOPT_CMD)
236 RUN_MENHIR = $(MENHIR_CMD)
237 RUN_OCAMLLEX = $(OCAMLLEX)
238 RUN_OCAMLYACC = $(OCAMLYACC)
239 else
240 RUN_OCAMLDEP = @echo "OCAMLDEP $<"; $(OCAMLDEP_CMD)
241 RUN_OCAMLC = $(SHOW_OCAMLC) "$<"; $(OCAMLC_CMD)
242 RUN_OCAMLC_O = $(SHOW_OCAMLC) "-o $@"; $(OCAMLC_CMD)
243 RUN_OCAMLOPT = $(SHOW_OCAMLOPT) "$<"; $(OCAMLOPT_CMD)
244 RUN_OCAMLOPT_O = $(SHOW_OCAMLOPT) "-o $@"; $(OCAMLOPT_CMD)
245 RUN_MENHIR = @echo "MENHIR $<"; $(MENHIR_CMD)
246 RUN_OCAMLLEX = @echo "OCAMLLEX $<"; $(OCAMLLEX)
247 RUN_OCAMLYACC = @echo "OCAMLYACC $<"; $(OCAMLYACC)
248 endif
249
250 MKDIR_P := mkdir -p
251
252 include Makefile.package
253
254 .PHONY : all
255 all : \
256 $(foreach tool,$(TOOLS),$(PREFIX_$(tool))$(tool)$(TOOLS_SUFFIX)) \
257 exposed-modules
258
259 .PHONY : all-dev
260 all-dev : byte-only exposed-modules
261
262 .PHONY : all.opt
263 all.opt : opt-only exposed-modules
264
265 .PHONY : all-release
266 all-release : all.opt docs
267
268 .PHONY : world
269 world : byte-only opt-only exposed-modules docs
270
271 .PHONY : exposed-modules
•272 exposed-modules : $(COMPILED_EXPOSED_MODULES)
273
274 .PHONY : check
275 check : spatch$(TOOLS_SUFFIX)
•276 ./spatch$(TOOLS_SUFFIX) --testall --no-update-score-file
277
278 .PHONY : check-cpp
279 check-cpp:
280 cd cpptests && ../scripts/cpptests.sh
281
282 .PHONY : check-cpp-html
283 check-cpp-html:
284 cd cpptests && ../scripts/cpptests.sh -o cpptests.html
285
286 .PHONY : clean
287 clean :
288 $(SHOW_CLEAN) ".depend"
289 @rm -f .depend
290
291 .PHONY : distclean
292 distclean : clean
293 $(SHOW_CLEAN) "configure"
294 @rm -f configure Makefile.config
295
296 .PHONY : opt-only opt
297 opt-only opt : $(foreach tool,$(TOOLS),$(PREFIX_$(tool))$(tool).opt)
298
299 .PHONY : byt-only byte-only byte
300 byt-only byte-only byte : $(foreach tool,$(TOOLS),$(PREFIX_$(tool))$(tool))
301
302 .PHONY: install
303 install: install-spatch install-spgen install-python install-bash install-man
304
305 .PHONY: install-bash
306 install-bash:
307 if test "x$(BASH_COMPLETION_DIR)" != "xno"; then \
308 $(MKDIR_P) $(DESTDIR)$(BASH_COMPLETION_DIR); \
309 $(INSTALL_DATA) scripts/spatch.bash_completion \
310 $(DESTDIR)$(BASH_COMPLETION_DIR)/spatch; \
311 fi
312
313 .PHONY: install-spatch
314 install-spatch : spatch$(TOOLS_SUFFIX)
315 $(MKDIR_P) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR)
316 $(MKDIR_P) $(DESTDIR)$(LIBDIR)/ocaml
317 if test -f bundles/pyml/dllpyml_stubs.so; then \
318 $(INSTALL_PROGRAM) bundles/pyml/dllpyml_stubs.so \
319 $(DESTDIR)$(LIBDIR); \
320 fi
321 if test -f bundles/pcre/dllpcre_stubs.so; then \
322 $(INSTALL_PROGRAM) bundles/pcre/dllpcre_stubs.so \
323 $(DESTDIR)$(LIBDIR); \
324 fi
325 $(INSTALL_PROGRAM) spatch$(TOOLS_SUFFIX) $(DESTDIR)$(BINDIR)/spatch
326 $(INSTALL_DATA) standard.h $(DESTDIR)$(LIBDIR)
327 $(INSTALL_DATA) standard.iso $(DESTDIR)$(LIBDIR)
328 $(INSTALL_DATA) ocaml/*.cmi $(DESTDIR)$(LIBDIR)/ocaml/
329 if test -f ocaml/coccilib.cmx; then \
330 $(INSTALL_DATA) ocaml/*.cmx $(DESTDIR)$(LIBDIR)/ocaml/; \
331 fi
332
333 .PHONY : install-man
334 install-man :
335 $(MKDIR_P) $(DESTDIR)$(MANDIR)/man1
336 $(MKDIR_P) $(DESTDIR)$(MANDIR)/man3
337 $(INSTALL_DATA) docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
338 $(INSTALL_DATA) docs/pycocci.1 $(DESTDIR)$(MANDIR)/man1/
339 $(INSTALL_DATA) docs/spgen.1 $(DESTDIR)$(MANDIR)/man1/
340 $(INSTALL_DATA) docs/Coccilib.3cocci $(DESTDIR)$(MANDIR)/man3/
341
342 .PHONY : install-spgen
343 install-spgen : tools/spgen/source/spgen$(TOOLS_SUFFIX)
344 $(INSTALL_PROGRAM) tools/spgen/source/spgen$(TOOLS_SUFFIX) \
345 $(DESTDIR)$(BINDIR)/spgen
346
347 .PHONY : install-python
348 install-python:
349 $(MKDIR_P) $(DESTDIR)$(LIBDIR)/python/coccilib
350 $(INSTALL_DATA) python/coccilib/*.py \
351 $(DESTDIR)$(LIBDIR)/python/coccilib
352
353 .PHONY : uninstall
354 uninstall : uninstall-bash
355 rm -f $(DESTDIR)$(BINDIR)/spatch
356 rm -f $(DESTDIR)$(BINDIR)/spatch.opt
357 rm -f $(DESTDIR)$(BINDIR)/spatch.byte
358
359 .PHONY : uninstall-bash
360 uninstall-bash :
361 rm -f $(DESTDIR)$(BASH_COMPLETION_DIR)/spatch
362 rmdir --ignore-fail-on-non-empty -p \
363 $(DESTDIR)$(BASH_COMPLETION_DIR)
364
365 ml_files_but_parsers := \
366 $(filter %.ml,$(SOURCEFILES)) \
367 $(patsubst %.mll,%.ml,$(filter %.mll,$(SOURCEFILES)))
368
369 .PHONY : docs
370 docs :
371 -$(MAKE) -C docs
372 -$(MAKE) docs -C tools/spgen/documentation
373
374 .PHONY : mlis
375 mlis : $(patsubst %.ml,%.mli,$(ml_files_but_parsers))
376
377 define foreach_ml_files_but_parsers
378 ifeq ($(wildcard $(sourcefile:.ml=.mli)),)
379 $(sourcefile:.ml=.mli) : $(sourcefile)
380 $(OCAMLC_CMD) -i $$< >$$@ || (rm $$@; false)
381 endif
382 endef
383 #$(foreach sourcefile,$(ml_files_but_parsers),\
384 # $(eval $(foreach_ml_files_but_parsers)))
385
386 %.ml.d : %.ml
387 $(RUN_OCAMLDEP) $< >$@ || (rm $@; false)
388
389 %.mli.d : %.mli
390 $(RUN_OCAMLDEP) $< >$@ || (rm $@; false)
391
392 %.ml : %.mll
393 $(RUN_OCAMLLEX) $<
394
395 ml_files_but_menhir := $(ml_files_but_parsers) parsing_c/parser_c.ml
396 ml_files := $(ml_files_but_menhir) parsing_cocci/parser_cocci_menhir.ml coccinelle.ml
397 ml_and_mli_files_but_menhir := $(ml_files_but_menhir) $(ml_files_but_menhir:.ml=.mli)
398
399 ifneq ($(MAKECMDGOALS),clean)
400 ifneq ($(MAKECMDGOALS),distclean)
401 ifeq ($(DEPEND_METHOD),onefile)
402 .depend : $(ml_and_mli_files_but_menhir) parsing_cocci/parser_cocci_menhir.mly $(MENHIR)
403 @echo OCAMLDEP .depend
404 @$(OCAMLDEP_CMD) $(ml_and_mli_files_but_menhir) >$@ || (rm $@; false)
405 @$(MENHIR_DEP_CMD) parsing_cocci/parser_cocci_menhir.mly >>$@ \
406 || (rm $@; false)
407
408 -include .depend
409 else ifeq ($(DEPEND_METHOD),multifile)
410 -include $(addsuffix .d,$(ml_and_mli_files_but_menhir))
411 -include parsing_cocci/parser_cocci_menhir.mly.d
412 else
413 $(error DEPEND_METHOD is expected to be 'onefile' or 'multifile',\
414 but got $(DEPEND_METHOD))
415 endif
416 endif
417 endif
418
419 define foreach_ml_files
420 ifeq ($(DEPEND_METHOD),onefile)
421 $(sourcefile:.ml=.cmi) : $(sourcefile:.ml=.mli) .depend
422 $$(RUN_OCAMLC) -c $$<
423
424 $(sourcefile:.ml=.cmo) : $(sourcefile) .depend
425 $$(RUN_OCAMLC) -for-pack Coccinelle_modules -c $$<
426
427 $(sourcefile:.ml=.cmx) : $(sourcefile) .depend
428 $$(RUN_OCAMLOPT) -for-pack Coccinelle_modules -c $$<
429 else
430 $(sourcefile:.ml=.cmi) : $(sourcefile:.ml=.mli) $(sourcefile:.ml=.mli.d)
431 $$(RUN_OCAMLC) -c $$<
432
433 $(sourcefile:.ml=.cmo) : $(sourcefile) $(sourcefile:.ml=.ml.d)
434 $$(RUN_OCAMLC) -for-pack Coccinelle_modules -c $$<
435
436 $(sourcefile:.ml=.cmx) : $(sourcefile) $(sourcefile:.ml=.ml.d)
437 $$(RUN_OCAMLOPT) -for-pack Coccinelle_modules -c $$<
438 endif
439 endef
440 $(foreach sourcefile,$(ml_files),\
441 $(eval $(foreach_ml_files)))
442
443 ## Parser_c
444
445 parsing_c/parser_c.ml : parsing_c/parser_c.mly
446 $(RUN_OCAMLYACC) $<
447 parsing_c/parser_c.mli : parsing_c/parser_c.ml
448
449 ## Parser_cocci_menhir
450
451 parsing_cocci/parser_cocci_menhir.mly.d : \
452 parsing_cocci/parser_cocci_menhir.mly $(MENHIR)
453 $(MENHIR_DEP_CMD) $< >$@ || (rm $@; false)
454
455 ifeq ($(DEPEND_METHOD),onefile)
456 parsing_cocci/parser_cocci_menhir.ml : \
457 parsing_cocci/parser_cocci_menhir.mly \
458 .depend \
459 $(MENHIR)
460 # bundles-menhirLib$(TOOLS_SUFFIX)-if-needed
461 $(RUN_MENHIR) $<
462 else
463 parsing_cocci/parser_cocci_menhir.ml : \
464 parsing_cocci/parser_cocci_menhir.mly \
465 parsing_cocci/parser_cocci_menhir.mly.d
466 # bundles-menhirLib$(TOOLS_SUFFIX)-if-needed
467 $(RUN_MENHIR) $<
468 endif
469 parsing_cocci/parser_cocci_menhir.mli : parsing_cocci/parser_cocci_menhir.ml
470
471 ## Bundles
472
473 ifneq ($(MENHIR_LIB),)
474 ifeq ($(NATIVE),yes)
475 $(MENHIR): $(STDCOMPAT_LIB)
476 $(MAKE) -C bundles/menhirLib all
477 $(MAKE) -C bundles/menhirLib all.opt
478 else
479 $(MENHIR): $(STDCOMPAT_LIB)
480 $(MAKE) -C bundles/menhirLib all
481 endif
482 endif
483
484 ifneq ($(PARMAP_LIB),)
485 ifeq ($(NATIVE),yes)
486 $(PARMAP_LIB): $(STDCOMPAT_LIB)
487 $(MAKE) -C bundles/parmap all
488 $(MAKE) -C bundles/parmap all.opt
489 else
490 $(PARMAP_LIB): $(STDCOMPAT_LIB)
491 $(MAKE) -C bundles/parmap all
492 endif
493 endif
494
495 ifneq ($(PYML_LIB),)
496 ifeq ($(NATIVE),yes)
497 $(PYML_LIB): $(STDCOMPAT_LIB)
498 $(MAKE) -C bundles/pyml all
499 $(MAKE) -C bundles/pyml all.opt
500 else
501 $(PYML_LIB): $(STDCOMPAT_LIB)
502 $(MAKE) -C bundles/pyml all
503 endif
504 endif
505
506 ifneq ($(PCRE_LIB),)
507 ifeq ($(NATIVE),yes)
508 $(PCRE_LIB): $(STDCOMPAT_LIB)
509 $(MAKE) -C bundles/pcre all
510 $(MAKE) -C bundles/pcre all.opt
511 else
512 $(PCRE_LIB): $(STDCOMPAT_LIB)
513 $(MAKE) -C bundles/pcre all
514 endif
515 endif
516
517 $(STDCOMPAT_LIB):
518 $(MAKE) -C bundles/stdcompat all
519
520 # For each $(bundle), targets bundles-$(bundle), bundles-$(bundle).opt,
521 # and clean-$(bundle) are defined. The targets bundles, bundles.opt and
522 # clean-bundles run all of them.
523
524 .PHONY : bundles
525 bundles : $(ALL_BUNDLES:%=bundles-%-if-needed)
526
527 .PHONY : bundles.opt
528 bundles.opt : $(ALL_BUNDLES:%=bundles-%.opt-if-needed)
529
530 .PHONY : clean-bundles
531 clean-bundles : $(ALL_BUNDLES:%=clean-%)
532
533 .PHONY : distclean-bundles
534 distclean-bundles : $(ALL_BUNDLES:%=clean-%)
535
536 define foreach_bundle
537 .PHONY : bundles-$(bundle)
538 bundles-$(bundle) :
539 $(MAKE) -C bundles/$(bundle) all
540
541 ifeq ($(bundle),stdcompat)
542 .PHONY : bundles-stdcompat.opt
543 bundles-stdcompat.opt :
544 $(MAKE) -C bundles/stdcompat all
545
546 .PHONY : distclean-stdcompat
547 distclean-stdcompat :
548 $(MAKE) -C bundles/stdcompat clean
549 else
550 .PHONY : bundles-$(bundle).opt
551 bundles-$(bundle).opt :
552 $(MAKE) -C bundles/$(bundle) all.opt
553
554 .PHONY : distclean-$(bundle)
555 distclean-$(bundle) :
556 $(MAKE) -C bundles/$(bundle) distclean
557 endif
558
559 .PHONY : bundles-$(bundle)-if-needed
560 bundles-$(bundle)-if-needed : \
561 $(patsubst %,bundles-$(bundle),$(filter %/$(bundle)/,$(MAKELIBS)))
562
563 .PHONY : bundles-$(bundle).opt-if-needed
564 bundles-$(bundle).opt-if-needed : \
565 $(patsubst %,bundles-$(bundle).opt,$(filter %/$(bundle)/,$(MAKELIBS)))
566
567 .PHONY : clean-$(bundle)
568 clean-$(bundle) :
569 $(MAKE) -C bundles/$(bundle) clean
570
571 clean : clean-$(bundle)
572 distclean : distclean-$(bundle)
573 endef
574 $(foreach bundle,$(ALL_BUNDLES),$(eval $(foreach_bundle)))
575
576 $(STDCOMPAT_USERS:=.cmo) $(STDCOMPAT_USERS:=.cmx) : $(STDCOMPAT_LIB)
577
578 main.cmo : $(PARMAP_LIB)
579 main.cmx : $(PARMAP_LIB)
580
581 parsing_c/includes.cmo : $(PARMAP_LIB)
582 parsing_c/includes.cmx : $(PARMAP_LIB)
583
584 python/yes_pycocci.cmi : $(PYML_LIB)
585 python/yes_pycocci.cmo : $(PYML_LIB)
586 python/yes_pycocci.cmx : $(PYML_LIB)
587
588 globals/regexp_pcre.cmi : $(PCRE_LIB)
589 globals/regexp_pcre.cmo : $(PCRE_LIB)
590 globals/regexp_pcre.cmx : $(PCRE_LIB)
591
592 ## Libraries
593
594 clean_sourcefile=$(foreach ext,cmi cmo cmx cmt cmti o ml.d mli.d,\
595 $(basename $(sourcefile)).$(ext))
596
597 define foreach_library
598 clean : clean-$(library)
599
600 .PHONY : clean-$(library)
601 clean-$(library) :
602 $(SHOW_CLEAN) "$(library)"
603 @rm -f $(library)/$(library).cma $(library)/$(library).cmxa \
604 $(library)/$(library).a \
605 $(foreach sourcefile,$(SOURCEFILES_$(library)),\
606 $(clean_sourcefile)) \
607 $(patsubst %.mll,%.ml,$(filter %.mll,\
608 $(SOURCEFILES_$(library)))) \
609 $(patsubst %.mly,%.ml,$(filter %.mly,\
610 $(SOURCEFILES_$(library)))) \
611 $(patsubst %.mly,%.mli,$(filter %.mly,\
612 $(SOURCEFILES_$(library)))) \
613 $(foreach sourcefile,$(CLEANFILES_$(library)),\
614 $(clean_sourcefile))
615
616 $(library)/$(library).cmxa : \
617 $(addsuffix .cmx,$(basename $(SOURCEFILES_$(library))))
618 $$(RUN_OCAMLOPT_O) -a $$^ -o $$@
619
620 $(library)/$(library).cma : \
621 $(addsuffix .cmo,$(basename $(SOURCEFILES_$(library))))
622 $$(RUN_OCAMLC_O) -a $$^ -o $$@
623
624 .PHONY: $(library)
625 ifeq ($(NATIVE),yes)
626 $(library): $(library)/$(library).cmxa
627 else
628 $(library): $(library)/$(library).cma
629 endif
630 endef
631 $(foreach library,$(LIBRARIES),$(eval $(foreach_library)))
632
633 define foreach_tool
634 clean : clean-$(tool)
635
636 .PHONY : clean-$(tool)
637 clean-$(tool) :
638 $(SHOW_CLEAN) "$(tool)"
639 @rm -f $(PREFIX_$(tool))$(tool) $(PREFIX_$(tool))$(tool).opt \
640 $(foreach sourcefile,$(SOURCEFILES_$(tool)),$(clean_sourcefile))
641
642 $(PREFIX_$(tool))$(tool) : \
643 $(foreach library,$(LIBRARIES_$(tool)),\
644 $(library)/$(library).cma) \
645 $(addsuffix .cmo,$(basename $(SOURCEFILES_$(tool))))
646 $$(RUN_OCAMLC_O) -custom $(LINK_BYTECODE) $(LIBS_$(tool):=.cma) $$^ -o $$@
647
648 $(PREFIX_$(tool))$(tool).opt : \
649 $(foreach library,$(LIBRARIES_$(tool)),\
650 $(library)/$(library).cmxa) \
651 $(addsuffix .cmx,$(basename $(SOURCEFILES_$(tool))))
652 $$(RUN_OCAMLOPT_O) $(LINK_NATIVE) $(LIBS_$(tool):=.cmxa) $$^ -o $$@
653 endef
654 $(foreach tool,$(TOOLS),$(eval $(foreach_tool)))
655
656 define copy_exposed_module
657 ocaml/$(notdir $(basename $(module))).$(EXT) : $(basename $(module)).$(EXT)
658 cp $$< $$@
659 endef
660
661 $(foreach module,$(basename $(EXPOSED_MODULES)),\
662 $(foreach EXT,cmi $(ALL_OBJECTS),$(eval $(copy_exposed_module))))
663
664 ocaml/parmap.cmi : $(PARMAP_LIB)
665 cp $(PARMAPDIR)/parmap.cmi $@
666 if test -f $(PARMAPDIR)/parmap.cmx; then \
667 cp $(PARMAPDIR)/parmap.cmx ocaml/parmap.cmx; \
668 fi
669
670 clean : clean-exposed-module
671
672 .PHONY : clean-exposed-module
673 clean-exposed-module :
674 $(SHOW_CLEAN) "exposed-module"
675 @rm -f $(foreach module,$(basename $(EXPOSED_MODULES)),\
676 $(foreach EXT,cmi $(ALL_OBJECTS),\
677 ocaml/$(notdir $(basename $(module))).$(EXT)))
678 @rm -f ocaml/parmap.cmi ocaml/parmap.cmx
679
680 # Coccinelle as library
681
682 library_all_sources := \
683 $(foreach library,$(LIBRARIES_spatch),$(SOURCEFILES_$(library))) \
684 $(SOURCEFILES_spatch)
685
686 coccinelle_modules.cmo : $(addsuffix .cmo,$(basename $(library_all_sources)))
687 $(RUN_OCAMLC_O) -pack $^ -o $@
688
689 coccinelle_modules.cmx : $(addsuffix .cmx,$(basename $(library_all_sources)))
690 $(RUN_OCAMLOPT_O) -pack $^ -o $@
691
692 coccinelle.cmo coccinelle.cmx : coccinelle.cmi
693
694 coccinelle.cmo : coccinelle_modules.cmo
695
696 coccinelle.cmx : coccinelle_modules.cmx
697
698 coccinelle.cma : coccinelle_modules.cmo coccinelle.cmo
699 $(RUN_OCAMLC_O) -a $^ -o $@
700
701 coccinelle.cmxa : coccinelle_modules.cmx coccinelle.cmx
702 $(RUN_OCAMLOPT_O) -a $^ -o $@
703
704 clean : clean-library
705
706 .PHONY : clean-library
707 clean-library :
708 rm -f coccinelle.cma coccinelle.cmxa coccinelle.a \
709 coccinelle.cmo coccinelle.cmx coccinelle.o \
710 coccinelle_modules.cmi coccinelle_modules.cmo \
711 coccinelle_modules.o coccinelle_modules.cmx