OMakefile 10.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#*********************************************************************#
#                                                                     #
#                          Caml Images                                #
#                                                                     #
#            Fran輟is Pessaux, projet Cristal, INRIA Rocquencourt     #
#            Pierre Weis, projet Cristal, INRIA Rocquencourt          #
#            Jun Furuse, projet Cristal, INRIA Rocquencourt           #
#                                                                     #
#  Copyright 1999-2004,                                               #
#  Institut National de Recherche en Informatique et en Automatique.  #
#  Distributed only by permission.                                    #
#                                                                     #
#*********************************************************************#

include OMyMakeroot

17 18 19 20
############################################################## Warnings

# For release, -warn-error should not be put

21
OCAMLFLAGS= -w A-4-9-40-42-44-45-37-41-48
22 23 24 25 26 27

# For the development, -warn-error A is turned on
if $(file-exists DEV)
   OCAMLFLAGS += -warn-error A
   export

28
########################################## External arguments
29 30 31 32 33 34 35 36

# Specify directories where X's rgb.txt can be found
PATH_RGB_TXT[]=
  /etc/X11
  /usr/share/X11

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

37
VERSION=4.2.0
38 39 40 41 42 43 44 45 46

# for src/META
PACKAGE_NAME=camlimages
PACKAGE_VERSION=$(VERSION)

OCAMLMKLIB=ocamlmklib

##################################################### Auto configuration

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
with_default(def, varname) =
    if $(not $(defined $(varname))) 
      return $(def)
    else
      getvar($(varname))

true_if_not_defined(var)=
    with_default(true, $(var))

failwith_if_defined(var, msg) =
  if $(defined $(var)):
      eprintln(Error: $(msg))
      exit 1

get_have(varname) =
    with_default(false, this.HAVE_$(varname)) # this required

get_support(varname) =
    with_default(false, this.SUPPORT_$(varname)) # this required

# CFLAGS_xxx and LDFLAGS_xxx must exist
get_flags(varname) =
    cflags = $(getvar this.CFLAGS_$(varname))
    ldflags = $(getvar this.LDFLAGS_$(varname))
    value $(string $(cflags) $(ldflags))

73 74 75 76
print_configured() =
  println(--- Configuring)
  println(wordsize  $(WORD_SIZE))
  println(--- C libraries)
77 78 79 80 81 82 83
  println(libgif:   $(get_have GIF))
  println(libpng:   $(get_have PNG))
  println(libjpeg:  $(get_have JPEG))
  println(libexif:  $(get_have EXIF))
  println(libtiff:  $(get_have TIFF))
  println(libxpm:   $(get_have XPM))
  println(libz:     $(get_have Z))
84
  println(--- Subpackages)
85 86 87 88 89 90 91 92 93 94 95
  println(gif:      $(get_support GIF) \($(get_flags gif)\))
  println(png:      $(get_support PNG) \($(get_flags png)\))
  println(jpeg:     $(get_support JPEG) \($(get_flags jpeg)\))
  println(exif:     $(get_support EXIF) \($(get_flags exif)\))
  println(tiff:     $(get_support TIFF) \($(get_flags tiff)\))
  println(xpm:      $(get_support XPM) \($(get_flags xpm)\))
  println(freetype: $(get_support FREETYPE) \($(PATH_FREETYPE_CONFIG)\) \($(get_flags freetype)\))
  println(ps:       $(get_support PS) \($(PATH_GS)\))
  println(rgb.txt:  $(get_support RGB_TXT) \($(string $(PATH_RGB_TXT))\))
  println(lablgtk2: $(get_support LABLGTK2))
  println(graphics: $(get_support GRAPHICS))
96
  println(--- Summary)
97 98 99
  println(supported subpackages: $(string $(SUPPORTED_SUBPACKAGES)))
  println(supported formats:     $(string $(SUPPORTED_FORMATS)))
  println(supported non-formats: $(string $(SUPPORTED_NON_FORMATS)))
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
  println(---)

