We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Linker error while building gtkdoc
I'm trying to make GStreamer modules build with meson inside Cerbero. When it builds gtkdoc I get this error:

```
Error in gtkdoc helper script:
'gtkdoc-scangobj' failed with status 1
ld: unrecognized option '-Wl,-rpath,/home/xclaesse/programmation/cerbero/build/sources/linux_x86_64/gst-transcoder-1.9/cerbero-build-dir/'
ld: use the --help option for usage information
Linking of scanner failed: 
```

The exact command line that produce that error is:

```
gtkdoc-scangobj --types=/home/xclaesse/programmation/cerbero/build/sources/linux_x86_64/gst-transcoder-1.9/cerbero-build-dir/docs/libs/gst-transcoder.types --module=gst-transcoder --cflags="-I/home/xclaesse/programmation/cerbero/build/sources/linux_x86_64/gst-transcoder-1.9/cerbero-build-dir/gst-libs -I/home/xclaesse/programmation/cerbero/build/sources/linux_x86_64/gst-transcoder-1.9/gst-libs -I/home/xclaesse/programmation/cerbero/build/dist/linux_x86_64/include/glib-2.0 -I/home/xclaesse/programmation/cerbero/build/dist/linux_x86_64/lib/glib-2.0/include -pthread -I/home/xclaesse/programmation/cerbero/build/dist/linux_x86_64/include/gstreamer-1.0" --ldflags="-L/home/xclaesse/programmation/cerbero/build/sources/linux_x86_64/gst-transcoder-1.9/cerbero-build-dir/ -Wl,-rpath,/home/xclaesse/programmation/cerbero/build/sources/linux_x86_64/gst-transcoder-1.9/cerbero-build-dir/ -lgsttranscoder-1.0 -L/home/xclaesse/programmation/cerbero/build/dist/linux_x86_64/lib -lglib-2.0 -lgobject-2.0 -lgstreamer-1.0 -lgstpbutils-1.0"
```

GStreamer's gtkdoc seems to build fine with meson when using gst-build, so I don't understand what's the difference when ran inside cerbero env.

