summaryrefslogtreecommitdiff
path: root/cil/Makefile.in
blob: a16d60cf1aa35b15cc7956a2117eee023af49ed0 (plain)
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
# -*- Mode: makefile -*- 

# Makefile for the cil wrapper
# @do_not_edit@ Makefile.in
#
# author: George Necula

#
# If you want to add extra CIL features, you do not always need to change 
# this file. Just invoke 
#        ./configure EXTRASRCDIRS=/home/foodir EXTRAFEATURES="foo bar"
# This will add two features that must be defined in foo.ml and bar.ml
# 

# Debugging. Set ECHO= to debug this Makefile 
.PHONY: setup quickbuild doc distrib machdep cilversion
ECHO = @

# It is important to build quickbuild first, to generate the proper dependencies
all:  quickbuild setup

# Now add the defines for the CIL features
@CIL_FEATURES_DEFINES@


# look out for outdated Makefile; if it's out of date, this will automatically
# re-run ./config.status, then re-exec make with the same arguments
Makefile: config.status Makefile.in 
	./$<

config.status: configure
	./$@ --recheck

configure: configure.in
	autoconf

ocamlutil/perfcount.c: config.status ocamlutil/perfcount.c.in
	./$<

@DEFAULT_COMPILER@=1



ifdef RELEASE
  NATIVECAML := 1
  UNSAFE     := 1
endif

ifndef ARCHOS
   ARCHOS=@ARCHOS@
endif

# Put here all the byproducts of make
OBJDIR      := obj/$(ARCHOS)
DEPENDDIR   := obj/.depend

CILLY_FEATURES :=
ifdef USE_BLOCKINGGRAPH
  CILLY_FEATURES += blockinggraph
endif
ifdef USE_RAND
  CILLY_FEATURES += rand
endif
ifdef USE_ARITHABS
  CILLY_FEATURES += arithabs
endif
ifdef USE_SMALLOC
  CILLY_FEATURES += smalloc
endif
ifdef USE_CQUALANN
  CILLY_FEATURES += cqualann
endif
ifdef USE_ZRAPP
  CILLY_FEATURES += rmciltmps zrapp
endif
# Add the EXTRAFEATURES
CILLY_FEATURES += @EXTRAFEATURES@

    # Now rules to make cilly
CILLY_LIBRARY_MODULES = pretty inthash errormsg alpha trace stats util clist \
              cilutil escape growArray\
              cabs cabsvisit cprint lexerhack machdep cparser clexer  \
              cilversion cil cillower formatparse formatlex formatcil cabs2cil \
              patch frontc check mergecil \
              dataflow dominators bitmap ssa ciltools \
              usedef logcalls logwrites rmtmps \
	      callgraph epicenter heapify \
              setp uref olf ptranal \
              canonicalize heap oneret partial simplemem simplify \
	      dataslicing sfi \
              cfg reachingdefs deadcodeelim availexps \
              liveness \
              testcil \
	      $(CILLY_FEATURES) \
	      ciloptions feature_config
# ww: we don't want "main" in an external cil library (cil.cma),
# otherwise every program that links against that library will get
# main's argument checking and whatnot ...
CILLY_MODULES = $(CILLY_LIBRARY_MODULES) main
CILLY_CMODULES =
CILLY_LIBS     = unix str

SOURCEDIRS  += src src/frontc src/ext src/ext/pta ocamlutil @EXTRASRCDIRS@
MLLS        += clexer.mll formatlex.mll
MLYS        += cparser.mly formatparse.mly
MODULES     += $(CILLY_MODULES) libmaincil



    # Include now the common set of rules for OCAML
include ocamlutil/Makefile.ocaml


   # Now the rule to make cilly

PROJECT_EXECUTABLE = $(OBJDIR)/cilly$(EXE)
PROJECT_MODULES    = $(CILLY_MODULES)
PROJECT_CMODULES   = perfcount $(CILLY_CMODULES)
PROJECT_LIBS       = $(CILLY_LIBS)
cilly: $(PROJECT_EXECUTABLE)
include ocamlutil/Makefile.ocaml.build


quickbuild: cilversion machdep cilly