.STATIC:
  # Variables must be initialized inside .STATIC, if they should be
  # exported out.

  if $(not $(OCAMLFIND_EXISTS))
     eprintln(This project requires ocamlfind\, but is was not found.)
     eprintln(You need to install ocamlfind and run "omake --configure".)
     exit 1

  OCAMLMKLIB_EXISTS = $(CheckProg $(OCAMLMKLIB))
  if $(not $(OCAMLMKLIB_EXISTS))
     eprintln(This project requires ocamlmklib, but is was not found.)
     eprintln(You need to install ocamlmklib and run "omake --configure".)
     exit 1

117 118 119 120 121
  BYTE_ENABLED=1
  if $(not $(defined NATIVE_ENABLED)):
      setvar(public.NATIVE_ENABLED, 1)
      export

122 123 124
  WORD_SIZE = $(Word_size)

  # Image formats implemented using external libraries or binaries
125
  FORMATS= gif png jpeg exif tiff xpm ps
126 127 128 129 130 131 132 133 134 135 136 137 138

  # Image formats with necessary libraries supported
  SUPPORTED_FORMATS[]=

  # GUI/font rendering libraries supported
  SUPPORTED_NON_FORMATS[]=

  # SUPPORTED_FORMATS + SUPPORTED_NON_FORMATS
  SUPPORTED_SUBPACKAGES[]=

  # OCaml packages found likable
  OCAMLPACKS[]=

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
  # pkg-config

  if $(true_if_not_defined ARG_WANT_PKG_CONFIG)
    if $(defined ARG_PATH_PKG_CONFIG):
        PATH_PKG_CONFIG = $(ARG_PATH_PKG_CONFIG)
        export
    else
        PATH_PKG_CONFIG = $(Check_prog_in_path pkg-config)
        export
    export

  # Zlib

  HAVE_Z = $(Check_header_library z, zlib.h, zlibVersion)

154
  # GIF
155
  CFLAGS_gif=
156
  LDFLAGS_gif=
157
  SUPPORT_GIF=false 
158
  if $(true_if_not_defined ARG_WANT_GIF)
159
    if $(not $(pkg_config_between_vers gif, libgif, 4.0.0, 5.0.0))
160 161 162 163 164 165 166 167
      HAVE_GIF = $(Check_header_library gif, gif_lib.h, DGifOpenFileName)
      SUPPORT_GIF = $(HAVE_GIF)
      if $(SUPPORT_GIF)
        LDFLAGS_gif=-lgif
        export
      else
        failwith_if_defined(ARG_WANT_GIF, gif requested but not found)
      export
168 169 170
    if $(SUPPORT_GIF)
      SUPPORTED_FORMATS+=gif
      export
171 172
    export

173
  # PNG
174
  CFLAGS_png=
175
  LDFLAGS_png=
176
  SUPPORT_PNG=false 
177
  if $(true_if_not_defined ARG_WANT_PNG)
178 179
    # we need a separate statement to get the vars defined in pkg_config reflected.
    res=$(pkg_config png, libpng)
180 181 182 183 184 185 186 187 188
    if $(not $(res))
      HAVE_PNG = $(Check_header_library png, png.h, png_create_read_struct)
      SUPPORT_PNG = $(and $(HAVE_Z) $(HAVE_PNG))
      if $(SUPPORT_PNG)
        LDFLAGS_png=-lpng -lz
        export
      else
        failwith_if_defined(ARG_WANT_PNG, png requested but not found)
      export
189 190 191
    if $(SUPPORT_PNG)
      SUPPORTED_FORMATS+=png
      export
192 193
    export

194
  # JPEG
195
  CFLAGS_jpeg=
196
  LDFLAGS_jpeg=
197
  SUPPORT_JPEG=false 
198
  if $(true_if_not_defined ARG_WANT_JPEG)
