Commits

camlspotter committed 5b69a15

CFLAGS from pkg-config

Comments (0)

Files changed (3)

 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))
+
 print_configured() =
   println(--- Configuring)
   println(wordsize  $(WORD_SIZE))
   println(libxpm:   $(get_have XPM))
   println(libz:     $(get_have Z))
   println(--- Subpackages)
-  println(gif:      $(get_support GIF) \($(string $(LDFLAGS_gif)\)))
-  println(png:      $(get_support PNG) \($(string $(LDFLAGS_png)\)))
-  println(jpeg:     $(get_support JPEG) \($(string $(LDFLAGS_jpeg)\)))
-  println(exif:     $(get_support EXIF) \($(string $(LDFLAGS_exif)\)))
-  println(tiff:     $(get_support TIFF) \($(string $(LDFLAGS_tiff)\)))
-  println(xpm:      $(get_support XPM) \($(string $(LDFLAGS_xpm)\)))
-  println(freetype: $(get_support FREETYPE) \($(PATH_FREETYPE_CONFIG)\) \($(string $(LDFLAGS_freetype))\))
+  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(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(---)
 
 .STATIC:
       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
   HAVE_Z = $(Check_header_library z, zlib.h, zlibVersion)
 
   # GIF
+  CFLAGS_gif=
   LDFLAGS_gif=
   if $(true_if_not_defined ARG_WANT_GIF)
     if $(not $(pkg_config gif, libgif))
-      HAVE_GIF = $(Check_header_library gif, gif_lib.h, DGifOpenFileName)
+      HAVE_GIF = $(Check_header_library gif, gif_lib.h, DGifOpenFileNamex)
       SUPPORT_GIF = $(HAVE_GIF)
       if $(SUPPORT_GIF)
         LDFLAGS_gif=-lgif
     export
 
   # PNG
+  CFLAGS_png=
   LDFLAGS_png=
   if $(true_if_not_defined ARG_WANT_PNG)
     res=$(pkg_config png, libpng) # we need a separate statement to get the vars defined in pkg_config reflected.
     export
 
   # JPEG
+  CFLAGS_jpeg=
   LDFLAGS_jpeg=
   if $(true_if_not_defined ARG_WANT_JPEG)
     res=$(pkg_config jpeg, libjpeg)
     export
 
   # EXIF
+  CFLAGS_exif=
   LDFLAGS_exif=
   if $(true_if_not_defined ARG_WANT_EXIF)
     res=$(pkg_config exif, libexif)
     export
 
   # TIFF
+  CFLAGS_tiff=
   LDFLAGS_tiff=
   if $(true_if_not_defined ARG_WANT_TIFF)
     res=$(pkg_config tiff, libtiff-4)
     export
 
   # XPM
+  CFLAGS_xpm=
   LDFLAGS_xpm=
   if $(true_if_not_defined ARG_WANT_XPM)
     res=$(pkg_config xpm, xpm)
     export
 
   # PS
+  CFLAGS_ps=
   LDFLAGS_ps=
   if $(true_if_not_defined ARG_WANT_GS)
     if $(defined ARG_PATH_GS):
     export
 
   # LABLGTK2
+  CFLAGS_lablgtk2=
+  LDFLAGS_lablgtk2=
   if $(true_if_not_defined ARG_WANT_LABLGTK2)
     SUPPORT_LABLGTK2 = $(Check_ocamlfind_package lablgtk2)
     if $(SUPPORT_LABLGTK2)
     export
 
   # GRAPHICS
+  CFLAGS_graphics=
+  LDFLAGS_graphics=
   if $(true_if_not_defined ARG_WANT_GRAPHICS)
     # CR: ocamlfind registers graphics even if not available
     SUPPORT_GRAPHICS = $(Check_ocamlfind_package_compilation graphics, Graphics)
     export
 
   # FREETYPE
+  CFLAGS_freetype=
   LDFLAGS_freetype=
   if $(true_if_not_defined ARG_WANT_FREETYPE)
     PATH_FREETYPE_CONFIG=
         export
     if $(SUPPORT_FREETYPE)
       # println(SUPPORT_FREETYPE=$(SUPPORT_FREETYPE)!)
-      CAMLIMAGES_CFLAGS+= $(shell $(PATH_FREETYPE_CONFIG) --cflags)
+      CFLAGS_freetype= $(shell $(PATH_FREETYPE_CONFIG) --cflags)
       LDFLAGS_freetype= $(shell $(PATH_FREETYPE_CONFIG) --libs)
       export
     if $(SUPPORT_FREETYPE)
   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:
 pkg_config(name, libname) =
   if $(and $(defined this.PATH_PKG_CONFIG), $(equal 0, $(shell-code $(PATH_PKG_CONFIG) $(libname))))
     println(Found pkg-config $(libname))
-    setvar(LDFLAGS_$(name), $(shell $(PATH_PKG_CONFIG) --libs $(libname)))
-    setvar(CFLAGS_$(name), $(shell $(PATH_PKG_CONFIG) --cflags $(libname)))
-    setvar(SUPPORT_$(uppercase $(name)), true)
-    setvar(HAVE_$(uppercase $(name)), true)
+    # this is required since it is called in .STATIC
+    setvar(this.LDFLAGS_$(name), $(shell $(PATH_PKG_CONFIG) --libs $(libname)))
+    setvar(this.CFLAGS_$(name), $(shell $(PATH_PKG_CONFIG) --cflags $(libname)))
+    setvar(this.SUPPORT_$(uppercase $(name)), true)
+    setvar(this.HAVE_$(uppercase $(name)), true)
     export
     value true
   else 
 
 ################################################################## C BUILD RULE
 
-CFLAGS+= -fPIC -I $(OCAML_WHERE)
+CFLAGS_supported=
+  x=
+  foreach(p, $(SUPPORTED_SUBPACKAGES))
+    x+= $(getvar CFLAGS_$(p))
+    export
+  value $(x)
+
+CFLAGS+= -fPIC -I $(OCAML_WHERE) $(CFLAGS_supported)
 
 MakeLibC(name) =
   OCamlMkLibC($(LIBRARY_PREFIX)_$(name), \
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.