# Setup also makes the native code versions
#
# sm: cillib is only built with NATIVECAML=1 because it builds libcil.a,
# which requires native-code .cmx compiled modules... could break it
# into two targets so we build cil.cma both ways, but no one is using
# cil.cma now so I'll leave it alone
setup: cilversion machdep
	$(MAKE) cilly NATIVECAML= 
	$(MAKE) cilly NATIVECAML=1
	$(MAKE) cillib NATIVECAML=
	$(MAKE) cillib NATIVECAML=1

# Create the machine dependency module
# If the cl command cannot be run then the MSVC part will be identical to GCC
.PHONY : machdep 
machdep: $(OBJDIR)/machdep.ml 
$(OBJDIR)/machdep.ml : src/machdep.c configure.in Makefile.in
	rm -f $@
	echo "(* This module was generated automatically by code in Makefile and machdep.c *)" >$@
# Now generate the type definition
	echo "type mach = {" >> $@ 
	echo "  version_major: int;     (* Major version number *)"    >> $@
	echo "  version_minor: int;     (* Minor version number *)"    >> $@
	echo "  version: string;        (* version number *)"          >> $@
	echo "  underscore_name: bool;  (* If assembly names have leading underscore *)" >> $@
	echo "  sizeof_short: int;      (* Size of \"short\" *)"       >> $@
	echo "  sizeof_int: int;        (* Size of \"int\" *)"         >> $@
	echo "  sizeof_long: int ;      (* Size of \"long\" *)"        >> $@
	echo "  sizeof_longlong: int;   (* Size of \"long long\" *)"   >> $@
	echo "  sizeof_ptr: int;        (* Size of pointers *)"        >> $@
	echo "  sizeof_enum: int;       (* Size of enum types *)"      >> $@
	echo "  sizeof_float: int;      (* Size of \"float\" *)"       >> $@
	echo "  sizeof_double: int;     (* Size of \"double\" *)"      >> $@
	echo "  sizeof_longdouble: int; (* Size of \"long double\" *)" >> $@
	echo "  sizeof_sizeof: int;     (* Size of \"sizeof(T)\" *)"   >> $@
	echo "  sizeof_wchar: int;      (* Size of \"wchar_t\" *)"     >> $@ 
	echo "  sizeof_void: int;       (* Size of \"void\" *)"        >> $@
	echo "  sizeof_fun: int;        (* Size of function *)"        >> $@
	echo "  alignof_short: int;     (* Alignment of \"short\" *)"  >> $@
	echo "  alignof_int: int;       (* Alignment of \"int\" *)"    >> $@
	echo "  alignof_long: int;      (* Alignment of \"long\" *)"   >> $@
	echo "  alignof_longlong: int;  (* Alignment of \"long long\" *)" >> $@
	echo "  alignof_ptr: int;       (* Alignment of pointers *)"   >> $@
	echo "  alignof_enum: int;      (* Alignment of enum types *)" >> $@
	echo "  alignof_float: int;     (* Alignment of \"float\" *)"  >> $@
	echo "  alignof_double: int;    (* Alignment of \"double\" *)" >> $@
	echo "  alignof_longdouble: int;  (* Alignment of \"long double\" *)" >> $@
	echo "  alignof_str: int;       (* Alignment of strings *)" >> $@
	echo "  alignof_fun: int;       (* Alignment of function *)" >> $@
	echo "  char_is_unsigned: bool; (* Whether \"char\" is unsigned *)">> $@
	echo "  const_string_literals: bool; (* Whether string literals have const chars *)">> $@
	echo "  little_endian: bool; (* whether the machine is little endian *)">>$@
	echo "}" >> $@ 	
	if gcc -D_GNUCC $< -o $(OBJDIR)/machdep.exe ;then \
	    echo "machdep.exe created succesfull." \
	;else \
            rm -f $@; exit 1 \
        ;fi 
	echo "let gcc = {" >>$@
	$(OBJDIR)/machdep.exe >>$@
	echo "	 underscore_name = @UNDERSCORE_NAME@ ;" >> $@
	echo "}"          >>$@
	if cl /D_MSVC $< /Fe$(OBJDIR)/machdep.exe /Fo$(OBJDIR)/machdep.obj ;then \
           echo "let hasMSVC = true" >>$@ \
        ;else \
           echo "let hasMSVC = false" >>$@ ;fi
	echo "let msvc = {" >>$@
	$(OBJDIR)/machdep.exe >>$@
	echo "	 underscore_name = true ;" >> $@
	echo "}"          >>$@
	echo "let gccHas__builtin_va_list = @HAVE_BUILTIN_VA_LIST@" >>$@
	echo "let __thread_is_keyword = @THREAD_IS_KEYWORD@"  >>$@

