Source

camlimages / OMakefile

#*********************************************************************#
#                                                                     #
#                          Caml Images                                #
#                                                                     #
#            Franis 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

########################################## External arguments

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

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

VERSION=4.1.0

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

OCAMLMKLIB=ocamlmklib

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

print_configured() =
  println(--- Configuring)
  println(wordsize  $(WORD_SIZE))
  println(--- C libraries)
  println(libgif:   $(HAVE_GIF))
  println(libpng:   $(HAVE_PNG))
  println(libjpeg:  $(HAVE_JPEG))
  println(libexif:  $(HAVE_EXIF))
  println(libtiff:  $(HAVE_TIFF))
  println(libxpm:   $(HAVE_XPM))
  println(libz:     $(HAVE_Z))
  println(--- Subpackages)
  println(gif:      $(SUPPORT_GIF) \($(string $(LDFLAGS_gif)\)))
  println(png:      $(SUPPORT_PNG) \($(string $(LDFLAGS_png)\)))
  println(jpeg:     $(SUPPORT_JPEG) \($(string $(LDFLAGS_jpeg)\)))
  println(exif:     $(SUPPORT_EXIF) \($(string $(LDFLAGS_exif)\)))
  println(tiff:     $(SUPPORT_TIFF) \($(string $(LDFLAGS_tiff)\)))
  println(xpm:      $(SUPPORT_XPM) \($(string $(LDFLAGS_xpm)\)))
  println(freetype: $(SUPPORT_FREETYPE) \($(PATH_FREETYPE_CONFIG)\) \($(string $(LDFLAGS_freetype))\))
  println(ps:       $(SUPPORT_PS) \($(PATH_GS)\))
  println(rgb.txt:  $(SUPPORT_RGB_TXT) \($(string $(PATH_RGB_TXT))\))
  println(lablgtk2: $(SUPPORT_LABLGTK2))
  println(graphics: $(SUPPORT_GRAPHICS))
  println(--- Summary)
  println(supported subpackages: $(string $(SUPPORTED_SUBPACKAGES)))
  println(supported formats:     $(string $(SUPPORTED_FORMATS)))
  println(supported non-formats: $(string $(SUPPORTED_NON_FORMATS)))
  println(--- Global compilation switch)
  # CFLAGS and LDFLAGS are already defined when print_configured()
  # is defined, so using CFLAGS here just prints the value of 
  # when this function is defined.
  # CR jfuruse: Something messy which I do not understand yet happens here!
  println(CFLAGS:   $(string $(CAMLIMAGES_CFLAGS)))
  println(LDFLAGS:  $(string $(CAMLIMAGES_LDFLAGS)))
  println(---)

true_if_not_defined(var)=
    if $(not $(defined $(var))) 
      true
    else
      value $(getvar $(var))

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

