summaryrefslogtreecommitdiff
path: root/scripts/build/debug/300-gdb.sh
blob: 9207ca7b16a785748b8f93a44aa2cf862c9182f4 (plain)
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
316
317
318
319
320
321
# Build script for the gdb debug facility

do_debug_gdb_suffix() {
    case "${CT_GDB_VERSION}" in
        snapshot)   ;;
        *)          echo "-${CT_GDB_VERSION}";;
    esac
}

do_debug_gdb_parts() {
    do_gdb=
    do_insight=
    do_ncurses=

    if [ "${CT_GDB_CROSS}" = y ]; then
        if [ "${CT_GDB_CROSS_INSIGHT}" = "y" ]; then
            do_insight=y
        else
            do_gdb=y
        fi
    fi

    if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
        do_gdb=y
    fi

    if [ "${CT_GDB_NATIVE}" = "y" ]; then
        do_gdb=y
        do_ncurses=y
    fi
}

do_debug_gdb_get() {
    do_debug_gdb_parts

    if [ "${do_gdb}" = "y" ]; then
        CT_GetFile "gdb$(do_debug_gdb_suffix)"              \
                   {ftp,http}://ftp.gnu.org/pub/gnu/gdb     \
                   ftp://sources.redhat.com/pub/gdb/{{,old-}releases,snapshots/current}
    fi

    if [ "${do_insight}" = "y" ]; then
        CT_GetFile "insight-${CT_GDB_VERSION}"                                              \
                   ftp://sourceware.org/pub/insight/releases                                \
                   {ftp,http}://ftp.twaren.net/Unix/Sourceware/insight/releases             \
                   {ftp,http}://ftp.gwdg.de/pub/linux/sources.redhat.com/insight/releases
    fi

    if [ "${do_ncurses}" = "y" ]; then
        CT_GetFile "ncurses-${CT_NCURSES_VERSION}"          \
                   {ftp,http}://ftp.gnu.org/pub/gnu/ncurses \
                   ftp://invisible-island.net/ncurses
    fi
}

do_debug_gdb_extract() {
    do_debug_gdb_parts

    if [ "${do_gdb}" = "y" ]; then
        CT_Extract "gdb$(do_debug_gdb_suffix)"
        CT_Patch "gdb$(do_debug_gdb_suffix)"
    fi

    if [ "${do_insight}" = "y" ]; then
        CT_Extract "insight-${CT_GDB_VERSION}"
        CT_Patch "insight-${CT_GDB_VERSION}"
    fi

    if [ "${do_ncurses}" = "y" ]; then
        CT_Extract "ncurses-${CT_NCURSES_VERSION}"
        CT_Patch "ncurses-${CT_NCURSES_VERSION}"
    fi
}