#
# Create the version information module
.PHONY: cilversion 
cilversion: $(OBJDIR)/cilversion.ml
$(OBJDIR)/cilversion.ml: configure.in Makefile.in
	rm -f $@
	echo "(* This module was generated automatically by code in Makefile *)" >$@
# Generate here the version information
	echo "let cilVersionMajor = @CIL_VERSION_MAJOR@" >>$@
	echo "let cilVersionMinor = @CIL_VERSION_MINOR@" >>$@
	echo "let cilVersionRev   = @CIL_VERSION_REV@"   >>$@
	echo "let cilVersion      = \"@CIL_VERSION@\""  >>$@ 

# build two libraries
.PHONY: cillib libcil
ifeq ($(NATIVECAML),1)
cillib: $(OBJDIR)/cil.$(CMXA) # $(OBJDIR)/libcil.a
else
cillib: $(OBJDIR)/cil.$(CMXA) 
endif


$(OBJDIR)/feature_config.ml: Makefile config.status
	rm -f $(OBJDIR)/feature_config.*
	echo "(* This module was generated automatically by code in Makefile.in *)" >$@
# The Cilly feature options. A list of Cil.featureDescr 
	echo "open Cil"   >>$@ 
	echo "let features : featureDescr list = [" >> $@
ifdef USE_BLOCKINGGRAPH
	echo "   Blockinggraph.feature;" >> $@  
endif
ifdef USE_RAND
	echo "   Rand.feature;" >> $@  
endif
ifdef USE_ARITHABS
	echo "   Arithabs.feature;" >>$@
endif
ifdef USE_SMALLOC
	echo "   Smalloc.feature;" >> $@  
endif
ifdef USE_CQUALANN
	echo "   Cqualann.feature;" >> $@  
endif
ifdef USE_ZRAPP
	echo "   Zrapp.feature;" >> $@  
endif
# Now the extra features, with the first letter capitalized
	echo \
          $(foreach f,@EXTRAFEATURES@, \
             `echo $f | cut -c 1 | tr "[a-z]" "[A-Z]"``echo $f | cut -c 2-`".feature;") >> $@
	echo "]"   >>$@ 
# Must delete main.d and remake it, because it may have been made
# before feature_config existed.
	rm -f $(DEPENDDIR)/main.d
	$(MAKE) $(DEPENDDIR)/main.d






OCAML_CIL_LIB_MODULES := $(CILLY_LIBRARY_MODULES) 
OCAML_CIL_LIB_CMODULES := perfcount

# list of modules to use for building a library; remove 'main'
# and add 'libmaincil'
OCAML_CIL_C_LIB_MODULES := $(CILLY_MODULES:main=) libmaincil

# Build an OCAML library (CMA / CMXA) that exports our Cil stuff
$(OBJDIR)/cil.$(CMXA): $(OCAML_CIL_LIB_CMODULES:%=$(OBJDIR)/lib%.a) \
                       $(OCAML_CIL_LIB_MODULES:%=$(OBJDIR)/%.$(CMO))
	$(CAMLLINK) -a -o $@ -ccopt -L$(pkglibdir) \
               $(OCAML_CIL_LIB_CMODULES:%=-cclib -l%) \
               $(OCAML_CIL_LIB_MODULES:%=$(OBJDIR)/%.$(CMO))

$(OBJDIR)/libperfcount.a: %: %($(OBJDIR)/perfcount.$(CMC))
	ranlib $@

# sm: for Simon: build a library of CIL functions which can
# be called from C code; this is like the target above, except
# it is callable from C instead of from Ocaml
ifeq ($(NATIVECAML),1)
$(OBJDIR)/libcil.a: $(OCAML_CIL_LIB_CMODULES:%=$(OBJDIR)/lib%.a) \
                    $(OCAML_CIL_LIB_MODULES:%=$(OBJDIR)/%.$(CMO))
	ocamlopt -output-obj -o $@ unix.cmxa str.cmxa $^
else
$(OBJDIR)/libcil.a:
	@echo "Can only build $@ when NATIVECAML is 1."
	exit 2
endif