.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

  BYTE_ENABLED=1
  if $(not $(defined NATIVE_ENABLED)):
      setvar(public.NATIVE_ENABLED, 1)
      export

  # It seems changing CFLAGS and INCLUDES in .STATIC is not a good idea.
  CAMLIMAGES_CFLAGS = $(CFLAGS) $(addprefix -I , $(INCLUDES))

  WORD_SIZE = $(Word_size)

  # Image formats implemented using external libraries or binaries
  FORMATS= gif png jpeg exif tiff xpm ps

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

  # GIF
  SUPPORT_GIF=false
  LDFLAGS_gif=
  HAVE_GIF=
  if $(true_if_not_defined ARG_WANT_GIF)
    HAVE_GIF = $(Check_header_library gif, gif_lib.h, DGifOpenFileName)
    SUPPORT_GIF = $(HAVE_GIF)
    if $(SUPPORT_GIF)
      LDFLAGS_gif=-lgif
      SUPPORTED_FORMATS+=gif
      export
    else
      failwith_if_defined(ARG_WANT_GIF, gif requested but not found)
    export

  # PNG
  SUPPORT_PNG=false
  LDFLAGS_png=
  HAVE_Z=
  HAVE_PNG=
  if $(true_if_not_defined ARG_WANT_PNG)
    HAVE_Z = $(Check_header_library z, zlib.h, zlibVersion)
    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
      SUPPORTED_FORMATS+=png
      export
    else
      failwith_if_defined(ARG_WANT_PNG, png requested but not found)
    export

  # JPEG
  SUPPORT_JPEG=false
  LDFLAGS_jpeg=
  HAVE_JPEG=
  if $(true_if_not_defined ARG_WANT_JPEG)
    HAVE_JPEG = $(Check_header_library jpeg, jpeglib.h, jpeg_read_header)
    SUPPORT_JPEG = $(HAVE_JPEG)
    if $(SUPPORT_JPEG)
      LDFLAGS_jpeg=-ljpeg
      SUPPORTED_FORMATS+=jpeg
      export
    else
      failwith_if_defined(ARG_WANT_JPEG, jpeg requested but not found)
    export

  # EXIF
  SUPPORT_EXIF=false
  HAVE_EXIF=
  LDFLAGS_exif=
  if $(true_if_not_defined ARG_WANT_EXIF)
    HAVE_EXIF = $(Check_header_library exif, exif-data.h, exif_data_load_data)
    SUPPORT_EXIF = $(HAVE_EXIF)
    if $(SUPPORT_EXIF)
      LDFLAGS_exif=-lexif
      SUPPORTED_FORMATS+=exif
      export
    else
      failwith_if_defined(ARG_WANT_EXIF, exif requested but not found)
    export

  # TIFF
  SUPPORT_TIFF=false
  LDFLAGS_tiff=
  HAVE_TIFF=
  if $(true_if_not_defined ARG_WANT_TIFF)
    HAVE_TIFF = $(Check_header_library tiff, tiff.h, TIFFOpen)
    SUPPORT_TIFF = $(and $(HAVE_Z) $(HAVE_JPEG) $(HAVE_TIFF))
    if $(SUPPORT_TIFF)
      LDFLAGS_tiff=$(array -ltiff -ljpeg -lz)
      SUPPORTED_FORMATS+=tiff
      export
    else
      failwith_if_defined(ARG_WANT_TIFF, tiff requested but not found)
    export

  # XPM
  SUPPORT_XPM=false
  LDFLAGS_xpm=
  HAVE_XPM=
  if $(true_if_not_defined ARG_WANT_XPM)
    HAVE_XPM = $(Check_header_library Xpm, X11/xpm.h, XpmReadFileToXpmImage)
    SUPPORT_XPM = $(HAVE_XPM)
    if $(SUPPORT_XPM)
      LDFLAGS_xpm=-lXpm
      SUPPORTED_FORMATS+=xpm
      export
    else
      failwith_if_defined(ARG_WANT_XPM, xpm requested but not found)
    export

  # PS
  SUPPORT_PS=false
  $(Check_prog_in_path gs)
  PATH_GS=$(WHERE)
  LDFLAGS_ps=
  if $(true_if_not_defined ARG_WANT_GS)
    # SUPPORT_PS = $(Check_prog_in_path gs)
    SUPPORT_PS = true
    if $(defined ARG_PATH_GS):
        PATH_GS = $(ARG_PATH_GS)
        export
    if $(SUPPORT_PS)
      SUPPORTED_FORMATS+=ps
      export
    else
      failwith_if_defined(ARG_WANT_GS, ps requested but not found)
    export

  # LABLGTK2
  SUPPORT_LABLGTK2=false
  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)
    export

  # GRAPHICS
  SUPPORT_GRAPHICS=false
  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)
    export

  # FREETYPE
  SUPPORT_FREETYPE = false
  $(Check_prog_in_path freetype-config)
  PATH_FREETYPE_CONFIG = $(WHERE)
  LDFLAGS_freetype=
  if $(true_if_not_defined ARG_WANT_FREETYPE)
    # SUPPORT_FREETYPE = $(Check_prog_in_path freetype-config)
    SUPPORT_FREETYPE = true
    if $(defined ARG_FREETYPE_CONFIG):
        PATH_FREETYPE_CONFIG = $(ARG_FREETYPE_CONFIG)
        export
    if $(SUPPORT_FREETYPE)
      # println(SUPPORT_FREETYPE=$(SUPPORT_FREETYPE)!)
      CAMLIMAGES_CFLAGS+= $(shell freetype-config --cflags)
      LDFLAGS_freetype= $(shell freetype-config --libs)
      export
    if $(SUPPORT_FREETYPE)
      SUPPORTED_NON_FORMATS+=freetype
      export
    else
      failwith_if_defined(ARG_WANT_FREETYPE, freetype requested but not found)
    export

  SUPPORTED_SUBPACKAGES= $(SUPPORTED_FORMATS) $(SUPPORTED_NON_FORMATS)

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

  # CR jfuruse: Something messy which I do not understand yet happens here!
  CAMLIMAGES_LDFLAGS=$(LDFLAGS)
  print_configured()

# CR jfuruse: Something messy which I do not understand yet happens here!
CFLAGS=$(CAMLIMAGES_CFLAGS)
LDFLAGS=$(CAMLIMAGES_LDFLAGS)

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

.PHONY: configure
configure:

.SUBDIRS: src test examples
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.