199 200 201 202 203 204 205 206 207 208
    res=$(pkg_config jpeg, libjpeg)
    if $(not $(res))
      HAVE_JPEG = $(Check_header_library jpeg, jpeglib.h, jpeg_read_header)
      SUPPORT_JPEG = $(HAVE_JPEG)
      if $(SUPPORT_JPEG)
        LDFLAGS_jpeg=-ljpeg
        export
      else
        failwith_if_defined(ARG_WANT_JPEG, jpeg requested but not found)
      export
209 210 211
    if $(SUPPORT_JPEG)
      SUPPORTED_FORMATS+=jpeg
      export
212 213
    export

214
  # EXIF
215
  CFLAGS_exif=
216
  LDFLAGS_exif=
217
  SUPPORT_EXIF=false 
218
  if $(true_if_not_defined ARG_WANT_EXIF)
219 220 221 222 223 224 225 226 227 228
    res=$(pkg_config exif, libexif)
    if $(not $(res))
      HAVE_EXIF = $(Check_header_library exif, exif-data.h, exif_data_load_data)
      SUPPORT_EXIF = $(HAVE_EXIF)
      if $(SUPPORT_EXIF)
        LDFLAGS_exif=-lexif
        export
      else
        failwith_if_defined(ARG_WANT_EXIF, exif requested but not found)
      export
229 230 231 232 233 234
    if $(SUPPORT_EXIF)
      SUPPORTED_FORMATS+=exif
      export
    export

  # TIFF
235
  CFLAGS_tiff=
236
  LDFLAGS_tiff=
237
  SUPPORT_TIFF=false 
238
  if $(true_if_not_defined ARG_WANT_TIFF)
239 240 241 242 243 244 245 246 247 248 249 250 251
    res=$(pkg_config tiff, libtiff-4)
    if $(not $(res))
      HAVE_TIFF = $(Check_header_library tiff, tiff.h, TIFFOpen)
      # CR jfuruse: libtiff depends on jpeg and z too, which are required for -static.
      # Impossible to resolve all the cases:
      # the current OCaml cma has no capability to have different lib flags for dyn and static	
      SUPPORT_TIFF = $(HAVE_TIFF)
      if $(SUPPORT_TIFF)
        LDFLAGS_tiff=-ltiff
        export
      else
        failwith_if_defined(ARG_WANT_TIFF, tiff requested but not found)
      export
252 253 254
    if $(SUPPORT_TIFF)
      SUPPORTED_FORMATS+=tiff
      export
255 256
    export

257
  # XPM
258
  CFLAGS_xpm=
259
  LDFLAGS_xpm=
260
  SUPPORT_XPM=false 
261
  if $(true_if_not_defined ARG_WANT_XPM)
262 263 264 265 266 267 268 269 270 271
    res=$(pkg_config xpm, xpm)
    if $(not $(res))
      HAVE_XPM = $(Check_header_library Xpm, X11/xpm.h, XpmReadFileToXpmImage)
      SUPPORT_XPM = $(HAVE_XPM)
      if $(SUPPORT_XPM)
        LDFLAGS_xpm=-lXpm
        export
      else
        failwith_if_defined(ARG_WANT_XPM, xpm requested but not found)
      export
272 273 274
    if $(SUPPORT_XPM)
      SUPPORTED_FORMATS+=xpm
      export
275 276
    export

277
  # PS
278
  CFLAGS_ps=
279
  LDFLAGS_ps=
280
  SUPPORT_PS=false 
281 282 283
  if $(true_if_not_defined ARG_WANT_GS)
    if $(defined ARG_PATH_GS):
        PATH_GS = $(ARG_PATH_GS)
284 285 286 287 288
        SUPPORT_PS=true
        export
    else
        PATH_GS=$(Check_prog_in_path gs)
        SUPPORT_PS=$(if $(PATH_GS), true, false)
289 290 291 292 293 294
        export
    if $(SUPPORT_PS)
      SUPPORTED_FORMATS+=ps
      export
    else
      failwith_if_defined(ARG_WANT_GS, ps requested but not found)