# Test cil
ifdef _MSVC
TESTCILARG=--MSVC --testcil "bash msvctestcil"
else
TESTCILARG=       --testcil "bash gcctestcil"
endif

.PHONY: testcil
testcil: $(OBJDIR)/cilly$(EXE)
	       cd test; ../$(OBJDIR)/cilly$(EXE) $(TESTCILARG)

.PHONY: odoc texdoc pdfdoc

###
### DOCUMENTATION
###
### The following are available
###
###   make doc  - creates the documentation
###   make publish_doc - creates the documentation and puts it on the web page

# Documentation generated by "ocamldoc"
odoc: $(OBJDIR)/pretty.cmi $(OBJDIR)/cil.cmi
	-rm -rf doc/html/cil/api
	-mkdir doc/html/cil/api
	-mkdir doc/html/cil/api-latex
	-rm -f doc/ocamldoc.sty
	ocamldoc -d doc/html/cil/api -v -stars \
             -html \
             -t "CIL API Documentation (version @CIL_VERSION@)" \
	     -I $(OBJDIR) \
                    ocamlutil/pretty.mli ocamlutil/errormsg.mli \
                    ocamlutil/clist.mli \
	  	    ocamlutil/stats.mli src/cil.mli src/formatcil.mli \
                    ocamlutil/alpha.mli src/cillower.mli \
                    src/ext/cfg.mli src/ext/dataflow.mli \
                    src/ext/dominators.mli

doc/cilpp.tex: doc/cilcode.pl doc/cil.tex 
	-rm -rf doc/html/cil
	-mkdir doc/html/cil
	-mkdir doc/html/cil/examples
	cd doc; perl cilcode.pl cil.tex >cilpp.tex.tmp
	mv doc/cilpp.tex.tmp $@

# Documentation generated from latex files using "hevea"
texdoc: doc/cilpp.tex
# Create the version document
	cd doc/html/cil; echo "\def\cilversion{@CIL_VERSION@}" >cil.version.tex
	cd doc/html/cil; echo "\def\ccuredversion{@CCURED_VERSION@}" >>cil.version.tex
	cd doc/html/cil; hevea -exec xxdate.exe ../../cilpp
	cd doc/html/cil; hevea -exec xxdate.exe ../../cilpp
	cd doc/html/cil; mv cilpp.html cil.html
	cd doc/html/cil; hacha -o ciltoc.html cil.html
	cp -f doc/index.html doc/html/cil/index.html
	cp -f doc/header.html doc/html/cil

pdfdoc: doc/cilpp.tex $(OBJDIR)/pretty.cmi $(OBJDIR)/cil.cmi
	cd doc; echo "\def\cilversion{@CIL_VERSION@}" >cil.version.tex
	cd doc; echo "\def\ccuredversion{@CCURED_VERSION@}" >>cil.version.tex
	cd doc; pdflatex cilpp.tex; pdflatex cilpp.tex
	cd doc; mv cilpp.pdf html/cil/CIL.pdf
	ocamldoc -o doc/cil-api.tex -v -stars \
             -latex \
             -t "CIL API Documentation (version @CIL_VERSION@)" \
	     -I $(OBJDIR) \
                    ocamlutil/pretty.mli ocamlutil/errormsg.mli \
                    ocamlutil/clist.mli \
	  	    ocamlutil/stats.mli src/cil.mli src/formatcil.mli \
                    ocamlutil/alpha.mli

	cd doc ; TEXINPUTS="$$TEXINPUTS:/usr/local/lib/ocaml/ocamldoc:/usr/lib/ocaml/ocamldoc" pdflatex cil-api.tex
	cd doc ; mv cil-api.pdf html/cil/CIL-API.pdf

doc: texdoc pdfdoc odoc


#----------------------------------------------------------------------
# Generate the CIL distribution
# This will create a file cil.tar.gz. It includes the HTML documentation 
# so that people can use it even if they don't have ocamldoc, hevea etc. 

.PHONY: distrib distrib-nocheck checkdistrib
CIL_TAR_GZ:=cil-@CIL_VERSION@.tar.gz
## Make a distribution and check it
distrib: distrib-nocheck checkdistrib

# Work in a temporary directory
TEMP_DIR = TEMP_cil-distrib

# The tar archive members will be relative to this directory
TOP_DIR = $(TEMP_DIR)/cil

