summaryrefslogtreecommitdiffstats
path: root/source-builder/config/gdb-common-1.cfg
blob: 49bf6733d15fee1e7a50cdc315535fc4efb2407f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#
# GDB Common Version 1.
#
# This configuration file configure's, make's and install's gdb.
#

#
# Python
#
# GDB uses python internally so we need to link to a suitable python
# dev kit. The dev kit for python is the header and a library. These
# files are versioned where the header file is located in a directory
# based on:
#
#  pythonM.m/Python.h
#
# where 'M' is the major version number and 'm' is the minor verison
# number. The library is:
#
#  libpythonM.m.a
#
# The python command is 'pythonM' which means we need to query it for
# the minor number.
#
# The python running the RSB may not be suitable, for example a MSC,
# MSYS or Cygwin version on Windows when we want the MinGW python dev
# file. A specific version cannot be forced because older versions of
# GDB can only link to 'python2'.
#
# Host support can perform a complex query of the system, for example
# Windows and set '%{gdb_python2}' and '%{gdb_python3}' with the full
# path to that version's executable.
#
# A configuration of GDB can set the version required by setting
# '%{gdb-python-version}' to the versions command, eg python2.
#
# The procedure is:
#
# 1. If the macros '%{gdb_python2}' or '%{gdb_python3}' are present
#    use that path they contain. Assume the path is valid.
#
# 2. Does the version of gdb specify a version of python that must be
#    used. Override with '%define gdb-python-version python2'.
#
# 3. Search for 'python3' and if not found search for 'python2'.
#
# User options to help find a suitable python:
#
# --with-python2 : name of a python2 command
#
# --with-python3 : name of a python2 command
#
# --with-python-version : name of a python command with a specific version
#
# For example `--with-python-version=python3.6
#
%if %{defined with_python2}
 %define gdb-python2 %{with_python2}
%endif
%if %{defined with_python3}
 %define gdb-python3 %{with_python3}
%endif
%if %{defined with_python_version}
 %define gdb-python-version %{with_python_version}
%endif
%if %{defined gdb-python2}
  %define gdb-enable-python %{gdb_python2}
%else
  %if %{defined gdb-python3}
    %define gdb-enable-python %{gdb_python3}
  %else
    %if %{defined gdb-python-version}
      %define gdb-enable-python %(command -v %{gdb-python-version} || true)
    %else
      %define gdb-enable-python %(command -v python3 || true)
      %if %{gdb-enable-python} == %{nil}
        %define gdb-enable-python %(command -v python2 || true)
      %endif
      %if %{gdb-enable-python} == %{nil}
        %define gdb-enable-python %(command -v python || true})
      %endif
    %endif
    %if %{gdb-enable-python} == %{nil}
      %error "gdb: python: no valid version of python found"
    %endif
  %endif
%endif

#
# Get the Python's major and minor version from the python
# command. The headers and libraries are installed under a major/minor
# (mm) version path and name.
#
# The library file name can vary across the hosts so wildcard the search.
#
%if %{!defined gdb-python-config}
  %define gdb-python-config %{nil}
%endif
%if %{gdb-python-config} == %{nil}
 %define gdb-python-config %(command -v %{gdb-enable-python}-config || true)
 %if %{gdb-python-config} == %{nil}
  %define gdb-python-config %(command -v %(basename %{gdb-enable-python})-config || true)
 %endif
%endif
%define gdb-python-ver-mm %(%{gdb-enable-python} --version 2>&1 | sed -e 's/.* //g' | rev | cut -d'.' -f2- | rev)
%define gdb-python-ver-major %(echo "%{gdb-python-ver-mm}" | sed -e 's/\..*//')
%define gdb-python-ver-minor %(echo "%{gdb-python-ver-mm}" | sed -e 's/.*\.//')
%define gdb-python-header Python.h
%define gdb-python-ver-header python%{gdb-python-ver-mm}/%{gdb-python-header}
%define gdb-python-ver-lib libpython%{gdb-python-ver-mm}.*
%if %{host_includes} == %{nil}
  %define gdb-host-incs %{nil}
%else
  %define gdb-host-incs -I '%{host_includes}'
%endif
%if %{gdb-python-config} != %{nil}
  %define gdb-python-config-incs -I '%(%{gdb-python-config} --includes)'
  %define gdb-python-header-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-incs} %{gdb-python-config-incs} -H %{gdb-python-header})
%else
  %define gdb-python-header-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-incs} -H %{gdb-python-ver-header})
%endif
%if %{gdb-python-header-check} == not-found && !%{_rsb_getting_source}
  %error "gdb: python: header file not found: %{gdb-python-ver-header}, please install"
%endif
%if %{host_ldflags} == %{nil}
  %define gdb-host-libs %{nil}
%else
  %define gdb-host-libs -L '%{host_ldflags}'
%endif
%if %{gdb-python-config} != %{nil}
  %define gdb-python-lib-filter awk '{for(i=1;i<NF;++i)if(match($i,".*lpython.*")) print "lib"substr($i,3)"\\*";}'
  %define gdb-python-libpath-filter awk '{for(i=1;i<NF;++i) if (match($i,"-L.*") == 1) l[substr($i,3)]=1;} END{for(i in l) printf("-L " i " "); printf("\n");}'
  %if %{gdb-python-ver-major} < 3 || \
      %{gdb-python-ver-major} == 3 && %{gdb-python-ver-minor} < 8
      %define gdb-python-config-lib-check-flags --ldflags
  %else
      %define gdb-python-config-lib-check-flags --ldflags --embed
  %endif
  %define gdb-python-config-libs %(%{gdb-python-config} %{gdb-python-config-lib-check-flags} | %{gdb-python-lib-filter})
  %define gdb-python-config-libpath %(%{gdb-python-config} %{gdb-python-config-lib-check-flags} | %{gdb-python-libpath-filter} | uniq)
  %define gdb-python-lib-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-libs} %{gdb-python-config-libpath} -l %{gdb-python-config-libs})