do_debug_gdb_build() {
    local -a extra_config

    gdb_src_dir="${CT_SRC_DIR}/gdb$(do_debug_gdb_suffix)"
    insight_src_dir="${CT_SRC_DIR}/insight-${CT_GDB_VERSION}"

    # Version 6.3 and below behave badly with gdbmi
    case "${CT_GDB_VERSION}" in
        6.2*|6.3)   extra_config+=("--disable-gdbmi");;
    esac

    if [ "${CT_GDB_CROSS}" = "y" ]; then
        local -a cross_extra_config

        CT_DoStep INFO "Installing cross-gdb"
        CT_DoLog EXTRA "Configuring cross-gdb"

        mkdir -p "${CT_BUILD_DIR}/build-gdb-cross"
        cd "${CT_BUILD_DIR}/build-gdb-cross"

        cross_extra_config=("${extra_config[@]}")
        if [ "${CT_GMP_MPFR}" = "y" ]; then
            cross_extra_config+=("--with-gmp=${CT_PREFIX_DIR}" "--with-mpfr=${CT_PREFIX_DIR}")
        fi
        case "${CT_THREADS}" in
            none)   cross_extra_config+=("--disable-threads");;
            *)      cross_extra_config+=("--enable-threads");;
        esac

        CC_for_gdb=
        LD_for_gdb=
        if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then
            CC_for_gdb="gcc -static"
            LD_for_gdb="ld -static"
        fi

        gdb_cross_configure="${gdb_src_dir}/configure"
        [ "${CT_GDB_CROSS_INSIGHT}" = "y" ] && gdb_cross_configure="${insight_src_dir}/configure"

        CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'"

        CC="${CC_for_gdb}"                              \
        LD="${LD_for_gdb}"                              \
        CT_DoExecLog ALL                                \
        "${gdb_cross_configure}"                        \
            --build=${CT_BUILD}                         \
            --host=${CT_HOST}                           \
            --target=${CT_TARGET}                       \
            --prefix="${CT_PREFIX_DIR}"                 \
            --with-build-sysroot="${CT_SYSROOT_DIR}"    \
            --disable-werror                            \
            "${cross_extra_config[@]}"

        CT_DoLog EXTRA "Building cross-gdb"
        CT_DoExecLog ALL make ${PARALLELMFLAGS}

        CT_DoLog EXTRA "Installing cross-gdb"
        CT_DoExecLog ALL make install

        CT_EndStep
    fi

    if [ "${CT_GDB_NATIVE}" = "y" ]; then
        local -a native_extra_config
        local -a ncurses_opt

        CT_DoStep INFO "Installing native gdb"

        CT_DoStep INFO "Installing ncurses library"

        [ "${CT_CC_LANG_CXX}" = "y" ] || ncurses_opts+=("--without-cxx" "--without-cxx-binding")
        [ "${CT_CC_LANG_ADA}" = "y" ] || ncurses_opts+=("--without-ada")

        CT_DoStep INFO "Installing native ncurses tic"
        CT_DoLog EXTRA "Configuring ncurses tic"
        mkdir -p "${CT_BUILD_DIR}/build-ncurses-build-tic"
        cd "${CT_BUILD_DIR}/build-ncurses-build-tic"

        # Use build = CT_REAL_BUILD so that configure thinks it is
        # cross-compiling, and thus will use the ${CT_BUILD}-*
        # tools instead of searching for the native ones...
        CT_DoExecLog ALL                                        \
        "${CT_SRC_DIR}/ncurses-${CT_NCURSES_VERSION}/configure" \
            --build=${CT_REAL_BUILD}                            \
            --host=${CT_BUILD}                                  \
            --prefix=/usr                                       \
            --without-shared                                    \
            --enable-symlinks                                   \
            --with-build-cc=${CT_REAL_BUILD}-gcc                \
            --with-build-cpp=${CT_REAL_BUILD}-gcc               \
            --with-build-cflags="${CT_CFLAGS_FOR_HOST}"         \
            "${ncurses_opts[@]}"

        # Under some operating systems (eg. Winblows), there is an
        # extension appended to executables. Find that.
        tic_ext=$(grep -E '^x[[:space:]]*=' progs/Makefile |sed -r -e 's/^.*=[[:space:]]*//;')

        CT_DoLog EXTRA "Building ncurses tic"
        CT_DoExecLog ALL make ${PARALLELMFLAGS} -C include
        CT_DoExecLog ALL make ${PARALLELMFLAGS} -C progs "tic${tic_ext}"

        CT_DoLog EXTRA "Installing ncurses tic"
        CT_DoExecLog ALL install -d -m 0755 "${CT_PREFIX_DIR}/bin"
        CT_DoExecLog ALL install -m 0755 "progs/tic${tic_ext}" "${CT_PREFIX_DIR}/bin"

        CT_EndStep # tic build

        CT_DoLog EXTRA "Configuring ncurses"
        mkdir -p "${CT_BUILD_DIR}/build-ncurses"
        cd "${CT_BUILD_DIR}/build-ncurses"

        CT_DoExecLog ALL                                        \
        "${CT_SRC_DIR}/ncurses-${CT_NCURSES_VERSION}/configure" \
            --build=${CT_BUILD}                                 \
            --host=${CT_TARGET}                                 \
            --with-build-cc=${CT_BUILD}-gcc                     \
            --with-build-cpp=${CT_BUILD}-gcc                    \
            --with-build-cflags="${CT_CFLAGS_FOR_HOST}"         \
            --prefix=/usr                                       \
            --with-shared                                       \
            --without-sysmouse                                  \
            --without-progs                                     \
            --enable-termcap                                    \
            "${ncurses_opts[@]}"

        CT_DoLog EXTRA "Building ncurses"
        CT_DoExecLog ALL make ${PARALLELMFLAGS}

        CT_DoLog EXTRA "Installing ncurses"
        mkdir -p "${CT_SYSROOT_DIR}/usr/bin"
        CT_DoExecLog ALL make DESTDIR="${CT_SYSROOT_DIR}" install

        # We no longer need the temporary tic. Remove it
        CT_DoExecLog DEBUG rm -fv "${CT_PREFIX_DIR}/bin/tic"

        CT_EndStep # ncurses build

        CT_DoLog EXTRA "Configuring native gdb"

        mkdir -p "${CT_BUILD_DIR}/build-gdb-native"
        cd "${CT_BUILD_DIR}/build-gdb-native"

        native_extra_config=("${extra_config[@]}")
        case "${CT_THREADS}" in
            none)   native_extra_config+=("--disable-threads");;
            *)      native_extra_config+=("--enable-threads");;
        esac
        if [ "${CT_GDB_NATIVE_USE_GMP_MPFR}" = "y" ]; then
            native_extra_config+=("--with-gmp=${CT_SYSROOT_DIR}/usr" "--with-mpfr=${CT_SYSROOT_DIR}/usr")
        fi

        if [ "${CT_GDB_NATIVE_STATIC}" = "y" ]; then
            CC_for_gdb="${CT_TARGET}-gcc -static"
            LD_for_gdb="${CT_TARGET}-ld -static"
        else
            CC_for_gdb="${CT_TARGET}-gcc"
            LD_for_gdb="${CT_TARGET}-ld"
        fi

        export ac_cv_func_strncmp_works=yes

        CT_DoLog DEBUG "Extra config passed: '${native_extra_config[*]}'"

        CC="${CC_for_gdb}"                              \
        LD="${LD_for_gdb}"                              \
        CT_DoExecLog ALL                                \
        "${gdb_src_dir}/configure"                      \
            --build=${CT_BUILD}                         \
            --host=${CT_TARGET}                         \
            --target=${CT_TARGET}                       \
            --prefix=/usr                               \
            --with-build-sysroot="${CT_SYSROOT_DIR}"    \
            --without-uiout                             \
            --disable-tui                               \
            --disable-gdbtk                             \
            --without-x                                 \
            --disable-sim                               \
            --disable-werror                            \
            --without-included-gettext                  \
            --without-develop                           \
            "${native_extra_config[@]}"

        CT_DoLog EXTRA "Building native gdb"
        CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}

        CT_DoLog EXTRA "Installing native gdb"
        CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install

        # Building a native gdb also builds a gdbserver
        find "${CT_DEBUGROOT_DIR}" -type f -name gdbserver -exec rm -fv {} \; 2>&1 |CT_DoLog ALL

        unset ac_cv_func_strncmp_works

        CT_EndStep # native gdb build
    fi

    if [ "${CT_GDB_GDBSERVER}" = "y" ]; then
        local -a gdbserver_extra_config

        CT_DoStep INFO "Installing gdbserver"
        CT_DoLog EXTRA "Configuring gdbserver"

        mkdir -p "${CT_BUILD_DIR}/build-gdb-gdbserver"
        cd "${CT_BUILD_DIR}/build-gdb-gdbserver"

        # Workaround for bad versions, where the configure
        # script for gdbserver is not executable...
        # Bah, GNU folks strike again... :-(
        chmod +x "${gdb_src_dir}/gdb/gdbserver/configure"

        gdbserver_LDFLAGS=
        if [ "${CT_GDB_GDBSERVER_STATIC}" = "y" ]; then
            gdbserver_LDFLAGS=-static
        fi

        gdbserver_extra_config=("${extra_config[@]}")

        LDFLAGS="${gdbserver_LDFLAGS}"                  \
        CT_DoExecLog ALL                                \
        "${gdb_src_dir}/gdb/gdbserver/configure"        \
            --build=${CT_BUILD}                         \
            --host=${CT_TARGET}                         \
            --target=${CT_TARGET}                       \
            --prefix=/usr                               \
            --sysconfdir=/etc                           \
            --localstatedir=/var                        \
            --includedir="${CT_HEADERS_DIR}"            \
            --with-build-sysroot="${CT_SYSROOT_DIR}"    \
            --program-prefix=                           \
            --without-uiout                             \
            --disable-tui                               \
            --disable-gdbtk                             \
            --without-x                                 \
            --without-included-gettext                  \
            --without-develop                           \
            --disable-werror                            \
            "${gdbserver_extra_config[@]}"

        CT_DoLog EXTRA "Building gdbserver"
        CT_DoExecLog ALL make ${PARALLELMFLAGS} CC=${CT_TARGET}-${CT_CC}

        CT_DoLog EXTRA "Installing gdbserver"
        CT_DoExecLog ALL make DESTDIR="${CT_DEBUGROOT_DIR}" install

        CT_EndStep
    fi
}