Any clue?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `mesonbuild/scripts/gtkdochelper.py`
Content:
```
1 # Copyright 2015-2016 The Meson development team
2 
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import sys, os
16 import subprocess
17 import shutil
18 import argparse
19 from ..mesonlib import MesonException, Popen_safe
20 from . import destdir_join
21 
22 parser = argparse.ArgumentParser()
23 
24 parser.add_argument('--sourcedir', dest='sourcedir')
25 parser.add_argument('--builddir', dest='builddir')
26 parser.add_argument('--subdir', dest='subdir')
27 parser.add_argument('--headerdirs', dest='headerdirs')
28 parser.add_argument('--mainfile', dest='mainfile')
29 parser.add_argument('--modulename', dest='modulename')
30 parser.add_argument('--htmlargs', dest='htmlargs', default='')
31 parser.add_argument('--scanargs', dest='scanargs', default='')
32 parser.add_argument('--scanobjsargs', dest='scanobjsargs', default='')
33 parser.add_argument('--gobjects-types-file', dest='gobject_typesfile', default='')
34 parser.add_argument('--fixxrefargs', dest='fixxrefargs', default='')
35 parser.add_argument('--mkdbargs', dest='mkdbargs', default='')
36 parser.add_argument('--ld', dest='ld', default='')
37 parser.add_argument('--cc', dest='cc', default='')
38 parser.add_argument('--ldflags', dest='ldflags', default='')
39 parser.add_argument('--cflags', dest='cflags', default='')
40 parser.add_argument('--content-files', dest='content_files', default='')
41 parser.add_argument('--expand-content-files', dest='expand_content_files', default='')
42 parser.add_argument('--html-assets', dest='html_assets', default='')
43 parser.add_argument('--ignore-headers', dest='ignore_headers', default='')
44 parser.add_argument('--namespace', dest='namespace', default='')
45 parser.add_argument('--mode', dest='mode', default='')
46 parser.add_argument('--installdir', dest='install_dir')
47 
48 def gtkdoc_run_check(cmd, cwd):
49     # Put stderr into stdout since we want to print it out anyway.
50     # This preserves the order of messages.
51     p, out = Popen_safe(cmd, cwd=cwd, stderr=subprocess.STDOUT)[0:2]
52     if p.returncode != 0:
53         err_msg = ["{!r} failed with status {:d}".format(cmd[0], p.returncode)]
54         if out:
55             err_msg.append(out)
56         raise MesonException('\n'.join(err_msg))
57 
58 def build_gtkdoc(source_root, build_root, doc_subdir, src_subdirs,
59                  main_file, module,
60                  html_args, scan_args, fixxref_args, mkdb_args,
61                  gobject_typesfile, scanobjs_args, ld, cc, ldflags, cflags,
62                  html_assets, content_files, ignore_headers, namespace,
63                  expand_content_files, mode):
64     print("Building documentation for %s" % module)
65 
66     src_dir_args = []
67     for src_dir in src_subdirs:
68         if not os.path.isabs(src_dir):
69             dirs = [os.path.join(source_root, src_dir),
70                     os.path.join(build_root, src_dir)]
71         else:
72             dirs = [src_dir]
73         src_dir_args += ['--source-dir=' + d for d in dirs]
74 
75     doc_src = os.path.join(source_root, doc_subdir)
76     abs_out = os.path.join(build_root, doc_subdir)
77     htmldir = os.path.join(abs_out, 'html')
78 
79     content_files += [main_file]
80     sections = os.path.join(doc_src, module + "-sections.txt")
81     if os.path.exists(sections):
82         content_files.append(sections)
83 
84     overrides = os.path.join(doc_src, module + "-overrides.txt")
85     if os.path.exists(overrides):
86         content_files.append(overrides)
87 
88     # Copy files to build directory
89     for f in content_files:
90         f_abs = os.path.join(doc_src, f)
91         shutil.copyfile(f_abs, os.path.join(
92             abs_out, os.path.basename(f_abs)))
93 
94     shutil.rmtree(htmldir, ignore_errors=True)
95     try:
96         os.mkdir(htmldir)
97     except Exception:
98         pass
99 
100     for f in html_assets:
101         f_abs = os.path.join(doc_src, f)
102         shutil.copyfile(f_abs, os.path.join(htmldir, os.path.basename(f_abs)))
103 
104     scan_cmd = ['gtkdoc-scan', '--module=' + module] + src_dir_args
105     if ignore_headers:
106         scan_cmd.append('--ignore-headers=' + ' '.join(ignore_headers))
107     # Add user-specified arguments
108     scan_cmd += scan_args
109     gtkdoc_run_check(scan_cmd, abs_out)
110 
111     if gobject_typesfile:
112         scanobjs_cmd = ['gtkdoc-scangobj'] + scanobjs_args + ['--types=' + gobject_typesfile,
113                                                               '--module=' + module,
114                                                               '--cflags=' + cflags,
115                                                               '--ldflags=' + ldflags]
116 
117         gtkdoc_run_check(scanobjs_cmd, abs_out)
118 
119     # Make docbook files
120     if mode == 'auto':
121         # Guessing is probably a poor idea but these keeps compat
122         # with previous behavior
123         if main_file.endswith('sgml'):
124             modeflag = '--sgml-mode'
125         else:
126             modeflag = '--xml-mode'
127     elif mode == 'xml':
128         modeflag = '--xml-mode'
129     elif mode == 'sgml':
130         modeflag = '--sgml-mode'
131     else: # none
132         modeflag = None
133 
134     mkdb_cmd = ['gtkdoc-mkdb',
135                 '--module=' + module,
136                 '--output-format=xml',
137                 '--expand-content-files=' + ' '.join(expand_content_files),
138                 ] + src_dir_args
139     if namespace:
140         mkdb_cmd.append('--name-space=' + namespace)
141     if modeflag:
142         mkdb_cmd.append(modeflag)
143     if len(main_file) > 0:
144         # Yes, this is the flag even if the file is in xml.
145         mkdb_cmd.append('--main-sgml-file=' + main_file)
146     # Add user-specified arguments
147     mkdb_cmd += mkdb_args
148     gtkdoc_run_check(mkdb_cmd, abs_out)
149 
150     # Make HTML documentation
151     mkhtml_cmd = ['gtkdoc-mkhtml',
152                   '--path=' + ':'.join((doc_src, abs_out)),
153                   module,
154                   ] + html_args
155     if len(main_file) > 0:
156         mkhtml_cmd.append('../' + main_file)
157     else:
158         mkhtml_cmd.append('%s-docs.xml' % module)
159     # html gen must be run in the HTML dir
160     gtkdoc_run_check(mkhtml_cmd, os.path.join(abs_out, 'html'))
161 
162     # Fix cross-references in HTML files
163     fixref_cmd = ['gtkdoc-fixxref',
164                   '--module=' + module,
165                   '--module-dir=html'] + fixxref_args
166     gtkdoc_run_check(fixref_cmd, abs_out)
167 
168 def install_gtkdoc(build_root, doc_subdir, install_prefix, datadir, module):
169     source = os.path.join(build_root, doc_subdir, 'html')
170     final_destination = os.path.join(install_prefix, datadir, module)
171     shutil.rmtree(final_destination, ignore_errors=True)
172     shutil.copytree(source, final_destination)
173 
174 def run(args):
175     options = parser.parse_args(args)
176     if len(options.htmlargs) > 0:
177         htmlargs = options.htmlargs.split('@@')
178     else:
179         htmlargs = []
180     if len(options.scanargs) > 0:
181         scanargs = options.scanargs.split('@@')
182     else:
183         scanargs = []
184     if len(options.scanobjsargs) > 0:
185         scanobjsargs = options.scanobjsargs.split('@@')
186     else:
187         scanobjsargs = []
188     if len(options.fixxrefargs) > 0:
189         fixxrefargs = options.fixxrefargs.split('@@')
190     else:
191         fixxrefargs = []
192     if len(options.mkdbargs) > 0:
193         mkdbargs = options.mkdbargs.split('@@')
194     else:
195         mkdbargs = []
196     build_gtkdoc(
197         options.sourcedir,
198         options.builddir,
199         options.subdir,
200         options.headerdirs.split('@@'),
201         options.mainfile,
202         options.modulename,
203         htmlargs,
204         scanargs,
205         fixxrefargs,
206         mkdbargs,
207         options.gobject_typesfile,
208         scanobjsargs,
209         options.ld,
210         options.cc,
211         options.ldflags,
212         options.cflags,
213         options.html_assets.split('@@') if options.html_assets else [],
214         options.content_files.split('@@') if options.content_files else [],
215         options.ignore_headers.split('@@') if options.ignore_headers else [],
216         options.namespace,
217         options.expand_content_files.split('@@') if options.expand_content_files else [],
218         options.mode)
219 
220     if 'MESON_INSTALL_PREFIX' in os.environ:
221         destdir = os.environ.get('DESTDIR', '')
222         install_prefix = destdir_join(destdir, os.environ['MESON_INSTALL_PREFIX'])
223         install_dir = options.install_dir if options.install_dir else options.modulename
224         if os.path.isabs(install_dir):
225             install_dir = destdir_join(destdir, install_dir)
226         install_gtkdoc(options.builddir,
227                        options.subdir,
228                        install_prefix,
229                        'share/gtk-doc/html',
230                        install_dir)
231     return 0
232 
233 if __name__ == '__main__':
234     sys.exit(run(sys.argv[1:]))
235
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/mesonbuild/scripts/gtkdochelper.py b/mesonbuild/scripts/gtkdochelper.py
--- a/mesonbuild/scripts/gtkdochelper.py
+++ b/mesonbuild/scripts/gtkdochelper.py
@@ -112,7 +112,8 @@
         scanobjs_cmd = ['gtkdoc-scangobj'] + scanobjs_args + ['--types=' + gobject_typesfile,
                                                               '--module=' + module,
                                                               '--cflags=' + cflags,
-                                                              '--ldflags=' + ldflags]
+                                                              '--ldflags=' + ldflags,
+                                                              '--ld=' + ld]
 
         gtkdoc_run_check(scanobjs_cmd, abs_out)

{"golden_diff": "diff --git a/mesonbuild/scripts/gtkdochelper.py b/mesonbuild/scripts/gtkdochelper.py\n--- a/mesonbuild/scripts/gtkdochelper.py\n+++ b/mesonbuild/scripts/gtkdochelper.py\n@@ -112,7 +112,8 @@\n         scanobjs_cmd = ['gtkdoc-scangobj'] + scanobjs_args + ['--types=' + gobject_typesfile,\n                                                               '--module=' + module,\n                                                               '--cflags=' + cflags,\n-                                                              '--ldflags=' + ldflags]\n+                                                              '--ldflags=' + ldflags,\n+                                                              '--ld=' + ld]\n \n         gtkdoc_run_check(scanobjs_cmd, abs_out)\n", "issue": "Linker error while building gtkdoc\nI'm trying to make GStreamer modules build with meson inside Cerbero. When it builds gtkdoc I get this error:\r\n\r\n```\r\nError in gtkdoc helper script:\r\n'gtkdoc-scangobj' failed with status 1\r\nld: unrecognized option '-Wl,-rpath,/home/xclaesse/programmation/cerbero/build/sources/linux_x86_64/gst-transcoder-1.9/cerbero-build-dir/'\r\nld: use the --help option for usage information\r\nLinking of scanner failed: \r\n```\r\n\r\nThe exact command line that produce that error is:\r\n\r\n```\r\ngtkdoc-scangobj --types=/home/xclaesse/programmation/cerbero/build/sources/linux_x86_64/gst-transcoder-1.9/cerbero-build-dir/docs/libs/gst-transcoder.types --module=gst-transcoder --cflags=\"-I/home/xclaesse/programmation/cerbero/build/sources/linux_x86_64/gst-transcoder-1.9/cerbero-build-dir/gst-libs -I/home/xclaesse/programmation/cerbero/build/sources/linux_x86_64/gst-transcoder-1.9/gst-libs -I/home/xclaesse/programmation/cerbero/build/dist/linux_x86_64/include/glib-2.0 -I/home/xclaesse/programmation/cerbero/build/dist/linux_x86_64/lib/glib-2.0/include -pthread -I/home/xclaesse/programmation/cerbero/build/dist/linux_x86_64/include/gstreamer-1.0\" --ldflags=\"-L/home/xclaesse/programmation/cerbero/build/sources/linux_x86_64/gst-transcoder-1.9/cerbero-build-dir/ -Wl,-rpath,/home/xclaesse/programmation/cerbero/build/sources/linux_x86_64/gst-transcoder-1.9/cerbero-build-dir/ -lgsttranscoder-1.0 -L/home/xclaesse/programmation/cerbero/build/dist/linux_x86_64/lib -lglib-2.0 -lgobject-2.0 -lgstreamer-1.0 -lgstpbutils-1.0\"\r\n```\r\n\r\nGStreamer's gtkdoc seems to build fine with meson when using gst-build, so I don't understand what's the difference when ran inside cerbero env.\r\n\r\nAny clue?\n", "before_files": [{"content": "# Copyright 2015-2016 The Meson development team\n\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n\n#     http://www.apache.org/licenses/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport sys, os\nimport subprocess\nimport shutil\nimport argparse\nfrom ..mesonlib import MesonException, Popen_safe\nfrom . import destdir_join\n\nparser = argparse.ArgumentParser()\n\nparser.add_argument('--sourcedir', dest='sourcedir')\nparser.add_argument('--builddir', dest='builddir')\nparser.add_argument('--subdir', dest='subdir')\nparser.add_argument('--headerdirs', dest='headerdirs')\nparser.add_argument('--mainfile', dest='mainfile')\nparser.add_argument('--modulename', dest='modulename')\nparser.add_argument('--htmlargs', dest='htmlargs', default='')\nparser.add_argument('--scanargs', dest='scanargs', default='')\nparser.add_argument('--scanobjsargs', dest='scanobjsargs', default='')\nparser.add_argument('--gobjects-types-file', dest='gobject_typesfile', default='')\nparser.add_argument('--fixxrefargs', dest='fixxrefargs', default='')\nparser.add_argument('--mkdbargs', dest='mkdbargs', default='')\nparser.add_argument('--ld', dest='ld', default='')\nparser.add_argument('--cc', dest='cc', default='')\nparser.add_argument('--ldflags', dest='ldflags', default='')\nparser.add_argument('--cflags', dest='cflags', default='')\nparser.add_argument('--content-files', dest='content_files', default='')\nparser.add_argument('--expand-content-files', dest='expand_content_files', default='')\nparser.add_argument('--html-assets', dest='html_assets', default='')\nparser.add_argument('--ignore-headers', dest='ignore_headers', default='')\nparser.add_argument('--namespace', dest='namespace', default='')\nparser.add_argument('--mode', dest='mode', default='')\nparser.add_argument('--installdir', dest='install_dir')\n\ndef gtkdoc_run_check(cmd, cwd):\n    # Put stderr into stdout since we want to print it out anyway.\n    # This preserves the order of messages.\n    p, out = Popen_safe(cmd, cwd=cwd, stderr=subprocess.STDOUT)[0:2]\n    if p.returncode != 0:\n        err_msg = [\"{!r} failed with status {:d}\".format(cmd[0], p.returncode)]\n        if out:\n            err_msg.append(out)\n        raise MesonException('\\n'.join(err_msg))\n\ndef build_gtkdoc(source_root, build_root, doc_subdir, src_subdirs,\n                 main_file, module,\n                 html_args, scan_args, fixxref_args, mkdb_args,\n                 gobject_typesfile, scanobjs_args, ld, cc, ldflags, cflags,\n                 html_assets, content_files, ignore_headers, namespace,\n                 expand_content_files, mode):\n    print(\"Building documentation for %s\" % module)\n\n    src_dir_args = []\n    for src_dir in src_subdirs:\n        if not os.path.isabs(src_dir):\n            dirs = [os.path.join(source_root, src_dir),\n                    os.path.join(build_root, src_dir)]\n        else:\n            dirs = [src_dir]\n        src_dir_args += ['--source-dir=' + d for d in dirs]\n\n    doc_src = os.path.join(source_root, doc_subdir)\n    abs_out = os.path.join(build_root, doc_subdir)\n    htmldir = os.path.join(abs_out, 'html')\n\n    content_files += [main_file]\n    sections = os.path.join(doc_src, module + \"-sections.txt\")\n    if os.path.exists(sections):\n        content_files.append(sections)\n\n    overrides = os.path.join(doc_src, module + \"-overrides.txt\")\n    if os.path.exists(overrides):\n        content_files.append(overrides)\n\n    # Copy files to build directory\n    for f in content_files:\n        f_abs = os.path.join(doc_src, f)\n        shutil.copyfile(f_abs, os.path.join(\n            abs_out, os.path.basename(f_abs)))\n\n    shutil.rmtree(htmldir, ignore_errors=True)\n    try:\n        os.mkdir(htmldir)\n    except Exception:\n        pass\n\n    for f in html_assets:\n        f_abs = os.path.join(doc_src, f)\n        shutil.copyfile(f_abs, os.path.join(htmldir, os.path.basename(f_abs)))\n\n    scan_cmd = ['gtkdoc-scan', '--module=' + module] + src_dir_args\n    if ignore_headers:\n        scan_cmd.append('--ignore-headers=' + ' '.join(ignore_headers))\n    # Add user-specified arguments\n    scan_cmd += scan_args\n    gtkdoc_run_check(scan_cmd, abs_out)\n\n    if gobject_typesfile:\n        scanobjs_cmd = ['gtkdoc-scangobj'] + scanobjs_args + ['--types=' + gobject_typesfile,\n                                                              '--module=' + module,\n                                                              '--cflags=' + cflags,\n                                                              '--ldflags=' + ldflags]\n\n        gtkdoc_run_check(scanobjs_cmd, abs_out)\n\n    # Make docbook files\n    if mode == 'auto':\n        # Guessing is probably a poor idea but these keeps compat\n        # with previous behavior\n        if main_file.endswith('sgml'):\n            modeflag = '--sgml-mode'\n        else:\n            modeflag = '--xml-mode'\n    elif mode == 'xml':\n        modeflag = '--xml-mode'\n    elif mode == 'sgml':\n        modeflag = '--sgml-mode'\n    else: # none\n        modeflag = None\n\n    mkdb_cmd = ['gtkdoc-mkdb',\n                '--module=' + module,\n                '--output-format=xml',\n                '--expand-content-files=' + ' '.join(expand_content_files),\n                ] + src_dir_args\n    if namespace:\n        mkdb_cmd.append('--name-space=' + namespace)\n    if modeflag:\n        mkdb_cmd.append(modeflag)\n    if len(main_file) > 0:\n        # Yes, this is the flag even if the file is in xml.\n        mkdb_cmd.append('--main-sgml-file=' + main_file)\n    # Add user-specified arguments\n    mkdb_cmd += mkdb_args\n    gtkdoc_run_check(mkdb_cmd, abs_out)\n\n    # Make HTML documentation\n    mkhtml_cmd = ['gtkdoc-mkhtml',\n                  '--path=' + ':'.join((doc_src, abs_out)),\n                  module,\n                  ] + html_args\n    if len(main_file) > 0:\n        mkhtml_cmd.append('../' + main_file)\n    else:\n        mkhtml_cmd.append('%s-docs.xml' % module)\n    # html gen must be run in the HTML dir\n    gtkdoc_run_check(mkhtml_cmd, os.path.join(abs_out, 'html'))\n\n    # Fix cross-references in HTML files\n    fixref_cmd = ['gtkdoc-fixxref',\n                  '--module=' + module,\n                  '--module-dir=html'] + fixxref_args\n    gtkdoc_run_check(fixref_cmd, abs_out)\n\ndef install_gtkdoc(build_root, doc_subdir, install_prefix, datadir, module):\n    source = os.path.join(build_root, doc_subdir, 'html')\n    final_destination = os.path.join(install_prefix, datadir, module)\n    shutil.rmtree(final_destination, ignore_errors=True)\n    shutil.copytree(source, final_destination)\n\ndef run(args):\n    options = parser.parse_args(args)\n    if len(options.htmlargs) > 0:\n        htmlargs = options.htmlargs.split('@@')\n    else:\n        htmlargs = []\n    if len(options.scanargs) > 0:\n        scanargs = options.scanargs.split('@@')\n    else:\n        scanargs = []\n    if len(options.scanobjsargs) > 0:\n        scanobjsargs = options.scanobjsargs.split('@@')\n    else:\n        scanobjsargs = []\n    if len(options.fixxrefargs) > 0:\n        fixxrefargs = options.fixxrefargs.split('@@')\n    else:\n        fixxrefargs = []\n    if len(options.mkdbargs) > 0:\n        mkdbargs = options.mkdbargs.split('@@')\n    else:\n        mkdbargs = []\n    build_gtkdoc(\n        options.sourcedir,\n        options.builddir,\n        options.subdir,\n        options.headerdirs.split('@@'),\n        options.mainfile,\n        options.modulename,\n        htmlargs,\n        scanargs,\n        fixxrefargs,\n        mkdbargs,\n        options.gobject_typesfile,\n        scanobjsargs,\n        options.ld,\n        options.cc,\n        options.ldflags,\n        options.cflags,\n        options.html_assets.split('@@') if options.html_assets else [],\n        options.content_files.split('@@') if options.content_files else [],\n        options.ignore_headers.split('@@') if options.ignore_headers else [],\n        options.namespace,\n        options.expand_content_files.split('@@') if options.expand_content_files else [],\n        options.mode)\n\n    if 'MESON_INSTALL_PREFIX' in os.environ:\n        destdir = os.environ.get('DESTDIR', '')\n        install_prefix = destdir_join(destdir, os.environ['MESON_INSTALL_PREFIX'])\n        install_dir = options.install_dir if options.install_dir else options.modulename\n        if os.path.isabs(install_dir):\n            install_dir = destdir_join(destdir, install_dir)\n        install_gtkdoc(options.builddir,\n                       options.subdir,\n                       install_prefix,\n                       'share/gtk-doc/html',\n                       install_dir)\n    return 0\n\nif __name__ == '__main__':\n    sys.exit(run(sys.argv[1:]))\n", "path": "mesonbuild/scripts/gtkdochelper.py"}], "after_files": [{"content": "# Copyright 2015-2016 The Meson development team\n\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n\n#     http://www.apache.org/licenses/LICENSE-2.0\n\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport sys, os\nimport subprocess\nimport shutil\nimport argparse\nfrom ..mesonlib import MesonException, Popen_safe\nfrom . import destdir_join\n\nparser = argparse.ArgumentParser()\n\nparser.add_argument('--sourcedir', dest='sourcedir')\nparser.add_argument('--builddir', dest='builddir')\nparser.add_argument('--subdir', dest='subdir')\nparser.add_argument('--headerdirs', dest='headerdirs')\nparser.add_argument('--mainfile', dest='mainfile')\nparser.add_argument('--modulename', dest='modulename')\nparser.add_argument('--htmlargs', dest='htmlargs', default='')\nparser.add_argument('--scanargs', dest='scanargs', default='')\nparser.add_argument('--scanobjsargs', dest='scanobjsargs', default='')\nparser.add_argument('--gobjects-types-file', dest='gobject_typesfile', default='')\nparser.add_argument('--fixxrefargs', dest='fixxrefargs', default='')\nparser.add_argument('--mkdbargs', dest='mkdbargs', default='')\nparser.add_argument('--ld', dest='ld', default='')\nparser.add_argument('--cc', dest='cc', default='')\nparser.add_argument('--ldflags', dest='ldflags', default='')\nparser.add_argument('--cflags', dest='cflags', default='')\nparser.add_argument('--content-files', dest='content_files', default='')\nparser.add_argument('--expand-content-files', dest='expand_content_files', default='')\nparser.add_argument('--html-assets', dest='html_assets', default='')\nparser.add_argument('--ignore-headers', dest='ignore_headers', default='')\nparser.add_argument('--namespace', dest='namespace', default='')\nparser.add_argument('--mode', dest='mode', default='')\nparser.add_argument('--installdir', dest='install_dir')\n\ndef gtkdoc_run_check(cmd, cwd):\n    # Put stderr into stdout since we want to print it out anyway.\n    # This preserves the order of messages.\n    p, out = Popen_safe(cmd, cwd=cwd, stderr=subprocess.STDOUT)[0:2]\n    if p.returncode != 0:\n        err_msg = [\"{!r} failed with status {:d}\".format(cmd[0], p.returncode)]\n        if out:\n            err_msg.append(out)\n        raise MesonException('\\n'.join(err_msg))\n\ndef build_gtkdoc(source_root, build_root, doc_subdir, src_subdirs,\n                 main_file, module,\n                 html_args, scan_args, fixxref_args, mkdb_args,\n                 gobject_typesfile, scanobjs_args, ld, cc, ldflags, cflags,\n                 html_assets, content_files, ignore_headers, namespace,\n                 expand_content_files, mode):\n    print(\"Building documentation for %s\" % module)\n\n    src_dir_args = []\n    for src_dir in src_subdirs:\n        if not os.path.isabs(src_dir):\n            dirs = [os.path.join(source_root, src_dir),\n                    os.path.join(build_root, src_dir)]\n        else:\n            dirs = [src_dir]\n        src_dir_args += ['--source-dir=' + d for d in dirs]\n\n    doc_src = os.path.join(source_root, doc_subdir)\n    abs_out = os.path.join(build_root, doc_subdir)\n    htmldir = os.path.join(abs_out, 'html')\n\n    content_files += [main_file]\n    sections = os.path.join(doc_src, module + \"-sections.txt\")\n    if os.path.exists(sections):\n        content_files.append(sections)\n\n    overrides = os.path.join(doc_src, module + \"-overrides.txt\")\n    if os.path.exists(overrides):\n        content_files.append(overrides)\n\n    # Copy files to build directory\n    for f in content_files:\n        f_abs = os.path.join(doc_src, f)\n        shutil.copyfile(f_abs, os.path.join(\n            abs_out, os.path.basename(f_abs)))\n\n    shutil.rmtree(htmldir, ignore_errors=True)\n    try:\n        os.mkdir(htmldir)\n    except Exception:\n        pass\n\n    for f in html_assets:\n        f_abs = os.path.join(doc_src, f)\n        shutil.copyfile(f_abs, os.path.join(htmldir, os.path.basename(f_abs)))\n\n    scan_cmd = ['gtkdoc-scan', '--module=' + module] + src_dir_args\n    if ignore_headers:\n        scan_cmd.append('--ignore-headers=' + ' '.join(ignore_headers))\n    # Add user-specified arguments\n    scan_cmd += scan_args\n    gtkdoc_run_check(scan_cmd, abs_out)\n\n    if gobject_typesfile:\n        scanobjs_cmd = ['gtkdoc-scangobj'] + scanobjs_args + ['--types=' + gobject_typesfile,\n                                                              '--module=' + module,\n                                                              '--cflags=' + cflags,\n                                                              '--ldflags=' + ldflags,\n                                                              '--ld=' + ld]\n\n        gtkdoc_run_check(scanobjs_cmd, abs_out)\n\n    # Make docbook files\n    if mode == 'auto':\n        # Guessing is probably a poor idea but these keeps compat\n        # with previous behavior\n        if main_file.endswith('sgml'):\n            modeflag = '--sgml-mode'\n        else:\n            modeflag = '--xml-mode'\n    elif mode == 'xml':\n        modeflag = '--xml-mode'\n    elif mode == 'sgml':\n        modeflag = '--sgml-mode'\n    else: # none\n        modeflag = None\n\n    mkdb_cmd = ['gtkdoc-mkdb',\n                '--module=' + module,\n                '--output-format=xml',\n                '--expand-content-files=' + ' '.join(expand_content_files),\n                ] + src_dir_args\n    if namespace:\n        mkdb_cmd.append('--name-space=' + namespace)\n    if modeflag:\n        mkdb_cmd.append(modeflag)\n    if len(main_file) > 0:\n        # Yes, this is the flag even if the file is in xml.\n        mkdb_cmd.append('--main-sgml-file=' + main_file)\n    # Add user-specified arguments\n    mkdb_cmd += mkdb_args\n    gtkdoc_run_check(mkdb_cmd, abs_out)\n\n    # Make HTML documentation\n    mkhtml_cmd = ['gtkdoc-mkhtml',\n                  '--path=' + ':'.join((doc_src, abs_out)),\n                  module,\n                  ] + html_args\n    if len(main_file) > 0:\n        mkhtml_cmd.append('../' + main_file)\n    else:\n        mkhtml_cmd.append('%s-docs.xml' % module)\n    # html gen must be run in the HTML dir\n    gtkdoc_run_check(mkhtml_cmd, os.path.join(abs_out, 'html'))\n\n    # Fix cross-references in HTML files\n    fixref_cmd = ['gtkdoc-fixxref',\n                  '--module=' + module,\n                  '--module-dir=html'] + fixxref_args\n    gtkdoc_run_check(fixref_cmd, abs_out)\n\ndef install_gtkdoc(build_root, doc_subdir, install_prefix, datadir, module):\n    source = os.path.join(build_root, doc_subdir, 'html')\n    final_destination = os.path.join(install_prefix, datadir, module)\n    shutil.rmtree(final_destination, ignore_errors=True)\n    shutil.copytree(source, final_destination)\n\ndef run(args):\n    options = parser.parse_args(args)\n    if len(options.htmlargs) > 0:\n        htmlargs = options.htmlargs.split('@@')\n    else:\n        htmlargs = []\n    if len(options.scanargs) > 0:\n        scanargs = options.scanargs.split('@@')\n    else:\n        scanargs = []\n    if len(options.scanobjsargs) > 0:\n        scanobjsargs = options.scanobjsargs.split('@@')\n    else:\n        scanobjsargs = []\n    if len(options.fixxrefargs) > 0:\n        fixxrefargs = options.fixxrefargs.split('@@')\n    else:\n        fixxrefargs = []\n    if len(options.mkdbargs) > 0:\n        mkdbargs = options.mkdbargs.split('@@')\n    else:\n        mkdbargs = []\n    build_gtkdoc(\n        options.sourcedir,\n        options.builddir,\n        options.subdir,\n        options.headerdirs.split('@@'),\n        options.mainfile,\n        options.modulename,\n        htmlargs,\n        scanargs,\n        fixxrefargs,\n        mkdbargs,\n        options.gobject_typesfile,\n        scanobjsargs,\n        options.ld,\n        options.cc,\n        options.ldflags,\n        options.cflags,\n        options.html_assets.split('@@') if options.html_assets else [],\n        options.content_files.split('@@') if options.content_files else [],\n        options.ignore_headers.split('@@') if options.ignore_headers else [],\n        options.namespace,\n        options.expand_content_files.split('@@') if options.expand_content_files else [],\n        options.mode)\n\n    if 'MESON_INSTALL_PREFIX' in os.environ:\n        destdir = os.environ.get('DESTDIR', '')\n        install_prefix = destdir_join(destdir, os.environ['MESON_INSTALL_PREFIX'])\n        install_dir = options.install_dir if options.install_dir else options.modulename\n        if os.path.isabs(install_dir):\n            install_dir = destdir_join(destdir, install_dir)\n        install_gtkdoc(options.builddir,\n                       options.subdir,\n                       install_prefix,\n                       'share/gtk-doc/html',\n                       install_dir)\n    return 0\n\nif __name__ == '__main__':\n    sys.exit(run(sys.argv[1:]))\n", "path": "mesonbuild/scripts/gtkdochelper.py"}]}