Makefile.introspection 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # -*- Mode: make -*-
  2. # Copyright 2009-2010 Johan Dahlin
  3. #
  4. # This file is free software; the author(s) gives unlimited
  5. # permission to copy and/or distribute it, with or without
  6. # modifications, as long as this notice is preserved.
  7. #
  8. # * Input variables:
  9. #
  10. # INTROSPECTION_GIRS - List of GIRS that should be generated
  11. # INTROSPECTION_SCANNER - Command to invoke scanner, normally set by
  12. # GOBJECT_INTROSPECTION_REQUIRE/CHECK() in introspection.m4
  13. # INTROSPECTION_SCANNER_ARGS - Additional args to pass in to the scanner
  14. # INTROSPECTION_SCANNER_ENV - Environment variables to set before running
  15. # the scanner
  16. # INTROSPECTION_COMPILER - Command to invoke compiler, normally set by
  17. # GOBJECT_INTROSPECTION_REQUIRE/CHECK() in introspection.m4
  18. # INTROSPECTION_COMPILER_ARGS - Additional args to pass in to the compiler
  19. #
  20. # * Simple tutorial
  21. #
  22. # Add this to configure.ac:
  23. # -Wno-portability to AM_INIT_AUTOMAKE
  24. # GOBJECT_INTROSPECTION_CHECK([0.6.7])
  25. #
  26. # Add this to Makefile.am where your library/program is built:
  27. # include $(INTROSPECTION_MAKEFILE)
  28. # INTROSPECTION_GIRS = YourLib-1.0.gir
  29. # YourLib-1.0.gir: libyourlib.la
  30. # YourLib_1_0_gir_NAMESPACE = YourLib
  31. # YourLib_1_0_gir_VERSION = 1.0
  32. # YourLib_1_0_gir_LIBS = libyourlib.la
  33. # YourLib_1_0_gir_FILES = $(libyourlib_1_0_SOURCES)
  34. # girdir = $(datadir)/gir-1.0
  35. # dist_gir_DATA = YourLib-1.0.gir
  36. # typelibdir = $(libdir)/girepository-1.0
  37. # typelib_DATA = YourLib-1.0.typelib
  38. # CLEANFILES = $(dist_gir_DATA) $(typelib_DATA)
  39. #
  40. # Make sure the required variables are set, these should under normal
  41. # circumstances come from introspection.m4
  42. $(if $(INTROSPECTION_SCANNER),,$(error Need to define INTROSPECTION_SCANNER))
  43. $(if $(INTROSPECTION_COMPILER),,$(error Need to define INTROSPECTION_COMPILER))
  44. # Private functions
  45. ## Transform the gir filename to something which can reference through a variable
  46. ## without automake/make complaining, eg Gtk-2.0.gir -> Gtk_2_0_gir
  47. _gir_name = $(subst /,_,$(subst -,_,$(subst .,_,$(1))))
  48. # Namespace and Version is either fetched from the gir filename
  49. # or the _NAMESPACE/_VERSION variable combo
  50. _gir_namespace = $(or $($(_gir_name)_NAMESPACE),$(firstword $(subst -, ,$(notdir $(1)))))
  51. _gir_version = $(or $($(_gir_name)_VERSION),$(lastword $(subst -, ,$(1:.gir=))))
  52. # _PROGRAM is an optional variable which needs it's own --program argument
  53. _gir_program = $(if $($(_gir_name)_PROGRAM),--program=$($(_gir_name)_PROGRAM))
  54. # Variables which provides a list of things
  55. _gir_libraries = $(foreach lib,$($(_gir_name)_LIBS),--library=$(lib))
  56. _gir_packages = $(foreach pkg,$($(_gir_name)_PACKAGES),--pkg=$(pkg))
  57. _gir_includes = $(foreach include,$($(_gir_name)_INCLUDES),--include=$(include))
  58. _gir_export_packages = $(foreach pkg,$($(_gir_name)_EXPORT_PACKAGES),--pkg-export=$(pkg))
  59. # Reuse the LIBTOOL variable from automake if it's set, but
  60. # work around MSYS weirdness: When running g-ir-scanner, MSYS changes
  61. # a command-line argument --libtool="/bin/sh ../../libtool" into
  62. # --libtool=c:/opt/msys/1.0/bin/libtool. So just use sh.exe without path
  63. # because we already "know" where the libtool configure produced is.
  64. _gir_libtool = $(if $(findstring MINGW,$(shell uname -s)),--libtool="$(top_builddir)/libtool",$(if $(LIBTOOL),--libtool="$(LIBTOOL)"))
  65. # Macros for AM_SILENT_RULES prettiness
  66. _gir_verbosity = $(if $(AM_DEFAULT_VERBOSITY),$(AM_DEFAULT_VERBOSITY),1)
  67. _gir_silent_scanner_prefix = $(_gir_silent_scanner_prefix_$(V))
  68. _gir_silent_scanner_prefix_ = $(_gir_silent_scanner_prefix_$(_gir_verbosity))
  69. _gir_silent_scanner_prefix_0 = @echo " GISCAN $(1)";
  70. _gir_silent_scanner_opts = $(_gir_silent_scanner_opts_$(V))
  71. _gir_silent_scanner_opts_ = $(_gir_silent_scanner_opts_$(_gir_verbosity))
  72. _gir_silent_scanner_opts_0 = --quiet
  73. _gir_silent_compiler = $(_gir_silent_compiler_$(V))
  74. _gir_silent_compiler_ = $(_gir_silent_compiler_$(_gir_verbosity))
  75. _gir_silent_compiler_0 = @echo " GICOMP $(1)";
  76. _gir_default_scanner_env = CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" CC="$(CC)" PKG_CONFIG="$(PKG_CONFIG)" DLLTOOL="$(DLLTOOL)"
  77. #
  78. # Creates a GIR by scanning C headers/sources
  79. # $(1) - Name of the gir file (output)
  80. #
  81. # If output is Gtk-2.0.gir then you should name the variables like
  82. # Gtk_2_0_gir_NAMESPACE, Gtk_2_0_gir_VERSION etc.
  83. # Required variables:
  84. # FILES - C sources and headers which should be scanned
  85. #
  86. # One of these variables are required:
  87. # LIBS - Library where the symbol represented in the gir can be found
  88. # PROGRAM - Program where the symbol represented in the gir can be found
  89. #
  90. # Optional variables
  91. # NAMESPACE - Namespace of the gir, first letter capital,
  92. # rest should be lower case, for instance: 'Gtk', 'Clutter', 'ClutterGtk'.
  93. # If not present the namespace will be fetched from the gir filename,
  94. # the part before the first dash. For 'Gtk-2.0', namespace will be 'Gtk'.
  95. # VERSION - Version of the gir, if not present, will be fetched from gir
  96. # filename, the part after the first dash. For 'Gtk-2.0', version will be '2.0'.
  97. # LIBTOOL - Command to invoke libtool, usually set by automake
  98. # SCANNERFLAGS - Flags to pass in to the scanner, see g-ir-scanner(1) for a list
  99. # CFLAGS - Flags to pass in to the parser when scanning headers
  100. # LDFLAGS - Linker flags used by the scanner
  101. # PACKAGES - list of pkg-config names which cflags are required to parse
  102. # the headers of this gir
  103. # INCLUDES - Gir files to include without the .gir suffix, for instance
  104. # GLib-2.0, Gtk-2.0. This is needed for all libraries which you depend on that
  105. # provides introspection information.
  106. # EXPORT_PACKAGES - list of pkg-config names that are provided by this gir.
  107. # By default the names in the PACKAGES variable will be used.
  108. #
  109. define introspection-scanner
  110. # Basic sanity check, to make sure required variables are set
  111. $(if $($(_gir_name)_FILES),,$(error Need to define $(_gir_name)_FILES))
  112. $(if $(or $(findstring --header-only,$($(_gir_name)_SCANNERFLAGS)),
  113. $($(_gir_name)_LIBS),
  114. $($(_gir_name)_PROGRAM)),,
  115. $(error Need to define $(_gir_name)_LIBS or $(_gir_name)_PROGRAM))
  116. # Only dependencies we know are actually filenames goes into _FILES, make
  117. # sure these are built before running the scanner. Libraries and programs
  118. # needs to be added manually.
  119. $(1): $$($(_gir_name)_FILES)
  120. @ $(MKDIR_P) $(dir $(1))
  121. $(_gir_silent_scanner_prefix) $(_gir_default_scanner_env) $(INTROSPECTION_SCANNER_ENV) $(INTROSPECTION_SCANNER) $(_gir_silent_scanner_opts) \
  122. $(INTROSPECTION_SCANNER_ARGS) \
  123. --namespace=$(_gir_namespace) \
  124. --nsversion=$(_gir_version) \
  125. $(_gir_libtool) \
  126. $(_gir_packages) \
  127. $(_gir_includes) \
  128. $(_gir_export_packages) \
  129. $(_gir_program) \
  130. $(_gir_libraries) \
  131. $($(_gir_name)_SCANNERFLAGS) \
  132. --cflags-begin \
  133. $($(_gir_name)_CFLAGS) \
  134. --cflags-end \
  135. $($(_gir_name)_LDFLAGS) \
  136. $$^ \
  137. --output $(1)
  138. endef
  139. $(foreach gir,$(INTROSPECTION_GIRS),$(eval $(call introspection-scanner,$(gir))))
  140. #
  141. # Compiles a gir into a typelib
  142. # $(1): gir filename (input)
  143. # $(2): typelib filename (output)
  144. #
  145. define introspection-compiler
  146. $(_gir_silent_compiler) $(INTROSPECTION_COMPILER) $(INTROSPECTION_COMPILER_ARGS) --includedir=. $(1) -o $(2)
  147. endef
  148. # Simple rule to compile a typelib.
  149. %.typelib: %.gir
  150. $(call introspection-compiler,$<,$@)