2 #############################################################################
3 # Configuration section
4 #############################################################################
6 -include Makefile.config
8 VERSION
=$(shell cat globals
/config.ml.in |grep version |perl
-p
-e
's/.*"(.*)".*/$$1/;')
9 CCVERSION
=$(shell cat scripts
/coccicheck
/README |grep
"Coccicheck version" |perl
-p
-e
's/.*version (.*)[ ]*/$$1/;')
11 ##############################################################################
13 ##############################################################################
16 SRC
=flag_cocci.ml cocci.ml testing.ml
test.ml main.ml
18 ifeq ($(FEATURE_PYTHON
),1)
19 PYCMA
=pycaml
/pycaml.cma
21 PYLIB
=dllpycaml_stubs.so
22 # the following is essential for Coccinelle to compile under gentoo (weird)
23 OPTLIBFLAGS
=-cclib dllpycaml_stubs.so
31 SEXPSYSCMA
=bigarray.cma nums.cma
33 SYSLIBS
=str.cma unix.cma
$(SEXPSYSCMA
)
34 LIBS
=commons
/commons.cma \
35 ocamlsexp
/sexplib1.cma commons
/commons_sexp.cma \
38 parsing_cocci
/cocci_parser.cma parsing_c
/parsing_c.cma \
39 engine
/cocciengine.cma popl09
/popl.cma \
40 extra
/extra.cma
$(PYCMA
) python
/coccipython.cma
42 #used for clean: and depend: and a little for rec & rec.opt
43 MAKESUBDIRS
=commons ocamlsexp \
44 globals menhirlib
$(PYDIR
) ctl parsing_cocci parsing_c \
45 engine popl09 extra python
46 INCLUDEDIRS
=commons commons
/ocamlextra ocamlsexp \
47 globals menhirlib
$(PYDIR
) ctl \
48 parsing_cocci parsing_c engine popl09 extra python
50 ##############################################################################
52 ##############################################################################
54 INCLUDES
=$(INCLUDEDIRS
:%=-I
%)
57 OPTOBJS
= $(SRC
:.ml
=.cmx
)
61 ##############################################################################
62 # Generic ocaml variables
63 ##############################################################################
65 OCAMLCFLAGS
=# -g -dtypes # -w A
67 # for profiling add -p -inline 0
68 # but 'make forprofiling' below does that for you.
69 # This flag is also used in subdirectories so don't change its name here.
70 # To enable backtrace support for native code, you need to put -g in OPTFLAGS
71 # to also link with -g, but even in 3.11 the backtrace support seems buggy so
74 # the following is essential for Coccinelle to compile under gentoo
75 # but is now defined above in this file
76 #OPTLIBFLAGS=-cclib dllpycaml_stubs.so
78 OCAMLC
=ocamlc
$(OPTBIN
) $(OCAMLCFLAGS
) $(INCLUDES
)
79 OCAMLOPT
=ocamlopt
$(OPTBIN
) $(OPTFLAGS
) $(INCLUDES
)
80 OCAMLLEX
=ocamllex
#-ml # -ml for debugging lexer, but slightly slower
81 OCAMLYACC
=ocamlyacc
-v
82 OCAMLDEP
=ocamldep
$(INCLUDES
)
83 OCAMLMKTOP
=ocamlmktop
-g
-custom
$(INCLUDES
)
85 # can also be set via 'make static'
86 STATIC
= #-ccopt -static
88 # can also be unset via 'make purebytecode'
89 BYTECODE_STATIC
=-custom
91 ##############################################################################
93 ##############################################################################
94 .PHONY
:: all all.opt byte opt top
clean distclean configure
95 .PHONY
:: $(MAKESUBDIRS
) $(MAKESUBDIRS
:%=%.opt
) subdirs subdirs.opt
97 all: Makefile.config byte preinstall
100 all.opt
: opt-compil preinstall
117 $(MAKE
) -C commons OCAMLCFLAGS
="$(OCAMLCFLAGS)"
118 $(MAKE
) -C ocamlsexp OCAMLCFLAGS
="$(OCAMLCFLAGS)"
119 $(MAKE
) -C commons sexp OCAMLCFLAGS
="$(OCAMLCFLAGS)"
120 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D || exit
1 ; done
123 $(MAKE
) -C commons
all.opt OCAMLCFLAGS
="$(OCAMLCFLAGS)"
124 $(MAKE
) -C ocamlsexp
all.opt OCAMLCFLAGS
="$(OCAMLCFLAGS)"
125 $(MAKE
) -C commons sexp.opt OCAMLCFLAGS
="$(OCAMLCFLAGS)"
126 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D.opt || exit
1 ; done
129 $(MAKE
) -C
$@ OCAMLCFLAGS
="$(OCAMLCFLAGS)" all
131 $(MAKESUBDIRS
:%=%.opt
):
132 $(MAKE
) -C
$(@
:%.opt
=%) OCAMLCFLAGS
="$(OCAMLCFLAGS)" all.opt
138 # parsing_cocci: commons globals menhirlib
139 # parsing_c:parsing_cocci
140 # ctl:globals commons
141 # engine: parsing_cocci parsing_c ctl
143 # extra: parsing_cocci parsing_c ctl
145 # python:pycaml parsing_cocci parsing_c
148 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
150 $(LIBS
): $(MAKESUBDIRS
)
151 $(LIBS
:.cma
=.cmxa
): $(MAKESUBDIRS
:%=%.opt
)
154 $(OPTOBJS
):$(LIBS
:.cma
=.cmxa
)
156 $(EXEC
): $(LIBS
) $(OBJS
)
157 $(OCAMLC
) $(BYTECODE_STATIC
) -o
$@
$(SYSLIBS
) $^
159 $(EXEC
).opt
: $(LIBS
:.cma
=.cmxa
) $(OPTOBJS
)
160 $(OCAMLOPT
) $(STATIC
) -o
$@
$(SYSLIBS
:.cma
=.cmxa
) $(OPTLIBFLAGS
) $^
162 $(EXEC
).top
: $(LIBS
) $(OBJS
)
163 $(OCAMLMKTOP
) -custom
-o
$@
$(SYSLIBS
) $^
166 rm -f
$(TARGET
) $(TARGET
).opt
$(TARGET
).top
167 rm -f dllpycaml_stubs.so
169 .PHONY
:: tools configure
175 @echo
"Makefile.config is missing. Have you run ./configure?"
182 $(MAKE
) -C tools
clean
185 rm -f spatch.opt spatch
186 $(MAKE
) STATIC
="-ccopt -static" spatch.opt
190 rm -f spatch.opt spatch
191 $(MAKE
) BYTECODE_STATIC
="" spatch
192 perl
-p
-i
-e
's/^#!.*/#!\/usr\/bin\/ocamlrun/' spatch
195 ##############################################################################
196 # Build documentation
197 ##############################################################################
207 make
-C docs
distclean
209 ##############################################################################
210 # Pre-Install (customization of spatch frontend script)
211 ##############################################################################
213 preinstall
: scripts
/spatch scripts
/spatch.opt scripts
/spatch.byte
215 # user will use spatch to run spatch.opt (native)
217 cp scripts
/spatch.sh scripts
/spatch.tmp2
218 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.tmp2
> scripts
/spatch.tmp
219 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.tmp
> scripts
/spatch
220 rm -f scripts
/spatch.tmp2 scripts
/spatch.tmp
222 # user will use spatch to run spatch (bytecode)
224 cp scripts
/spatch.sh scripts
/spatch.byte.tmp3
225 sed
"s|\.opt||" scripts
/spatch.byte.tmp3
> scripts
/spatch.byte.tmp2
226 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.byte.tmp2 \
227 > scripts
/spatch.byte.tmp
228 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.byte.tmp \
229 > scripts
/spatch.byte
230 rm -f scripts
/spatch.byte.tmp3 \
231 scripts
/spatch.byte.tmp2 \
232 scripts
/spatch.byte.tmp
234 # user will use spatch.opt to run spatch.opt (native)
236 cp scripts
/spatch.sh scripts
/spatch.opt.tmp2
237 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.opt.tmp2 \
238 > scripts
/spatch.opt.tmp
239 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.opt.tmp \
241 rm -f scripts
/spatch.opt.tmp scripts
/spatch.opt.tmp2
244 rm -f scripts
/spatch scripts
/spatch.byte scripts
/spatch.opt
246 ##############################################################################
248 ##############################################################################
250 # don't remove DESTDIR, it can be set by package build system like ebuild
251 # for staged installation.
253 mkdir
-p
$(DESTDIR
)$(BINDIR
)
254 mkdir
-p
$(DESTDIR
)$(LIBDIR
)
255 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)
256 mkdir
-p
$(DESTDIR
)$(MANDIR
)/man1
257 $(INSTALL_DATA
) standard.h
$(DESTDIR
)$(SHAREDIR
)
258 $(INSTALL_DATA
) standard.iso
$(DESTDIR
)$(SHAREDIR
)
259 $(INSTALL_DATA
) docs
/spatch
.1 $(DESTDIR
)$(MANDIR
)/man1
/
260 @if
[ $(FEATURE_PYTHON
) -eq
1 ]; then
$(MAKE
) install-python
; fi
263 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
264 $(INSTALL_DATA
) python
/coccilib
/*.py \
265 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
266 $(INSTALL_DATA
) python
/coccilib
/coccigui
/*.py \
267 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
268 $(INSTALL_DATA
) python
/coccilib
/coccigui
/pygui.glade \
269 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
270 $(INSTALL_DATA
) python
/coccilib
/coccigui
/pygui.gladep \
271 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
272 $(INSTALL_LIB
) dllpycaml_stubs.so
$(DESTDIR
)$(LIBDIR
)
274 install: install-common
275 @if
test -x spatch
-a
! -x spatch.opt
; then \
276 $(MAKE
) install-byte
;fi
277 @if
test ! -x spatch
-a
-x spatch.opt
; then \
278 $(MAKE
) install-def
; $(MAKE
) install-opt
;fi
279 @if
test -x spatch
-a
-x spatch.opt
; then \
280 $(MAKE
) install-byte
; $(MAKE
) install-opt
;fi
281 @if
test ! -x spatch
-a
! -x spatch.opt
; then \
282 echo
"\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
284 @echo
"\tYou can also install spatch by copying the program spatch"
285 @echo
"\t(available in this directory) anywhere you want and"
286 @echo
"\tgive it the right options to find its configuration files."
289 # user will use spatch to run spatch.opt (native)
291 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
292 $(INSTALL_PROGRAM
) scripts
/spatch
$(DESTDIR
)$(BINDIR
)/spatch
294 # user will use spatch to run spatch (bytecode)
296 $(INSTALL_PROGRAM
) spatch
$(DESTDIR
)$(SHAREDIR
)
297 $(INSTALL_PROGRAM
) scripts
/spatch.byte
$(DESTDIR
)$(BINDIR
)/spatch
299 # user will use spatch.opt to run spatch.opt (native)
301 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
302 $(INSTALL_PROGRAM
) scripts
/spatch.opt
$(DESTDIR
)$(BINDIR
)/spatch.opt
305 rm -f
$(DESTDIR
)$(BINDIR
)/spatch
306 rm -f
$(DESTDIR
)$(BINDIR
)/spatch.opt
307 rm -f
$(DESTDIR
)$(LIBDIR
)/dllpycaml_stubs.so
308 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.h
309 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.iso
310 rm -rf
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
311 rm -f
$(DESTDIR
)$(MANDIR
)/man1
/spatch
.1
314 @echo
"spatch $(VERSION)"
315 @echo
"coccicheck $(CCVERSION)"
318 ##############################################################################
320 ##############################################################################
322 PACKAGE
=coccinelle-
$(VERSION
)
323 CCPACKAGE
=coccicheck-
$(CCVERSION
)
325 BINSRC
=spatch env.sh env.csh standard.h standard.iso \
327 docs
/manual
/manual.pdf docs
/manual
/options.pdf docs
/manual
/main_grammar.pdf docs
/spatch
.1 \
328 docs
/manual
/cocci-python.txt \
329 demos
/foo.
* demos
/simple.
*
330 # $(PYLIB) python/coccilib/ demos/printloc.*
331 BINSRC2
=$(BINSRC
:%=$(PACKAGE
)/%)
334 OCAMLVERSION
=$(shell ocaml
-version |perl
-p
-e
's/.*version (.*)/$$1/;')
336 # Procedure to do first time:
338 # cvs checkout coccinelle -dP
341 # Procedure to do each time:
343 # 1) make prepackage # WARN: These will clean your local rep. of pending modifications
345 # UPDATE VERSION number in globals/config.ml.in
350 # The project is then automatically licensified.
352 # Remember to comment the -g -dtypes in this Makefile
353 # You can also remove a few things, for instance I removed in this
354 # Makefile things related to popl/ and popl09/
355 # make sure that ocaml is the distribution ocaml of /usr/bin, not ~pad/...
359 # if WEBSITE is set properly, you can also run 'make website'
360 # Check that run an ocaml in /usr/bin
362 # To test you can try compile and run spatch from different instances
363 # like my ~/coccinelle, ~/release/coccinelle, and the /tmp/coccinelle-0.X
364 # downloaded from the website.
366 # For 'make srctar' it must done from a clean
367 # repo such as ~/release/coccinelle. It must also be a repo where
368 # the scripts/licensify has been run at least once.
369 # For the 'make bintar' I can do it from my original repo.
376 cvs ci
-m
"Release $(VERSION)" globals
/config.ml-in
380 $(MAKE
) distclean # Clean project
382 .
/configure
--without-python
387 $(MAKE
) distclean # Clean project
388 .
/configure
# Reconfigure project with Python support
390 $(MAKE
) bintar-python
391 $(MAKE
) bytecodetar-python
395 # I currently pre-generate the parser so the user does not have to
396 # install menhir on his machine. We could also do a few cleanups.
397 # You may have first to do a 'make licensify'.
399 # update: make docs generates pdf but also some ugly .log files, so
400 # make clean is there to remove them while not removing the pdf
401 # (only distclean remove the pdfs).
406 cp
-a .
$(TMP
)/$(PACKAGE
)
407 cd
$(TMP
)/$(PACKAGE
); cd parsing_cocci
/; make parser_cocci_menhir.ml
408 cd
$(TMP
); tar cvfz
$(PACKAGE
).tgz
--exclude-vcs
$(PACKAGE
)
409 rm -rf
$(TMP
)/$(PACKAGE
)
413 rm -f
$(TMP
)/$(PACKAGE
)
414 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
415 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-x86.tgz
--exclude-vcs
$(BINSRC2
)
416 rm -f
$(TMP
)/$(PACKAGE
)
418 staticbintar
: all.opt
419 rm -f
$(TMP
)/$(PACKAGE
)
420 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
422 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-x86-static.tgz
--exclude-vcs
$(BINSRC2
)
423 rm -f
$(TMP
)/$(PACKAGE
)
425 # add ocaml version in name ?
427 rm -f
$(TMP
)/$(PACKAGE
)
428 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
430 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
).tgz
--exclude-vcs
$(BINSRC2
)
431 rm -f
$(TMP
)/$(PACKAGE
)
434 rm -f
$(TMP
)/$(PACKAGE
)
435 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
436 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-x86-python.tgz
--exclude-vcs
$(BINSRC2
)
437 rm -f
$(TMP
)/$(PACKAGE
)
439 # add ocaml version in name ?
440 bytecodetar-python
: all
441 rm -f
$(TMP
)/$(PACKAGE
)
442 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
444 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
)-python.tgz
--exclude-vcs
$(BINSRC2
)
445 rm -f
$(TMP
)/$(PACKAGE
)
448 cp
-a
`pwd`/scripts
/coccicheck
$(TMP
)/$(CCPACKAGE
)
449 tar cvfz
$(TMP
)/$(CCPACKAGE
).tgz
-C
$(TMP
) --exclude-vcs
$(CCPACKAGE
)
450 rm -rf
$(TMP
)/$(CCPACKAGE
)
453 rm -f
$(TMP
)/$(PACKAGE
).tgz
454 rm -f
$(TMP
)/$(PACKAGE
)-bin-x86.tgz
455 rm -f
$(TMP
)/$(PACKAGE
)-bin-x86-static.tgz
456 rm -f
$(TMP
)/$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
).tgz
457 rm -f
$(TMP
)/$(PACKAGE
)-bin-x86-python.tgz
458 rm -f
$(TMP
)/$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
)-python.tgz
459 rm -f
$(TMP
)/$(CCPACKAGE
).tgz
462 # No need to licensify 'demos'. Because these is basic building blocks
465 TOLICENSIFY
=ctl engine globals parsing_cocci popl popl09 python scripts tools
467 ocaml str.cma tools
/licensify.ml
468 set
-e
; for i in
$(TOLICENSIFY
); do cd
$$i; ocaml str.cma ..
/tools
/licensify.ml
; cd ..
; done
470 # When checking out the source from diku sometimes I have some "X in the future"
473 echo do
'touch **/*.*'
477 # echo do 'rm -rf **/CVS'
480 @echo
$(OCAMLVERSION
)
482 ##############################################################################
484 ##############################################################################
486 -include Makefile.dev
492 .
/$(TARGET
) -D standard.h
-parse_c
-dir tests
/
496 # -inline 0 to see all the functions in the profile.
497 # Can also use the profile framework in commons/ and run your program
500 $(MAKE
) OPTFLAGS
="-p -inline 0 " opt
506 otags
-no-mli-tags
-r .
509 find
-name
"*.ml" |grep
-v
"scripts" | xargs ocamldep
-I commons
-I globals
-I ctl
-I parsing_cocci
-I parsing_c
-I engine
-I popl09
-I extra
> /tmp
/dependfull.depend
510 ocamldot
-lr
/tmp
/dependfull.depend
> /tmp
/dependfull.dot
511 dot
-Tps
/tmp
/dependfull.dot
> /tmp
/dependfull.ps
512 ps2pdf
/tmp
/dependfull.ps
/tmp
/dependfull.pdf
514 ##############################################################################
516 ##############################################################################
518 # each member of the project can have its own test.ml. this file is
521 echo
"let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
524 beforedepend
:: test.ml
527 #INC=$(dir $(shell which ocaml))
530 #INCZ=$(INCY:/=)/lib/ocaml
533 # gcc -c -o prim.o -I $(INCZ) prim.c
536 ##############################################################################
537 # Generic ocaml rules
538 ##############################################################################
540 .SUFFIXES
: .ml .mli .cmo .cmi .cmx
553 rm -f
*.cm
[iox
] *.o
*.annot
554 rm -f
*~ .
*~
*.exe
#*#
557 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
559 rm -f Makefile.config
560 rm -f python
/coccilib
/output.py
561 rm -f python
/pycocci.ml
562 rm -f python
/pycocci_aux.ml
563 rm -f globals
/config.ml
565 rm -f tests
/SCORE_actual.sexp
566 rm -f tests
/SCORE_best_of_both.sexp
567 find
-name
".#*1.*" | xargs
rm -f
571 depend
:: beforedepend
572 $(OCAMLDEP
) *.mli
*.ml
> .depend
573 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
576 @if
[ ! -f .depend
] ; then
$(MAKE
) depend
; fi