DISTRIB_ROOT = README LICENSE INSTALL Makefile.in  \
               config.h.in Makefile.gcc Makefile.msvc \
	       configure configure.in install-sh config.guess config.sub \
	       cil.spec cil.spec.in

DISTRIB_SRC = cilutil.ml cil.ml cil.mli check.ml check.mli \
	      rmtmps.ml rmtmps.mli formatlex.mll formatparse.mly \
	      formatcil.mli formatcil.ml testcil.ml \
	      mergecil.ml mergecil.mli main.ml machdep.c \
	      ciloptions.ml ciloptions.mli libmaincil.ml \
	      escape.ml escape.mli cillower.mli cillower.ml

DISTRIB_OCAMLUTIL = pretty.ml pretty.mli errormsg.ml errormsg.mli \
                    trace.ml trace.mli stats.ml stats.mli util.ml util.mli \
                    inthash.ml inthash.mli alpha.ml alpha.mli \
		    intmap.ml intmap.mli clist.ml clist.mli \
                    growArray.ml growArray.mli \
                    perfcount.c.in Makefile.ocaml Makefile.ocaml.build


DISTRIB_SRC_FRONTC = cabs.ml cprint.ml clexer.mli clexer.mll \
		     cparser.mly lexerhack.ml \
		     cabs2cil.ml cabs2cil.mli frontc.ml frontc.mli \
	             cabsvisit.mli cabsvisit.ml patch.mli patch.ml

DISTRIB_SRC_EXT = logcalls.ml logcalls.mli \
                  astslicer.ml heap.ml partial.ml \
                  logwrites.ml heapify.ml callgraph.ml callgraph.mli \
                  epicenter.ml usedef.ml ciltools.ml \
                  cfg.ml deadcodeelim.ml availexps.ml \
                  dataflow.ml dataflow.mli \
		  dominators.ml dominators.mli \
		  bitmap.ml bitmap.mli \
		  ssa.ml ssa.mli \
	          stackoverflow.mli stackoverflow.ml \
	          canonicalize.ml canonicalize.mli \
	          oneret.ml oneret.mli sfi.ml \
	          simplemem.ml simplify.ml \
	          blockinggraph.ml blockinggraph.mli \
		  dataslicing.ml dataslicing.mli \
		  reachingdefs.ml \
		  cfg.ml cfg.mli \
		  liveness.ml

DISTRIB_SRC_EXT_PTA = setp.ml setp.mli golf.ml golf.mli \
                      ptranal.ml ptranal.mli \
	              steensgaard.mli steensgaard.ml \
                      uref.ml uref.mli olf.ml olf.mli

DISTRIB_LIB = Cilly.pm KeptFile.pm OutputFile.pm TempFile.pm

DISTRIB_BIN = CilConfig.pm.in cilly cilly.bat.in \
              patcher patcher.bat.in test-bad teetwo

DISTRIB_SMALL1=hello.c func.c init.c init1.c wchar1.c vararg1.c testharness.h 

