OMakefile 11 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 22
# OCAMLFLAGS= -w A-4-9-35-37-40-41-42-44-45-48
OCAMLFLAGS= -w A-3-4-9-37-40-41-42-44-45-41-48-50 -safe-string
23 24 25

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

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

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

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

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

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

OCAMLMKLIB=ocamlmklib

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

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
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))

74 75 76 77
print_configured() =
  println(--- Configuring)
  println(wordsize  $(WORD_SIZE))
  println(--- C libraries)
78 79 80 81 82 83 84
  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))
85
  println(--- Subpackages)
86 87 88 89 90 91 92 93 94 95 96
  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))
97
  println(--- Summary)
98 99 100
  println(supported subpackages: $(string $(SUPPORTED_SUBPACKAGES)))
  println(supported formats:     $(string $(SUPPORTED_FORMATS)))
  println(supported non-formats: $(string $(SUPPORTED_NON_FORMATS)))
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
  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

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

123 124 125
  WORD_SIZE = $(Word_size)

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

  # 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[]=

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
  # 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)

155
  # GIF
156
  CFLAGS_gif=
157
  LDFLAGS_gif=
158
  SUPPORT_GIF=false 
159
  if $(true_if_not_defined ARG_WANT_GIF)
160
    if $(not $(pkg_config_between_vers gif, libgif, 4.0.0, 5.0.0))
161 162 163 164 165 166 167 168
      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
169 170 171
    if $(SUPPORT_GIF)
      SUPPORTED_FORMATS+=gif
      export
172 173
    export

174
  # PNG
175
  CFLAGS_png=
176
  LDFLAGS_png=
177
  SUPPORT_PNG=false 
178
  if $(true_if_not_defined ARG_WANT_PNG)
179 180
    # we need a separate statement to get the vars defined in pkg_config reflected.
    res=$(pkg_config png, libpng)
181 182 183 184 185 186 187 188 189
    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
190 191 192
    if $(SUPPORT_PNG)
      SUPPORTED_FORMATS+=png
      export
193 194
    export

195
  # JPEG
196
  CFLAGS_jpeg=
197
  LDFLAGS_jpeg=
198
  SUPPORT_JPEG=false 
199
  if $(true_if_not_defined ARG_WANT_JPEG)
200 201 202 203 204 205 206 207 208 209
    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
210 211 212
    if $(SUPPORT_JPEG)
      SUPPORTED_FORMATS+=jpeg
      export
213 214
    export

215
  # EXIF
216
  CFLAGS_exif=
217
  LDFLAGS_exif=
218
  SUPPORT_EXIF=false 
219
  if $(true_if_not_defined ARG_WANT_EXIF)
220 221 222 223 224 225 226 227 228 229
    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
230 231 232 233 234 235
    if $(SUPPORT_EXIF)
      SUPPORTED_FORMATS+=exif
      export
    export

  # TIFF
236
  CFLAGS_tiff=
237
  LDFLAGS_tiff=
238
  SUPPORT_TIFF=false 
239
  if $(true_if_not_defined ARG_WANT_TIFF)
240 241 242 243 244 245 246 247 248 249 250 251 252
    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
253 254 255
    if $(SUPPORT_TIFF)
      SUPPORTED_FORMATS+=tiff
      export
256 257
    export

258
  # XPM
259
  CFLAGS_xpm=
260
  LDFLAGS_xpm=
261
  SUPPORT_XPM=false 
262
  if $(true_if_not_defined ARG_WANT_XPM)
263 264 265 266 267 268 269 270 271 272
    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
273 274 275
    if $(SUPPORT_XPM)
      SUPPORTED_FORMATS+=xpm
      export
276 277
    export

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

298
  # LABLGTK2
299 300 301
  CFLAGS_lablgtk2=
  LDFLAGS_lablgtk2=
  SUPPORT_LABLGTK2=false 
302 303 304 305 306 307 308 309
  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)
310 311
    export

312
  # GRAPHICS
313 314 315
  CFLAGS_graphics=
  LDFLAGS_graphics=
  SUPPORT_GRAPHICS=false 
316 317 318 319 320 321 322 323 324
  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)
325 326
    export

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

373 374 375
.PHONY: configure
configure:

376
.SUBDIRS: src test examples