295 296
    export

297
  # LABLGTK2
298 299 300
  CFLAGS_lablgtk2=
  LDFLAGS_lablgtk2=
  SUPPORT_LABLGTK2=false 
301 302 303 304 305 306 307 308
  if $(true_if_not_defined ARG_WANT_LABLGTK2)
    SUPPORT_LABLGTK2 = $(Check_ocamlfind_package lablgtk2)
    if $(SUPPORT_LABLGTK2)
      SUPPORTED_NON_FORMATS+=lablgtk2
      OCAMLPACKS+=lablgtk2
      export
    else
      failwith_if_defined(ARG_WANT_LABLGTK2, lablgtk2 requested but not found)
309 310
    export

311
  # GRAPHICS
312 313 314
  CFLAGS_graphics=
  LDFLAGS_graphics=
  SUPPORT_GRAPHICS=false 
315 316 317 318 319 320 321 322 323
  if $(true_if_not_defined ARG_WANT_GRAPHICS)
    # CR: ocamlfind registers graphics even if not available
    SUPPORT_GRAPHICS = $(Check_ocamlfind_package_compilation graphics, Graphics)
    if $(SUPPORT_GRAPHICS)
      SUPPORTED_NON_FORMATS+=graphics
      OCAMLPACKS+=graphics
      export
    else
      failwith_if_defined(ARG_WANT_GRAPHICS, graphics requested but not found)
324 325
    export

326
  # FREETYPE
327
  CFLAGS_freetype=
328
  LDFLAGS_freetype=
329
  SUPPORT_FREETYPE=false 
330
  if $(true_if_not_defined ARG_WANT_FREETYPE)
331 332 333 334 335 336 337 338
    PATH_FREETYPE_CONFIG=
    if $(defined ARG_PATH_FREETYPE_CONFIG):
        PATH_FREETYPE_CONFIG = $(ARG_PATH_FREETYPE_CONFIG)
        SUPPORT_FREETYPE = true
        export
    else
        PATH_FREETYPE_CONFIG = $(Check_prog_in_path freetype-config)
        SUPPORT_FREETYPE=$(if $(PATH_FREETYPE_CONFIG), true, false)
339 340 341
        export
    if $(SUPPORT_FREETYPE)
      # println(SUPPORT_FREETYPE=$(SUPPORT_FREETYPE)!)
342 343
      CFLAGS_freetype= $(shell $(PATH_FREETYPE_CONFIG) --cflags)
      LDFLAGS_freetype= $(shell $(PATH_FREETYPE_CONFIG) --libs)
344 345 346 347 348 349
      export
    if $(SUPPORT_FREETYPE)
      SUPPORTED_NON_FORMATS+=freetype
      export
    else
      failwith_if_defined(ARG_WANT_FREETYPE, freetype requested but not found)
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
    export

  SUPPORTED_SUBPACKAGES= $(SUPPORTED_FORMATS) $(SUPPORTED_NON_FORMATS)

  SUPPORT_RGB_TXT = $(Check_file_in_path $(PATH_RGB_TXT), rgb.txt)
  PATH_RGB_TXT = $(WHERE)

  print_configured()

# for config.h
CGeneratedFiles(config.h)
section:
  PACKAGE=\"camlimages\"
  PACKAGE_BUGREPORT=\"jun.furuse@gmail.com\"
  PACKAGE_NAME=$(PACKAGE)
  PACKAGE_STRING=\"camlimages $(VERSION)\"
  PACKAGE_TARNAME=$(PACKAGE)
  PACKAGE_VERSION=\"$(VERSION)\"
  SIZEOF_LONG=$(WORD_SIZE)
  VERSION=$(PACKAGE_VERSION)
  ConfReplaceConfigH(config.h)

372 373 374
.PHONY: configure
configure:

375
.SUBDIRS: src test examples