%else
  %define gdb-python-lib-check %(%{_sbdir}/sb/rtems-build-dep -c %{__cc} %{gdb-host-libs} -l %{gdb-python-ver-lib})
%endif
%if %{gdb-python-lib-check} == not-found && !%{_rsb_getting_source}
  %error "gdb: python: library file not found: %{gdb-python-ver-lib}, please install"
%endif

#
# If in a virtual environment use that as GDB will look 'bin/python' under it
# Supportted in GDB 13 and later.
#
%define gdb_version_major %(echo "%{gdb_version}" | sed -e 's/\..*//')
%if %{gdb_version_major} >= 13
  %define python-venv %(echo $VIRTUAL_ENV)
  %if %{python-venv} != %{nil}
    %define gdb-enable-python %{python-venv}
  %endif
%endif

#
# See if the simulator has been disabled for Windows.
#
# Build using the system's readline, it is in better shape
# than GDB's one with MSYS2.
#
%if %{_host_os} == win32
 %if %{defined win32-gdb-disable-sim}
  %define gdb-disable-sim 1
 %endif
 %define with_system_readline 1
%endif

#
# Default to building simulators.
#
%ifn %{defined gdb-disable-sim}
 %define gdb-disable-sim 0
%else
 %undefine gdb-sim-options
%endif

%include %{_configdir}/checks.cfg

#
# Select Snapshot Macro Maps
#
%select gdb-snapshot
%select expat-snapshot

#
# The description.
#
Name:      %{_target}-gdb-%{gdb_version}-%{_host}-%{release}
Summary:   GDB v%{gdb_version} for target %{_target} on host %{_host}
Version:   %{gdb_version}
Release:   %{release}
URL:       http://www.gnu.org/software/gdb/

#
# GDB has changed it default extension.
#
%ifn %{defined gdb_src_ext}
  %define gdb_src_ext gz
%endif

#
# Source
#
%source set gdb https://ftp.gnu.org/gnu/gdb/gdb-%{gdb_version}.tar.%{gdb_src_ext}

#
# Disable Python on Cxc builds for now.
#
%if "%{_build}" != "%{_host}"
  %define without_python
%endif

#
# The --with-python option is either the default which is auto or the path to
# the specific python to be used.
#
%if %{defined with_python_path}
  %define with_python_option --with-python=%{with_python_path}
%else
  %if %{defined gdb-enable-python}
    %define with_python_option --with-python=%{gdb-enable-python}
  %else
    %define with_python_option --with-python
  %endif
%endif

#
# Fix the mess iconv is on FreeBSD 10.0 and higher.
#
%if %{defined iconv_prefix}
 %define iconv_opts --with-libiconv-prefix=%{iconv_prefix}
%else
 %define iconv_opts %{nil}
%endif

#
#
# Prepare the source code.
#
%prep
  build_top=$(pwd)

  gdb_source=%{?gdb_external:%{gdb_expand_name}}%{!?gdb_external:"gdb-%{gdb_version}"}

  source_dir_gdb=${gdb_source}
  %source setup gdb -q -n ${gdb_source}
  %patch setup gdb -p1

  cd ${build_top}

%build
  build_top=$(pwd)

  %{build_directory}

  mkdir -p ${build_dir}
  cd ${build_dir}

  %{host_build_flags}

  if test "%{_build}" != "%{_host}" ; then
    GDB_LIBS_STATIC="-lexpat"
  else
    GDB_LIBS_STATIC="-lexpat"
    GDB_LIBS="%{_forced_static}"
  fi

  LIBS_STATIC=${GDB_LIBS_STATIC} \
  LIBS=${GDB_LIBS} \
  ../${source_dir_gdb}/configure \
    --build=%{_build} --host=%{_host} \
    --target=%{_target} \
    --verbose --disable-nls \
    --disable-gas --disable-binutils --disable-ld --disable-gold --disable-gprof \
    %{?with_system_readline:--with-system-readline} \
    --without-included-gettext \
    --disable-win32-registry \
    --disable-werror \
    %{!?gdb-disable-sim:--enable-sim}%{?gdb-disable-sim:--disable-sim} \
    %{?gdb-sim-options:%{gdb-sim-options}} \
    --without-zlib \
    --with-expat \
    --with-guile=no \
    %{iconv_opts} \
    %{!?without_python:%{with_python_option}} \
    --prefix=%{_prefix} --bindir=%{_bindir} \
    --exec-prefix=%{_exec_prefix} \
    --includedir=%{_includedir} --libdir=%{_libdir} \
    --mandir=%{_mandir} --infodir=%{_infodir}

  %{__make} %{?_smp_mflags} all

  cd ${build_top}

%install
  build_top=$(pwd)

  %{__rmdir} $SB_BUILD_ROOT

  cd ${build_dir}
  %{__make} DESTDIR=$SB_BUILD_ROOT install

  # Dropped in FSF-binutils-2.9.5, but Cygwin still ships it.
  %{__rmdir} $SB_BUILD_ROOT%{_infodir}/configure.info*

  %{__rmfile} $SB_BUILD_ROOT%{_infodir}/dir
  touch $SB_BUILD_ROOT%{_infodir}/dir

  cd ${build_top}