File: Makefile.OCaml

package info (click to toggle)
unison2.32.52 2.32.52-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,184 kB
  • ctags: 4,027
  • sloc: ml: 23,058; objc: 4,161; makefile: 514; ansic: 494; sh: 80
file content (394 lines) | stat: -rw-r--r-- 10,835 bytes parent folder | download | duplicates (2)
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
####################################################################
#         Makefile rules for compiling ocaml programs              #
####################################################################

####################################################################
### Try to automatically guess OS

ifeq (${OSCOMP},cygwingnuc) # Define this if compiling with Cygwin GNU C
  OSARCH=win32gnuc
  ETAGS=/bin/etags
  buildexecutable:: win32rc/unison.res.lib
else
# Win32 system
ifeq (${OSTYPE},cygwin32) # Cygwin Beta 19
  OSARCH=win32
  ETAGS=/bin/etags
else
ifeq (${OSTYPE},cygwin)	  # Cygwin Beta 20
  OSARCH=win32
  ETAGS=/bin/etags
else

# Unix system
ifeq ($(shell uname),SunOS)
  OSARCH=solaris
else
ifeq ($(shell uname),Darwin)
  OSARCH=osx
else
ifeq ($(shell uname),OpenBSD)
  OSARCH=OpenBSD
else
ifeq ($(shell uname),NetBSD)
  OSARCH=NetBSD
endif
endif
endif
endif
ETAGS=etags
endif
endif
endif

# The OCaml lib dir is used by all versions
# It is extracted from 'ocamlc -v' and Windows '\' separators are turned
# to Unix '/' separators, and extraneous control-M's are deleted.
# Unfortunately there is a literal control-M buried in this, I'd rather
# get rid of it...
# OCAMLLIBDIR=$(shell ocamlc -v | tail -n -1 | sed -e 's/.* //g' | sed -e 's/\\/\//g' | sed -e 's///g')
# Better(?) version, June 2005:
OCAMLLIBDIR=$(shell ocamlc -v | tail -n -1 | sed -e 's/.* //g' | sed -e 's/\\/\//g' | tr -d '\r')

## BCP (6/05) an alternative, but not quite working, version
## suggested by Nick Montfort:
# OCAMLLIBDIR=$(shell ocamlc -v | sed -n '$p' | sed -e 's/^Standard library directory: //' | sed -e 's/\\/\//g' | sed -e 's/\r//g')

# User interface style:
#   Legal values are
#     UISTYLE=text
#     UISTYLE=gtk
#     UISTYLE=gtk2
#     UISTYLE=mac     (old and limited, but working)
#     UISTYLE=macnew  (spiffy, but not yet extensively tested)
#
# This should be set to an appropriate value automatically, depending
# on whether the lablgtk library is available
LABLGTKLIB=$(OCAMLLIBDIR)/lablgtk
LABLGTK2LIB=$(OCAMLLIBDIR)/lablgtk2
##BCP [3/2007]: Removed temporarily, since the OSX UI is not working well 
## at the moment and we don't want to confuse people by building it by default
ifeq ($(OSARCH),osx)
  UISTYLE=macnew
else
  ifeq ($(wildcard $(LABLGTK2LIB)),$(LABLGTK2LIB))
    UISTYLE=gtk2
  else
    UISTYLE=text
endif
endif
buildexecutable::
	@echo UISTYLE = $(UISTYLE)

####################################################################
### Default parameters

INCLFLAGS=-I lwt -I ubase
CAMLFLAGS+=$(INCLFLAGS)

ifeq ($(OSARCH),win32)
  # Win32 system
  EXEC_EXT=.exe
  OBJ_EXT=.obj
  CWD=.
#  Fix suggested by Karl M, Jan 2009:
#    "The new flexlink wrapper that OCaml 3.11 uses was gagging on the res
#    file. So the res file has to be passed through flexlink untouched to
#    the linker.  I only touched the MSVC side, but mingw may have the same
#    issue."
#  CLIBS+=-cclib win32rc/unison.res
#  STATICLIBS+=-cclib win32rc/unison.res
  CLIBS+=-cclib "-link win32rc/unison.res"
  STATICLIBS+=-cclib "-link win32rc/unison.res"
  buildexecutable::
	@echo Building for Windows
else
  # Unix system, or Cygwin with GNU C compiler
  OBJ_EXT=.o
  CWD=$(shell pwd)
  ifeq ($(OSARCH),win32gnuc)
    EXEC_EXT=.exe
    CLIBS+=-cclib win32rc/unison.res.lib
    STATIC=false                      # Cygwin is not MinGW :-(
    buildexecutable::
	@echo Building for Windows with Cygwin GNU C
  else
    EXEC_EXT=
    # openpty is in the libutil library
    ifneq ($(OSARCH),solaris)
      ifneq ($(OSARCH),osx)
        CLIBS+=-cclib -lutil
      endif
    endif
    buildexecutable::
	@echo Building for Unix
  endif
endif

buildexecutable::
	@echo NATIVE = $(NATIVE)
	@echo THREADS = $(THREADS)
	@echo STATIC = $(STATIC)
	@echo OSTYPE = $(OSTYPE)
	@echo OSARCH = $(OSARCH)

