-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
575 lines (442 loc) · 13.9 KB
/
Makefile
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
###########################################################################
# OcamlMakefile
# Copyright (C) 1999, 2000, 2001 Markus Mottl
#
# For updates see:
# http://miss.wu-wien.ac.at/~mottl/ocaml_sources
#
# $Id: Makefile,v 1.2 2001/10/17 14:59:33 vince Exp $
#
###########################################################################
# Set these variables to the names of the sources to be processed and
# the result variable. Order matters during linkage!
OCAMLLEX = ocamllex
S = Sources/
SOURCES = \
$(S)utils.ml \
$(S)touist_solver.ml \
$(S)smtsolver.ml \
$(S)smtsolver_extractplan.ml \
$(S)symb.ml \
$(S)symbSet.ml \
$(S)timedata.ml \
$(S)functionFormula.ml \
$(S)atom.ml \
$(S)typeset.ml \
$(S)formula.ml \
$(S)constraintsType.ml \
$(S)domain.ml \
$(S)parser.mli\
$(S)lexer.ml\
$(S)parser.mly \
$(S)node.ml \
$(S)plan.ml \
$(S)parallelPlan.ml \
$(S)sequentialPlan.ml \
$(S)planningData.ml \
$(S)touistplan.ml \
$(S)countConstraints.ml \
$(S)tlpgp.ml \
$(S)tsp.ml \
$(S)tsp2.ml \
$(S)main.ml
#ajouter smtplan.ml apres tlpgp.ml
OCAMLFLAGS = -unsafe
# -pp "camlp4o ./p4.cmo"
LIBS = unix
RESULT = touistplan
ifndef SOURCES
SOURCES := foo.ml
endif
export SOURCES
ifndef RESULT
RESULT := foo
endif
export RESULT
export BCSUFFIX
export NCSUFFIX
ifndef TOPSUFFIX
TOPSUFFIX := .top
endif
export TOPSUFFIX
# Eventually set include- and library-paths, libraries to link,
# additional compilation-, link- and ocamlyacc-flags
# Path- and library information needs not be written with "-I" and such...
# Define THREADS if you need it, otherwise leave it unset!
export THREADS
export UNIX
export INCDIRS
export LIBDIRS
export OCAML_DEFAULT_DIRS
export OCAML_LIB_INSTALL
export LIBS
export CLIBS
export OCAMLFLAGS
export OCAMLNCFLAGS
export OCAMLBCFLAGS
export OCAMLLDFLAGS
export OCAMLNLDFLAGS
export OCAMLBLDFLAGS
ifndef OCAMLCPFLAGS
OCAMLCPFLAGS := a
endif
export OCAMLCPFLAGS
export YFLAGS
export IDLFLAGS
export CC
export CFLAGS
export LDFLAGS
# Add a list of optional trash files that should be deleted by "make clean"
export TRASH
#################### variables depending on your Ocaml-installation
BCRESULT := $(addsuffix $(BCSUFFIX), $(RESULT))
NCRESULT := $(addsuffix $(NCSUFFIX), $(RESULT))
TOPRESULT := $(addsuffix $(TOPSUFFIX), $(RESULT))
ifndef OCAMLC
OCAMLC := ocamlc.opt
endif
export OCAMLC
ifndef OCAMLOPT
OCAMLOPT := ocamlopt.opt
endif
export OCAMLOPT
ifndef OCAMLMKTOP
OCAMLMKTOP := ocamlmktop
endif
export OCAMLMKTOP
ifndef OCAMLCP
OCAMLCP := ocamlcp
endif
export OCAMLCP
ifndef OCAMLDEP
OCAMLDEP := ocamldep
endif
export OCAMLDEP
ifndef OCAMLLEX
OCAMLLEX := ocamllex.opt
endif
export OCAMLLEX
ifndef OCAMLYACC
OCAMLYACC := ocamlyacc
endif
export OCAMLYACC
ifndef OCAMLIDL
CAMLIDL := camlidl
endif
export OCAMLIDL
ifndef NOIDLHEADER
MAYBE_IDL_HEADER := -header
endif
export NOIDLHEADER
ifndef OCAMLMAKEFILE
OCAMLMAKEFILE := Makefile
endif
export OCAMLMAKEFILE
ifndef OCAMLLIBPATH
OCAMLLIBPATH := \
$(shell $(OCAMLC) 2>/dev/null -where || echo /usr/local/lib/ocaml)
endif
export OCAMLLIBPATH
ifndef OCAML_LIB_INSTALL
OCAML_LIB_INSTALL := $(OCAMLLIBPATH)/contrib
endif
export OCAML_LIB_INSTALL
###########################################################################
#################### change following sections only if
#################### you know what you are doing!
# for pedants using "--warn-undefined-variables"
export MAYBE_IDL
export REAL_RESULT
export CAMLIDLFLAGS
export THREAD_FLAG
SHELL := /bin/sh
MLDEPDIR := ._d
BCDIDIR := ._bcdi
NCDIDIR := ._ncdi
FILTERED := $(filter %.mli %.ml %.mll %.mly %.idl %.c, $(SOURCES))
SOURCE_DIRS := $(filter-out ./, $(sort $(dir $(FILTERED))))
FILTERED_ML := $(filter %.ml, $(FILTERED))
DEP_ML := $(FILTERED_ML:%.ml=$(MLDEPDIR)/%.d)
FILTERED_MLI := $(filter %.mli, $(FILTERED))
DEP_MLI := $(FILTERED_MLI:.mli=.di)
FILTERED_MLL := $(filter %.mll, $(FILTERED))
DEP_MLL := $(FILTERED_MLL:%.mll=$(MLDEPDIR)/%.d)
AUTO_MLL := $(FILTERED_MLL:.mll=.ml)
FILTERED_MLY := $(filter %.mly, $(FILTERED))
DEP_MLY := $(FILTERED_MLY:%.mly=$(MLDEPDIR)/%.d) $(FILTERED_MLY:.mly=.di)
AUTO_MLY := $(FILTERED_MLY:.mly=.mli) $(FILTERED_MLY:.mly=.ml)
FILTERED_IDL := $(filter %.idl, $(FILTERED))
DEP_IDL := $(FILTERED_IDL:%.idl=$(MLDEPDIR)/%.d) $(FILTERED_IDL:.idl=.di)
C_IDL := $(FILTERED_IDL:%.idl=%_idl.c) $(FILTERED_IDL:.idl=.h)
OBJ_C_IDL := $(FILTERED_IDL:%.idl=%_idl.o)
AUTO_IDL := $(FILTERED_IDL:.idl=.mli) $(FILTERED_IDL:.idl=.ml) $(C_IDL)
FILTERED_C := $(filter %.c, $(FILTERED))
OBJ_C := $(FILTERED_C:.c=.o)
AUTO_TARGETS := $(AUTO_MLL) $(AUTO_MLY) $(AUTO_IDL)
ALL_DEPS := $(DEP_ML) $(DEP_MLI) $(DEP_MLL) $(DEP_MLY) $(DEP_IDL)
MLDEPS := $(filter %.d, $(ALL_DEPS))
MLIDEPS := $(filter %.di, $(ALL_DEPS))
BCDEPIS := $(MLIDEPS:%.di=$(BCDIDIR)/%.di)
NCDEPIS := $(MLIDEPS:%.di=$(NCDIDIR)/%.di)
ALLML := $(filter %.mli %.ml %.mll %.mly %.idl, $(FILTERED))
IMPLO_INTF := $(ALLML:%.mli=%.mli.__)
IMPLO_INTF := $(foreach file, $(IMPLO_INTF), \
$(basename $(file)).cmi $(basename $(file)).cmo)
IMPLO_INTF := $(filter-out %.mli.cmo, $(IMPLO_INTF))
IMPLO_INTF := $(IMPLO_INTF:%.mli.cmi=%.cmi)
IMPLX_INTF := $(IMPLO_INTF:.cmo=.cmx)
INTF := $(filter %.cmi, $(IMPLO_INTF))
IMPL_CMO := $(filter %.cmo, $(IMPLO_INTF))
IMPL_CMX := $(IMPL_CMO:.cmo=.cmx)
OBJ_LINK := $(OBJ_C_IDL) $(OBJ_C)
OBJ_FILES := $(IMPL_CMO:.cmo=.o) $(OBJ_LINK)
EXECS := $(sort $(TOPRESULT) $(BCRESULT) $(NCRESULT))
NONEXECS := $(INTF) $(IMPL_CMO) $(IMPL_CMX) $(OBJ_FILES) $(AUTO_TARGETS) \
$(BCRESULT).cma $(NCRESULT).cmxa $(NCRESULT).a
TARGETS := $(EXECS) $(NONEXECS)
# If there are IDL-files
ifneq "$(strip $(FILTERED_IDL))" ""
MAYBE_IDL := -cclib -lcamlidl
endif
INCFLAGS := $(SOURCE_DIRS:%=-I %) $(INCDIRS:%=-I %) $(OCAML_DEFAULT_DIRS:%=-I %)
CINCFLAGS := $(SOURCE_DIRS:%=-I%) $(INCDIRS:%=-I%) $(OCAML_DEFAULT_DIRS:%=-I%)
ifndef PROFILING
INTF_OCAMLC := $(OCAMLC)
else
ifndef THREADS
INTF_OCAMLC := $(OCAMLCP) -p $(OCAMLCPFLAGS)
else
# OCaml does not support profiling byte code
# with threads (yet), therefore we force an error.
ifndef REAL_OCAMLC
error
endif
endif
endif
COMMON_LDFLAGS := $(LDFLAGS:%=-ccopt %) $(SOURCE_DIRS:%=-ccopt -L%) \
$(LIBDIRS:%=-ccopt -L%) $(OCAML_DEFAULT_DIRS:%=-ccopt -L%)
OBJS_LIBS := $(OBJ_LINK) $(CLIBS:%=-cclib -l%) $(MAYBE_IDL)
# If we have to make byte-code
ifndef REAL_OCAMLC
SPECIAL_OCAMLFLAGS := $(OCAMLBCFLAGS)
REAL_OCAMLC := $(INTF_OCAMLC)
REAL_IMPL := $(IMPL_CMO)
REAL_IMPL_INTF := $(IMPLO_INTF)
IMPL_SUF := .cmo
DEPFLAGS :=
MAKE_DEPS := $(MLDEPS) $(BCDEPIS)
ifndef THREADS
ifneq "$(strip $(OBJ_LINK))" ""
ALL_LDFLAGS := -custom
endif
ifdef CLIBS
ALL_LDFLAGS := -custom
endif
endif
ALL_LDFLAGS += $(INCFLAGS) $(OCAMLLDFLAGS) $(OCAMLBLDFLAGS) \
$(COMMON_LDFLAGS) $(LIBS:%=%.cma)
ifdef THREADS
ALL_LDFLAGS += -thread unix.cma threads.cma
THREAD_FLAG := -thread
endif
ifdef UNIX
ALL_LDFLAGS += unix.cma
endif
# we have to make native-code
else
ifndef PROFILING
SPECIAL_OCAMLFLAGS := $(OCAMLNCFLAGS)
PLDFLAGS :=
else
SPECIAL_OCAMLFLAGS := -p $(OCAMLNCFLAGS)
PLDFLAGS := -p
endif
REAL_IMPL := $(IMPL_CMX)
REAL_IMPL_INTF := $(IMPLX_INTF)
IMPL_SUF := .cmx
CFLAGS := -DNATIVE_CODE $(CFLAGS)
DEPFLAGS := -native
MAKE_DEPS := $(MLDEPS) $(NCDEPIS)
ALL_LDFLAGS := $(PLDFLAGS) $(INCFLAGS) $(OCAMLLDFLAGS) \
$(OCAMLNLDFLAGS) $(COMMON_LDFLAGS)
ifndef CREATE_LIB
ALL_LDFLAGS += $(LIBS:%=%.cmxa)
endif
ifdef THREADS
ALL_LDFLAGS := -thread $(ALL_LDFLAGS)
ifndef CREATE_LIB
ALL_LDFLAGS += unix.cmxa threads.cmxa
endif
THREAD_FLAG := -thread
endif
ifdef UNIX
ALL_LDFLAGS := unix.cmxa $(ALL_LDFLAGS)
endif
endif
ALL_OCAMLCFLAGS := $(THREAD_FLAG) $(OCAMLFLAGS) \
$(INCFLAGS) $(SPECIAL_OCAMLFLAGS)
ifdef make_deps
-include $(MAKE_DEPS)
AUTO_TARGETS :=
endif
###########################################################################
# USER RULES
# generates byte-code (default)
byte-code: $(AUTO_TARGETS)
@$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \
REAL_RESULT="$(BCRESULT)" make_deps=yes
bc: byte-code
top: $(AUTO_TARGETS)
@$(MAKE) -r -f $(OCAMLMAKEFILE) $(TOPRESULT) \
REAL_RESULT="$(BCRESULT)" make_deps=yes
# generates native-code
native-code: $(AUTO_TARGETS)
@$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \
REAL_RESULT="$(NCRESULT)" \
REAL_OCAMLC="$(OCAMLOPT)" \
make_deps=yes
nc: native-code
# generates byte-code libraries
byte-code-library: $(AUTO_TARGETS)
@$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT).cma \
REAL_RESULT="$(BCRESULT)" \
CREATE_LIB=yes \
make_deps=yes
bcl: byte-code-library
# generates native-code libraries
native-code-library: $(AUTO_TARGETS)
@$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT).cmxa \
REAL_RESULT="$(NCRESULT)" \
REAL_OCAMLC="$(OCAMLOPT)" \
CREATE_LIB=yes \
make_deps=yes
ncl: native-code-library
# generates byte-code with debugging information
debug-code: $(AUTO_TARGETS)
@$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \
REAL_RESULT="$(BCRESULT)" make_deps=yes \
OCAMLFLAGS="-g $(OCAMLFLAGS)" \
OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)"
dc: debug-code
# generates byte-code libraries with debugging information
debug-code-library: $(AUTO_TARGETS)
@$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT).cma \
REAL_RESULT="$(BCRESULT)" make_deps=yes \
CREATE_LIB=yes \
OCAMLFLAGS="-g $(OCAMLFLAGS)" \
OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)"
dcl: debug-code-library
# generates byte-code for profiling
profiling-byte-code: $(AUTO_TARGETS)
@$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \
REAL_RESULT="$(BCRESULT)" PROFILING="y" \
make_deps=yes
pbc: profiling-byte-code
# generates native-code
profiling-native-code: $(AUTO_TARGETS)
@$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \
REAL_RESULT="$(NCRESULT)" \
REAL_OCAMLC="$(OCAMLOPT)" \
PROFILING="y" \
make_deps=yes
pnc: profiling-native-code
# generates byte-code libraries
profiling-byte-code-library: $(AUTO_TARGETS)
@$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT).cma \
REAL_RESULT="$(BCRESULT)" PROFILING="y" \
CREATE_LIB=yes \
make_deps=yes
pbcl: profiling-byte-code-library
# generates native-code libraries
profiling-native-code-library: $(AUTO_TARGETS)
@$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT).cmxa \
REAL_RESULT="$(NCRESULT)" PROFILING="y" \
REAL_OCAMLC="$(OCAMLOPT)" \
CREATE_LIB=yes \
make_deps=yes
pncl: profiling-native-code-library
###########################################################################
# LOW LEVEL RULES
$(REAL_RESULT): $(REAL_IMPL_INTF) $(OBJ_LINK)
$(REAL_OCAMLC) $(ALL_LDFLAGS) $(OBJS_LIBS) -o $@ \
$(REAL_IMPL)
%$(TOPSUFFIX): $(REAL_IMPL_INTF) $(OBJ_LINK)
$(OCAMLMKTOP) $(ALL_LDFLAGS) $(OBJS_LIBS) -o $@ \
$(REAL_IMPL)
.SUFFIXES: .mli .ml .cmi .cmo .cmx .cma .cmxa .o \
.mly .di .d .a .idl .c .h
%.cma: $(REAL_IMPL_INTF) $(OBJ_LINK)
$(REAL_OCAMLC) -a $(ALL_LDFLAGS) $(OBJS_LIBS) -o $@ \
$(OCAMLBLDFLAGS) $(REAL_IMPL)
%.cmxa %.a: $(REAL_IMPL_INTF) $(OBJ_LINK)
$(OCAMLOPT) -a $(ALL_LDFLAGS) $(OBJS_LIBS) \
$(OCAMLNLDFLAGS) -o $@ $(REAL_IMPL)
.mli.cmi:
$(INTF_OCAMLC) -c $(THREAD_FLAG) $(OCAMLFLAGS) \
$(INCFLAGS) $<
.ml.cmi .ml.o .ml.cmx .ml.cmo:
$(REAL_OCAMLC) -c $(ALL_OCAMLCFLAGS) $<
.PRECIOUS: %.ml
%.ml: %.mll
$(OCAMLLEX) $<
.PRECIOUS: %.ml %.mli
%.ml %.mli: %.mly
$(OCAMLYACC) $(YFLAGS) $<
.PRECIOUS: %.ml %.mli %_idl.c %.h
%.ml %.mli %_idl.c %.h: %.idl
$(CAMLIDL) $(MAYBE_IDL_HEADER) $(IDLFLAGS) \
$(CAMLIDLFLAGS) $<
@if [ $(NOIDLHEADER) ]; then touch $*.h; fi;
mv $*.c $*_idl.c
.c.o:
$(CC) -c $(CFLAGS) $(CINCFLAGS) -I$(OCAMLLIBPATH) \
$< -o $@
$(MLDEPDIR)/%.d: %.ml
@echo making $@ from $<
@d=`dirname $@`; \
if [ ! -d $$d ]; then mkdir -p $$d; fi
@$(OCAMLDEP) $(INCFLAGS) $< > $@
$(BCDIDIR)/%.di $(NCDIDIR)/%.di: %.mli
@echo making $@ from $<
@d=`dirname $@`; \
if [ ! -d $$d ]; then mkdir -p $$d; fi
@$(OCAMLDEP) $(DEPFLAGS) $(INCFLAGS) $< > $@
###########################################################################
# (UN)INSTALL RULES FOR LIBRARIES
.PHONY: libinstall
libinstall: all
@printf "\nInstalling library to: $(OCAML_LIB_INSTALL)\n"
@printf "Is this ok? (y/[n]) - "
@\
read ans; \
if [ "$$ans" != "y" ]; then \
echo Installation aborted.; exit 1; fi
@echo
-install -d $(OCAML_LIB_INSTALL)
for i in $(LIBINSTALL_FILES); \
do install -m 0644 $$i $(OCAML_LIB_INSTALL); done
@printf "\nInstallation successful.\n"
.PHONY: libuninstall
libuninstall:
@printf "\nUninstalling library from: $(OCAML_LIB_INSTALL)\n"
@printf "Is this ok? (y/[n]) - "
@\
read ans; \
if [ "$$ans" != "y" ]; then \
echo Uninstallation aborted.; exit 1; fi
@echo
cd $(OCAML_LIB_INSTALL); rm $(LIBINSTALL_FILES)
@printf "\nUninstallation successful.\n"
###########################################################################
# MAINTAINANCE RULES
.PHONY: clean
clean:
rm -f $(TARGETS) $(TRASH)
rm -rf $(BCDIDIR) $(NCDIDIR) $(MLDEPDIR)
.PHONY: cleanup
cleanup:
rm -f $(NONEXECS) $(TRASH)
rm -rf $(BCDIDIR) $(NCDIDIR) $(MLDEPDIR)
.PHONY: nobackup
nobackup:
rm -f *.bak *~ *.dup