1a244e0d56f58b8502a06d580b46a409ebbeb50b
[platform/upstream/atk.git] / win32 / Makefile.msvc-introspection
1 # Author: Fan, Chun-wei
2 # Common autotools file for constructing the g-ir-scanner and
3 # g-ir-compiler command lines for Visual Studio builds.
4
5 # This is copied from $(srcroot)/win32 from the gobject-introspection
6 # project, which may be included in projects that support both
7 # Visual Studio builds and introspection.
8
9 # * Input variables:
10 #
11 #   MSVC_INTROSPECT_GIRS - List of .gir's that should be built
12 #                          in the NMake Makefiles
13 #
14 # * Simple tutorial
15 #
16 # Add this to Makefile.am where your library/program is built:
17 #   (Either YourLib_1_0_gir_MSVC_LIBS or YourLib_1_0_gir_MSVC_PROGRAM
18 #    is required unless --headers-only is specified in
19 #    YourLib_1_0_gir__MSVC_SCANNERFLAGS)
20 #
21 #   include <this Makefile.msvc-introspection>
22 #   MSVC_INTROSPECT_GIRS = YourLib-1.0.gir
23 #   YourLib_1_0_gir_NAMESPACE = YourLib # This is optional
24 #   YourLib_1_0_gir_VERSION = 1.0 # This is optional
25 #   YourLib_1_0_gir_MSVC_LIBS = yourlib-1.0
26 #   YourLib_1_0_gir_MSVC_FILES = $(libyourlib_1_0_SOURCES)
27 #   YourLib_1_0_gir_MSVC_PROGRAM = YourProgram
28 #   YourLib_1_0_gir_MSVC_PACKAGES = (Dependent .pc files)
29 #   YourLib_1_0_gir_MSVC_INCLUDE_GIRS = (Dependent external .gir's)
30 #   YourLib_1_0_gir_MSVC_EXPORT_PACKAGES = (Packages exported by this .gir)
31 #   YourLib_1_0_gir_MSVC_C_INCLUDES = (List of public C headers which need to be included by
32 #                                      consumers at compile time to make use of the API)
33
34 # Private functions
35
36 ## Transform the MSVC project filename (no filename extensions) to something which can reference through a variable
37 ## without automake/make complaining, eg Gtk-2.0 -> Gtk_2_0
38 _gir_name=$(subst /,_,$(subst -,_,$(subst .,_,$(1))))
39
40 # Namespace and Version is either fetched from the gir filename
41 # or the _NAMESPACE/_VERSION variable combo
42 _gir_namespace_msvc = $(or $($(_gir_name)_NAMESPACE),$(firstword $(subst -, ,$(notdir $(1)))))
43 _gir_version_msvc = $(or $($(_gir_name)_VERSION),$(lastword $(subst -, ,$(1:.gir=))))
44 _typelib_basename_msvc = $(_gir_namespace_msvc)'-'$(_gir_version_msvc)
45
46 # _PROGRAM is an optional variable which needs its own --program argument
47 _gir_program_msvc = $(if $($(_gir_name)_MSVC_PROGRAM),--program=$($(_gir_name)_MSVC_PROGRAM))
48
49 # Deduce the sub-folder from $(srcroot) where the sources reside in
50 _gir_source_path_raw_msvc:=$(subst $(abs_top_srcdir),,$(abs_srcdir))
51 _gir_source_path_msvc=$(subst /,\\,$(_gir_source_path_raw_msvc))
52 _gir_source_subdir_int_msvc=$(subst \\\\,\\,\\$(_gir_source_path_msvc)\\)
53 _gir_source_subdir_msvc=$(subst \\.\\,\\,$(_gir_source_subdir_int_msvc))
54
55 _gir_files_raw_msvc=$(subst /,\\,$($(_gir_name)_MSVC_FILES))
56 _gir_files_msvc=$(subst $(srcdir)\\,,$(subst $(builddir)\\,,$(subst $(top_builddir)\\$(_gir_source_path_msvc)\\,\\,$(_gir_files_raw_msvc))))
57
58 # Create a list of items for:
59 # - Libraries
60 # - Packages
61 # - GIRs to include
62 # - packages to export
63
64 _gir_libraries_msvc = $(foreach lib,$($(_gir_name)_MSVC_LIBS),--library=$(lib))
65 _gir_packages_msvc = $(foreach pkg,$($(_gir_name)_MSVC_PACKAGES),--pkg=$(pkg))
66 _gir_includes_msvc = $(foreach include,$($(_gir_name)_MSVC_INCLUDE_GIRS),--include=$(include))
67 _gir_export_packages_msvc = $(foreach pkg,$($(_gir_name)_MSVC_EXPORT_PACKAGES),--pkg-export=$(pkg))
68 _gir_c_includes_msvc = $(foreach include,$($(_gir_name)_MSVC_C_INCLUDES),--c-include=$(include))
69
70 #
71 # Create NMake Makefile Sections for Building Introspection files
72 # from autotools files
73 # $(1) - File Name of the .gir that is to be generated
74 #
75
76 define gir-nmake-builder
77
78 # Basic sanity check, to make sure required variables are set
79 $(if $($(_gir_name)_MSVC_FILES),,$(error Need to define $(_gir_name)_MSVC_FILES))
80 $(if $(or $(findstring --header-only,$($(_gir_name)_MSVC_SCANNERFLAGS)),
81           $($(_gir_name)_MSVC_LIBS),
82           $($(_gir_name)_MSVC_PROGRAM)),,
83     $(error Need to define $(_gir_name)_MSVC_LIBS or $(_gir_name)_MSVC_PROGRAM))
84
85 $(top_builddir)/win32/$(_gir_name)_list:
86         for F in $(_gir_files_msvc); do \
87                 case $$$$F in \
88                 *.c|*.cpp|*.cc|*.cxx|*.h|*.hpp|*.hh|*.hxx) \
89                         echo '..'$(_gir_source_subdir_msvc)$$$$F >>$(top_builddir)/win32/$(_gir_name)_list \
90                         ;; \
91                 esac; \
92         done
93
94 $(top_builddir)/win32/$(1).msvc.introspect:
95         -$(RM) $(top_builddir)/win32/$(1).msvc.introspect
96
97 # Assemble the Command to Run g-ir-scanner
98         echo $(1)': '$(_gir_name)'_list '$($(_gir_name)_MSVC_GIR_DEPS)>>$(top_builddir)/win32/$(1).msvc.introspect
99         echo '  @-echo Generating $$$$@...'>>$(top_builddir)/win32/$(1).msvc.introspect
100         echo '  $$$$(PYTHON) $$$$(G_IR_SCANNER) \'>>$(top_builddir)/win32/$(1).msvc.introspect
101         echo '  --verbose -no-libtool   \'>>$(top_builddir)/win32/$(1).msvc.introspect
102         echo '  --namespace='$(_gir_namespace_msvc)'    \'>>$(top_builddir)/win32/$(1).msvc.introspect
103         echo '  --nsversion='$(_gir_version_msvc)'      \'>>$(top_builddir)/win32/$(1).msvc.introspect
104         echo '  '$(_gir_packages_msvc)' \'>>$(top_builddir)/win32/$(1).msvc.introspect
105         echo '  '$(_gir_libraries_msvc)'        \'>>$(top_builddir)/win32/$(1).msvc.introspect
106         echo '  '$(_gir_program_msvc)'  \'>>$(top_builddir)/win32/$(1).msvc.introspect
107         echo '  --add-include-path=$$$$(G_IR_INCLUDEDIR)        \'>>$(top_builddir)/win32/$(1).msvc.introspect
108         echo '  '$(_gir_includes_msvc)' \'>>$(top_builddir)/win32/$(1).msvc.introspect
109         echo '  '$(_gir_export_packages_msvc)'  \'>>$(top_builddir)/win32/$(1).msvc.introspect
110         echo '  '$(_gir_c_includes_msvc)'       \'>>$(top_builddir)/win32/$(1).msvc.introspect
111         echo '  --cflags-begin  \'>>$(top_builddir)/win32/$(1).msvc.introspect
112         echo '  '$($(_gir_name)_MSVC_CFLAGS)'   \'>>$(top_builddir)/win32/$(1).msvc.introspect
113         echo '  --cflags-end    \'>>$(top_builddir)/win32/$(1).msvc.introspect
114         echo '  '$($(_gir_name)_MSVC_SCANNERFLAGS)'     \'>>$(top_builddir)/win32/$(1).msvc.introspect
115         echo '  --filelist='$(_gir_name)'_list  \'>>$(top_builddir)/win32/$(1).msvc.introspect
116         echo '  -o $$$$@'>>$(top_builddir)/win32/$(1).msvc.introspect
117         echo '' >>$(top_builddir)/win32/$(1).msvc.introspect
118
119 # Finally Assemble the Command to Compile the generated .gir
120         echo '$(_typelib_basename_msvc).typelib: '$(_typelib_basename_msvc)'.gir'>>$(top_builddir)/win32/$(1).msvc.introspect
121         echo '  @-echo Compiling $$$$@...'>>$(top_builddir)/win32/$(1).msvc.introspect
122         echo '  $$$$(G_IR_COMPILER)     \'>>$(top_builddir)/win32/$(1).msvc.introspect
123         echo '  --includedir=. --debug --verbose        \'>>$(top_builddir)/win32/$(1).msvc.introspect
124         echo '  '$(1)'  \'>>$(top_builddir)/win32/$(1).msvc.introspect
125         echo '  -o $$$$@'>>$(top_builddir)/win32/$(1).msvc.introspect
126         echo '' >>$(top_builddir)/win32/$(1).msvc.introspect
127 endef
128
129 $(foreach gir,$(MSVC_INTROSPECT_GIRS),$(eval $(call gir-nmake-builder,$(gir))))