ubase/projectInfo.ml: mkProjectInfo
	echo 'let myName = "'$(NAME)'";;' > $@
	echo 'let myVersion = "'$(VERSION)'";;' >> $@
	echo 'let myMajorVersion = "'$(MAJORVERSION)'";;' >> $@

clean::
	$(RM) ubase/projectInfo.ml

####################################################################
### Unison objects and libraries

ifeq ($(UISTYLE),mac)
  buildexecutable:: macexecutable
  UIMACDIR=uimac
else
ifeq ($(UISTYLE),macnew)
  buildexecutable:: macexecutable
  UIMACDIR=uimacnew
else
  buildexecutable:: $(NAME)$(EXEC_EXT)
endif
endif

MINOSXVERSION=10.4

# NOTE: the OCAMLLIBDIR is not getting passed correctly?
# The two cases for cltool are needed because Xcode 2.1+
# builds in build/Default/, and earlier versions use build/
macexecutable: $(NAME)-blob.o
#	sed -e's/@@VERSION@@/$(VERSION)/' $(UIMACDIR)/Info.plist.template > $(UIMACDIR)/Info.plist
	(cd $(UIMACDIR); xcodebuild OCAMLLIBDIR="$(OCAMLLIBDIR)" SYMROOT=build)
	if [ -e $(UIMACDIR)/build/Default ]; then \
	  gcc -mmacosx-version-min=$(MINOSXVERSION) $(UIMACDIR)/cltool.c -o $(UIMACDIR)/build/Default/Unison.app/Contents/MacOS/cltool -framework Carbon; \
	else \
	  gcc -mmacosx-version-min=$(MINOSXVERSION) $(UIMACDIR)/cltool.c -o $(UIMACDIR)/build/Unison.app/Contents/MacOS/cltool -framework Carbon; \
	fi

# OCaml objects for the bytecode version
# File extensions will be substituted for the native code version

OCAMLOBJS += \
          ubase/projectInfo.cmo ubase/myMap.cmo ubase/safelist.cmo \
          ubase/uprintf.cmo ubase/util.cmo ubase/rx.cmo ubase/uarg.cmo \
          ubase/prefs.cmo ubase/trace.cmo \
          \
          lwt/pqueue.cmo lwt/lwt.cmo lwt/lwt_util.cmo lwt/lwt_unix.cmo \
          \
          bytearray.cmo case.cmo pred.cmo uutil.cmo \
          fileutil.cmo name.cmo path.cmo fspath.cmo fingerprint.cmo \
          abort.cmo osx.cmo external.cmo \
          props.cmo fileinfo.cmo os.cmo lock.cmo clroot.cmo common.cmo \
          tree.cmo checksum.cmo terminal.cmo \
          transfer.cmo xferhint.cmo remote.cmo globals.cmo copy.cmo \
          stasher.cmo update.cmo \
	  files.cmo sortri.cmo recon.cmo transport.cmo \
          strings.cmo uicommon.cmo uitext.cmo test.cmo

OCAMLOBJS+=main.cmo

# OCaml libraries for the bytecode version
# File extensions will be substituted for the native code version
OCAMLLIBS+=unix.cma str.cma bigarray.cma

COBJS+=osxsupport$(OBJ_EXT) pty$(OBJ_EXT) bytearray_stubs$(OBJ_EXT)

########################################################################
### User Interface setup

## Text UI
ifeq ($(UISTYLE), text)
  OCAMLOBJS+=linktext.cmo
endif

## Old Mac UI
ifeq ($(UISTYLE),mac)
  OCAMLOBJS+=uimacbridge.cmo
endif

## New Mac UI
ifeq ($(UISTYLE),macnew)
  OCAMLOBJS+=uimacbridgenew.cmo
  THREADS=true
  OCAMLLIBS+=threads.cma
  INCLFLAGS+=-thread 
endif

## Graphic UI

# Setup the lib directories

# Win32 system : this very Makefile must be used with GNU Make, so that we
#                expect CygWin Bash to be used.
# The directory must be provided following one of the model below :
# - unix, relative      ../../ocaml/lib/labltk
# - unix, absolute      d:/home/foobar/ocaml/lib/labltk
# -  dos, relative      ..\\..\\ocaml\\lib\\labltk
# -  dos, absolute      d:\\home\\foobar\\ocaml\\lib\\labltk

# Patch to make a Windows GUI version come up with no
# console when click-started
#  ifeq ($(OSARCH), win32)
#    COBJS+=winmain.c
#    CFLAGS+=-cclib /subsystem:windows
#  endif

# Gtk GUI
ifeq ($(UISTYLE), gtk)
  CAMLFLAGS+=-I +lablgtk
  OCAMLOBJS+=pixmaps.cmo uigtk.cmo linkgtk.cmo
  OCAMLLIBS+=lablgtk.cma
endif

# Gtk2 GUI
ifeq ($(UISTYLE), gtk2)
  CAMLFLAGS+=-I +lablgtk2
  OCAMLOBJS+=pixmaps.cmo uigtk2.cmo linkgtk2.cmo
  OCAMLLIBS+=lablgtk.cma