distrib-nocheck: $(DISTRIB_ROOT) doc
        # Create the distribution from scratch
	rm -rf $(TEMP_DIR)
	mkdir $(TEMP_DIR)

	rm -rf $(CIL_TAR_GZ)
	mkdir $(TOP_DIR) \
	      $(TOP_DIR)/src \
              $(TOP_DIR)/src/frontc \
              $(TOP_DIR)/src/ext \
              $(TOP_DIR)/src/ext/pta \
              $(TOP_DIR)/obj \
              $(TOP_DIR)/doc \
	      $(TOP_DIR)/lib \
	      $(TOP_DIR)/bin \
	      $(TOP_DIR)/doc/api \
              $(TOP_DIR)/obj/.depend \
              $(TOP_DIR)/obj/x86_WIN32 \
              $(TOP_DIR)/obj/x86_LINUX \
              $(TOP_DIR)/obj/ppc_DARWIN \
              $(TOP_DIR)/obj/sparc_SOLARIS \
              $(TOP_DIR)/test \
              $(TOP_DIR)/test/small1 \
              $(TOP_DIR)/ocamlutil

	cp $(patsubst %,%,$(DISTRIB_ROOT)) $(TOP_DIR)

	cp $(patsubst %,src/%,$(DISTRIB_SRC)) $(TOP_DIR)/src
	cp $(patsubst %,ocamlutil/%,$(DISTRIB_OCAMLUTIL)) $(TOP_DIR)/ocamlutil
	cp $(patsubst %,src/ext/%,$(DISTRIB_SRC_EXT)) $(TOP_DIR)/src/ext
	cp $(patsubst %,src/ext/pta/%,$(DISTRIB_SRC_EXT_PTA)) \
                                      $(TOP_DIR)/src/ext/pta
	cp $(patsubst %,src/frontc/%,$(DISTRIB_SRC_FRONTC)) \
		$(TOP_DIR)/src/frontc
	cp $(patsubst %,lib/%,$(DISTRIB_LIB)) $(TOP_DIR)/lib
	cp $(patsubst %,bin/%,$(DISTRIB_BIN)) $(TOP_DIR)/bin
	cp $(patsubst %,test/small1/%,$(DISTRIB_SMALL1)) $(TOP_DIR)/test/small1

	cp -r doc/html/cil/* $(TOP_DIR)/doc
# Delete all CVS directories
	if find $(TEMP_DIR) -name CVS -print >cvss.txt ; then \
            rm -rf `cat cvss.txt` ;fi
# Now make the TAR ball
	cd $(TEMP_DIR); tar cfz $(CIL_TAR_GZ) cil
	mv $(TEMP_DIR)/$(CIL_TAR_GZ) .

#	rm -rf $(TEMP_DIR)

## Check a distribution
checkdistrib:
	cd $(TOP_DIR) && ./configure && \
           $(MAKE) && $(MAKE) quicktest

distclean: clean
	rm -f src/frontc/cparser.output
	rm -f src/formatparse.output
	rm -f ocamlutil/perfcount.c
	rm -f bin/cilly.bat
	rm -f bin/patcher.bat
	rm -f bin/CilConfig.pm
	rm -f config.log
	rm -f config.h
	rm -f Makefile

## Publish the distribution
CILHTMLDEST=/var/www/cil
publish_distrib: publish_doc
	if test -d $(CILHTMLDEST); then \
           cp -rf doc/html/cil/* $(CILHTMLDEST); \
           cp -f $(CIL_TAR_GZ) $(CILHTMLDEST)/distrib; \
           ln -sf $(CILHTMLDEST)/distrib/$(CIL_TAR_GZ) $(CILHTMLDEST)/distrib/cil-latest.tar.gz ; \
           echo "Publish succeeded"; \
	else \
	   error "Cannot publish because $(CILHTMLDEST) does not exist" ; \
        fi

publish_doc: doc
	if test -d $(CILHTMLDEST); then \
           cp -rf doc/html/cil/* $(CILHTMLDEST); echo "Done publishing doc"; \
	else \
	   error "Cannot publish because $(CILHTMLDEST) does not exist" ; \
        fi

cleancheck:
	rm -f test/small1/*.o
	rm -f test/small1/hello
	rm -f test/small1/vararg1
	rm -f test/small1/wchar1

clean: cleancaml cleancheck
	rm -f $(OBJDIR)/machdep.ml

# Now include the compiler specific stuff
ifdef _MSVC
  include Makefile.msvc
else
  ifdef _GNUCC
    include Makefile.gcc
  endif
endif

test/%: 
	bin/cilly $(CONLY) test/small1/$*.c $(OBJOUT)test/small1/$*.o

testrun/%: 
	bin/cilly test/small1/$*.c $(OBJOUT)test/small1/$*
	test/small1/$*



.PHONY: quicktest
quicktest: $(patsubst %,test/%,func init init1) \
           $(patsubst %,testrun/%,hello wchar1 vararg1)

.PHONY: check
check: quicktest

############# Binary distribution ################
.PHONY: bindistrb checkbindistrib

BINCIL_TAR_GZ:=cil-win32-@CIL_VERSION@.tar.gz

# Work in a temporary directory
BINTEMP_DIR = TEMP_cil-bindistrib

# The tar archive members will be relative to this directory
BINTOP_DIR = $(BINTEMP_DIR)/cil

BINDISTRIB_ROOT = README LICENSE

BINDISTRIB_LIB = Cilly.pm KeptFile.pm OutputFile.pm TempFile.pm

BINDISTRIB_BIN = CilConfig.pm.in cilly cilly.bat.in \
              patcher patcher.bat.in

BINDISTRIB_OBJ = cilly.byte.exe cilly.asm.exe

BINDISTRIB_SMALL1=hello.c 

bindistrib-nocheck: $(BINDISTRIB_ROOT) obj/x86_WIN32/cilly.asm.exe
        # Create the distribution from scratch
	rm -rf $(BINTEMP_DIR)
	mkdir $(BINTEMP_DIR)

	mkdir $(BINTOP_DIR) \
              $(BINTOP_DIR)/obj \
              $(BINTOP_DIR)/doc \
	      $(BINTOP_DIR)/lib \
	      $(BINTOP_DIR)/bin \
	      $(BINTOP_DIR)/doc/api \
              $(BINTOP_DIR)/obj/.depend \
              $(BINTOP_DIR)/obj/x86_WIN32 \
              $(BINTOP_DIR)/test \
              $(BINTOP_DIR)/test/small1 

	cp $(patsubst %,%,$(BINDISTRIB_ROOT)) $(BINTOP_DIR)
	cp $(patsubst %,lib/%,$(BINDISTRIB_LIB)) $(BINTOP_DIR)/lib
	cat bin/CilConfig.pm.in \
            | sed -e "s|@||g" \
            | sed -e "s|CC|cl|" \
            | sed -e "s|DEFAULT_CIL_MODE|MSVC|" \
            | sed -e "s|ARCHOS|x86_WIN32|" \
               > $(BINTOP_DIR)/bin/CilConfig.pm
	cat bin/patcher.bat.in | sed -e "s|@||g" >$(BINTOP_DIR)/bin/patcher.bat
	cp bin/patcher $(BINTOP_DIR)/bin
	cp bin/cilly $(BINTOP_DIR)/bin
	cat bin/cilly.bat.in | sed -e "s|@||g" > $(BINTOP_DIR)/bin/cilly.bat
	cp $(patsubst %,test/small1/%,$(BINDISTRIB_SMALL1)) \
                                                 $(BINTOP_DIR)/test/small1
	cp $(patsubst %,obj/x86_WIN32/%,$(BINDISTRIB_OBJ)) \
                                       $(BINTOP_DIR)/obj/x86_WIN32

	cp -r doc/html/cil/* $(BINTOP_DIR)/doc
# Delete all CVS directories
	if find $(BINTEMP_DIR) -name CVS -print >cvss.txt ; then \
            rm -rf `cat cvss.txt` ;fi
# Now make the TAR ball
	cd $(BINTEMP_DIR); tar cfz $(BINCIL_TAR_GZ) cil
	mv $(BINTEMP_DIR)/$(BINCIL_TAR_GZ) .

#	rm -rf $(TEMP_DIR)

## Check a distribution
checkbindistrib:

########################################################################


INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@

prefix = @prefix@
exec_prefix = @exec_prefix@
libdir = @libdir@
pkglibdir = $(libdir)/cil
datadir = @datadir@
pkgdatadir = $(datadir)/cil

all_mli := $(filter %.mli, $(DISTRIB_OCAMLUTIL) $(DISTRIB_SRC) $(DISTRIB_SRC_FRONTC) $(DISTRIB_SRC_EXT) $(DISTRIB_SRC_EXT_PTA))
install_mli := $(filter $(OCAML_CIL_LIB_MODULES:=.mli), $(all_mli))
install_cmi := $(install_mli:%.mli=$(OBJDIR)/%.cmi)
install_cma := $(addprefix $(OBJDIR)/cil., cma cmxa a)
install_lib := $(OCAML_CIL_LIB_CMODULES:%=$(OBJDIR)/lib%.a)

install: $(install_cmi) $(install_cma) $(install_lib)
	$(INSTALL) -d $(DESTDIR)$(pkglibdir)
	$(INSTALL_DATA) $(install_cma) $(DESTDIR)$(pkglibdir)
	$(INSTALL_DATA) $(install_cmi) $(DESTDIR)$(pkglibdir)
	$(INSTALL_DATA) $(install_lib) $(DESTDIR)$(pkglibdir)
	$(INSTALL) -d $(DESTDIR)$(pkgdatadir)
	$(INSTALL_DATA) $(addprefix lib/, $(filter %.pm, $(DISTRIB_LIB))) $(DESTDIR)$(pkgdatadir)

cil.spec: cil.spec.in
	./config.status $@

rpms: distrib
	rpmbuild -ta $(CIL_TAR_GZ)