1 backend_build_deps = [backend_code]
3 backend_link_with = [pgport_srv, common_srv]
5 generated_backend_sources = []
21 subdir('partitioning')
33 subdir('po', if_found: libintl)
36 backend_link_args = []
37 backend_link_depends = []
40 # On windows when compiling with msvc we need to make postgres export all its
41 # symbols so that extension libraries can use them. For that we need to scan
42 # the constituting objects and generate a file specifying all the functions as
43 # exported (variables need an "import" declaration in the header, hence
44 # PGDLLEXPORT, but functions work without that, due to import libraries
45 # basically being trampolines).
47 # For dtrace probes we need to invoke dtrace on all input files, before
48 # linking the final executable (see more below).
51 # On meson there's currently no easy way to do this that I found. So we build
52 # a static library with all the input objects, run our script to generate
53 # exports, and build the final executable using that static library
55 # We could do that only if either dtrace or msvc is in use, but it seems
56 # easier to just always do so.
58 # Can't name the static library 'postgres', because msbuild ends up with a
59 # conflict for the .pdb file otherwise.
61 postgres_lib = static_library('postgres_lib',
62 backend_sources + timezone_sources + generated_backend_sources,
63 link_whole: backend_link_with,
64 dependencies: backend_build_deps,
65 kwargs: internal_lib_args,
68 if cc.get_id() == 'msvc'
69 postgres_def = custom_target('postgres.def',
70 command: [perl, files('../tools/msvc/gendef.pl'),
72 '--tempdir', '@PRIVATE_DIR@',
73 '--deffile', '@OUTPUT@',
75 input: [postgres_lib, common_srv, pgport_srv],
76 output: 'postgres.def',
77 depends: [postgres_lib, common_srv, pgport_srv],
79 build_by_default: false,
82 backend_link_args += '/DEF:@0@'.format(postgres_def.full_path())
83 backend_link_depends += postgres_def
85 elif host_system == 'aix'
86 # The '.' argument leads mkldexport.sh to emit "#! .", which refers to the
87 # main executable, allowing extension libraries to resolve their undefined
88 # symbols to symbols in the postgres binary.
89 postgres_imp = custom_target('postgres.imp',
90 command: [files('port/aix/mkldexport.sh'), '@INPUT@', '.'],
92 output: 'postgres.imp',
96 build_by_default: false,
98 backend_link_args += '-Wl,-bE:@0@'.format(postgres_imp.full_path())
99 backend_link_depends += postgres_imp
103 backend_objs = [postgres_lib.extract_all_objects(recursive: false)]
106 # The probes.o file is necessary for dtrace support on Solaris, and on recent
107 # versions of systemtap. (Older systemtap releases just produce an empty
108 # file, but that's okay.) However, macOS's dtrace doesn't use it and doesn't
109 # even recognize the -G option. So, build probes.o except on macOS.
110 # This might need adjustment as other platforms add dtrace support.
112 # On at least linux we don't actually need to pass in all the objects, but
113 # at least on FreeBSD and Solaris we have to.
115 # XXX: The reason we don't use the objects for generated sources is that
116 # hits a meson bug. Luckily we don't don't have probes in generated
118 if dtrace.found() and host_system != 'darwin'
119 backend_input += custom_target(
121 input: ['utils/probes.d', postgres_lib.extract_objects(backend_sources, timezone_sources)],
123 command: [dtrace, '-C', '-G', '-o', '@OUTPUT@', '-s', '@INPUT@'],
128 postgres = executable('postgres',
130 objects: backend_objs,
131 link_args: backend_link_args,
132 link_with: backend_link_with,
133 link_depends: backend_link_depends,
134 export_dynamic: true,
136 dependencies: backend_build_deps,
137 kwargs: default_bin_args,
140 backend_targets += postgres
142 pg_mod_c_args = cflags_mod
143 pg_mod_cpp_args = cxxflags_mod
144 pg_mod_link_args = ldflags_sl + ldflags_mod
145 pg_mod_link_depend = []
147 # A few platforms like MacOS and Windows link shared modules against postgres,
148 # or a [import] library derived from it. Set up the link flags for that.
149 if mod_link_args_fmt.length() > 0
150 # To avoid unnecessary build-time dependencies on other operating systems,
151 # only the dependency when it when necessary.
152 pg_mod_link_depend += postgres
154 name = mod_link_with_name.format('postgres')
155 link_with_uninst = meson.current_build_dir() / name
156 link_with_inst = '${@0@}/@1@'.format(mod_link_with_dir, name)
158 foreach el : mod_link_args_fmt
159 pg_mod_link_args += el.format(link_with_uninst)
164 # Note there's intentionally no dependency on pgport/common here - we want the
165 # symbols from the main binary for extension modules, rather than the
166 # extension linking separately to pgport/common.
167 backend_mod_code = declare_dependency(
168 compile_args: pg_mod_c_args,
169 include_directories: postgres_inc,
170 link_args: pg_mod_link_args,
171 sources: generated_headers + generated_backend_headers,
172 dependencies: backend_mod_deps,
175 pg_mod_args = default_mod_args + {
176 'dependencies': [backend_mod_code],
177 'cpp_args': pg_mod_cpp_args,
178 'link_depends': pg_mod_link_depend,
183 # Shared modules that, on some system, link against the server binary. Only
184 # enter these after we defined the server build.
187 subdir('replication/libpqwalreceiver')
188 subdir('replication/pgoutput')
190 subdir('utils/mb/conversion_procs')