endif

####################################################################
### Static build setup

ifeq ($(STATIC), true)
  STATICLIBS+=-cclib -static
endif

####################################################################
### Dependencies

# Include an automatically generated list of dependencies
include .depend

ifeq ($(OSARCH), OpenBSD)
  ifeq ($(shell echo type ocamldot | ksh), file)
    OCAMLDOT=true
  endif
else
  ifeq ($(shell echo type -t ocamldot | bash), file)
    OCAMLDOT=true
  endif
endif

ifeq ($(OSARCH), NetBSD)
  OCAMLDOT=false
endif

# Rebuild dependencies (must be invoked manually)
.PHONY: depend
depend::
	ocamldep $(INCLFLAGS) *.mli *.ml */*.ml */*.mli > .depend
ifdef OCAMLDOT
	echo 'digraph G {' > dot.tmp
	echo '{ rank = same; "Fileinfo"; "Props"; "Fspath"; "Os"; "Path"; }'\
           >>dot.tmp
	echo '{ rank = same; "Uitext"; "Uigtk"; }'>>dot.tmp
	echo '{ rank = same; "Recon"; "Update"; "Transport"; "Files"; }'\
           >>dot.tmp
	echo '{ rank = same; "Tree"; "Safelist"; }'>>dot.tmp
	echo '{ rank = same; "Uarg"; "Prefs"; }'>>dot.tmp
	ocamldot .depend | tail -n +2 >> dot.tmp
	-dot -Tps -o DEPENDENCIES.ps dot.tmp
endif

####################################################################
### Compilation boilerplate

ifeq ($(DEBUGGING), false)
  ifneq ($(OSARCH), win32)
    ifneq ($(OSARCH), osx)
      # Strip the binary (does not work with MS compiler; might not work
      # under OSX)
      CFLAGS+=-cclib -Wl,-s
    endif
  endif
endif

ifeq ($(PROFILING), true)
  OCAMLC=ocamlcp
else
  OCAMLC=ocamlc
endif
OCAMLOPT=ocamlopt

ifeq ($(NATIVE), true)
  ## Set up for native code compilation

  CAMLC=$(OCAMLOPT)
  ifeq ($(PROFILING), true)
    CAMLFLAGS+=-p
    CLIBS+=-cclib -ldl
  endif

  CAMLOBJS=$(subst .cmo,.cmx, $(subst .cma,.cmxa, $(OCAMLOBJS)))
  CAMLLIBS=$(subst .cma,.cmxa, $(OCAMLLIBS))

else
  ## Set up for bytecode compilation

  CAMLC=$(OCAMLC)
  CAMLFLAGS+=-custom
  ifeq ($(DEBUGGING), true)
    CAMLFLAGS+=-g
  endif

  CAMLOBJS=$(OCAMLOBJS)
  CAMLLIBS=$(OCAMLLIBS)

endif

win32rc/unison.res.lib: win32rc/unison.res
	windres win32rc/unison.res win32rc/unison.res.lib

%.ml: %.mll
	-$(RM) $@
	ocamllex $<

%.cmi : %.mli
	@echo "$(CAMLC): $< ---> $@"
	$(CAMLC) $(CAMLFLAGS) -c $(CWD)/$<

%.cmo: %.ml
	@echo "$(OCAMLC): $< ---> $@"
	$(OCAMLC) $(CAMLFLAGS) -c $(CWD)/$<

%.cmx: %.ml
	@echo "$(OCAMLOPT): $< ---> $@"
	$(OCAMLOPT) $(CAMLFLAGS) -c $(CWD)/$<

%.o %.obj: %.c
	@echo "$(OCAMLOPT): $< ---> $@"
	$(CAMLC) $(CAMLFLAGS) -c $(CWD)/$<

$(NAME)$(EXEC_EXT): $(CAMLOBJS) $(COBJS)
	@echo Linking $@
	$(CAMLC) -verbose $(CAMLFLAGS) -o $@ $(CFLAGS) $(CAMLLIBS) $^ $(CLIBS)

# Unfortunately -output-obj does not put .o files into the output, only .cmx
# files, so we have to use $(LD) to take care of COBJS.
$(NAME)-blob.o: $(CAMLOBJS) $(COBJS)
	@echo Linking $@
	$(CAMLC) -output-obj -verbose $(CAMLFLAGS) -o u-b.o $(CFLAGS) $(CAMLLIBS) $(CLIBS) $(CAMLOBJS)
	$(LD) -r -o $@ u-b.o $(COBJS)
	$(RM) u-b.o

%$(EXEC_EXT): %.ml
	$(OCAMLC) -verbose -o $@ $^

######################################################################
### Misc

clean::
	-$(RM) -r *.cmi *.cmo *.cmx *.cma *.cmxa TAGS tags
	-$(RM) -r *.o core gmon.out *~ .*~
	-$(RM) -r *.obj *.lib *.exp
	-$(RM) -r *.tmp *.bak?.tmp .*.bak?.tmp

paths:
	@echo PATH = $(PATH)
	@echo OCAMLLIBDIR = $(OCAMLLIBDIR)