1#!/bin/sh
2
3# Copyright (c) 2000, 2021, Oracle and/or its affiliates.
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License, version 2.0,
7# as published by the Free Software Foundation.
8#
9# This program is also distributed with certain software (including
10# but not limited to OpenSSL) that is licensed under separate terms,
11# as designated in a particular file or component or in included license
12# documentation.  The authors of MySQL hereby grant you an additional
13# permission to link the program and your derivative works with the
14# separately licensed software that they have included with MySQL.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19# GNU General Public License, version 2.0, for more details.
20#
21# You should have received a copy of the GNU Library General Public
22# License along with this library; if not, write to the Free
23# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24# MA 02110-1301, USA
25
26########################################################################
27
28get_key_value()
29{
30  echo "$1" | sed 's/^--[a-zA-Z_-]*=//'
31}
32
33usage()
34{
35cat <<EOF 
36Usage: $0 [-h|-n] [configure-options]
37  -h, --help              Show this help message.
38  -n, --just-print        Don't actually run any commands; just print them.
39  -c, --just-configure    Stop after running configure.
40  --with-debug=full       Build with full debug(no optimizations, keep call stack).
41  --warning-mode=[old|pedantic|maintainer]
42                          Influences the debug flags. Old is default.
43  --prefix=path           Build with prefix 'path'.
44
45Note: this script is intended for internal use by MySQL developers.
46EOF
47}
48
49parse_options()
50{
51  while test $# -gt 0
52  do
53    case "$1" in
54    --prefix=*)
55      prefix=`get_key_value "$1"`;;
56    --with-debug=full)
57      full_debug="=full";;
58    --warning-mode=*)
59      warning_mode=`get_key_value "$1"`;;
60    -c | --just-configure)
61      just_configure=1;;
62    -n | --just-print | --print)
63      just_print=1;;
64    -h | --help)
65      usage
66      exit 0;;
67    *)
68      echo "Unknown option '$1'"
69      exit 1;;
70    esac
71    shift
72  done
73}
74
75########################################################################
76
77if test ! -f sql/mysqld.cc
78then
79  echo "You must run this script from the MySQL top-level directory"
80  exit 1
81fi
82
83prefix="/usr/local/mysql"
84just_print=
85just_configure=
86warning_mode=
87maintainer_mode=
88full_debug=
89
90parse_options "$@"
91
92if test -n "$MYSQL_BUILD_PREFIX"
93then
94  prefix="$MYSQL_BUILD_PREFIX"
95fi
96
97set -e
98
99#
100# Check for the CPU and set up CPU specific flags. We may reset them
101# later.
102#
103path=`dirname $0`
104. "$path/check-cpu"
105
106export AM_MAKEFLAGS
107AM_MAKEFLAGS="-j 6"
108
109# SSL library to use.
110SSL_LIBRARY=--with-ssl=system
111
112if [ "x$warning_mode" = "xpedantic" ]; then
113  warnings="-W -Wall -ansi -pedantic -Wno-long-long -Wno-unused -D_POSIX_SOURCE"
114  c_warnings="$warnings"
115  cxx_warnings="$warnings -std=c++98"
116# NOTE: warning mode should not influence optimize/debug mode.
117# Please feel free to add a separate option if you don't feel it's an overkill.
118  debug_extra_cflags="-O0"
119# Reset CPU flags (-mtune), they don't work in -pedantic mode
120  check_cpu_cflags=""
121elif [ "x$warning_mode" = "xmaintainer" ]; then
122  c_warnings="-Wall -Wextra"
123  cxx_warnings="$c_warnings -Wno-unused-parameter"
124  maintainer_mode="--enable-mysql-maintainer-mode"
125  debug_extra_cflags="-g3"
126else
127# Both C and C++ warnings
128  warnings="-Wall -Wextra -Wunused -Wwrite-strings"
129
130# For more warnings, uncomment the following line
131# warnings="$warnings -Wshadow"
132
133# C warnings
134  c_warnings="$warnings"
135# C++ warnings
136  cxx_warnings="$warnings -Wno-unused-parameter"
137# cxx_warnings="$cxx_warnings -Woverloaded-virtual -Wsign-promo"
138  cxx_warnings="$cxx_warnings -Wnon-virtual-dtor"
139  debug_extra_cflags="-O0 -g3 -gdwarf-2"
140fi
141
142# Set flags for various build configurations.
143# Used in -valgrind builds
144valgrind_flags="-DMYSQL_SERVER_SUFFIX=-valgrind-max"
145valgrind_configs="--with-valgrind"
146#
147# Used in -debug builds
148debug_cflags="-DEXTRA_DEBUG "
149debug_cflags="$debug_cflags -DSAFE_MUTEX"
150error_inject="--with-error-inject "
151#
152# Base C++ flags for all builds
153base_cxxflags="-felide-constructors"
154#
155# Flags for optimizing builds.
156# Be as fast as we can be without losing our ability to backtrace.
157fast_cflags="-O3 -fno-omit-frame-pointer"
158
159debug_configs="--with-debug"
160if [ -z "$full_debug" ]
161then
162  debug_cflags="$debug_cflags $debug_extra_cflags"
163fi
164
165
166#
167# Configuration options.
168#
169base_configs="--prefix=$prefix --enable-assembler "
170base_configs="$base_configs --with-extra-charsets=complex "
171base_configs="$base_configs --enable-thread-safe-client "
172base_configs="$base_configs --with-big-tables $maintainer_mode"
173
174
175if test -d "$path/../cmd-line-utils/libedit"
176then
177    base_configs="$base_configs --with-libedit"
178fi
179
180static_link="--with-mysqld-ldflags=-all-static "
181static_link="$static_link --with-client-ldflags=-all-static"
182# we need local-infile in all binaries for rpl000001
183# if you need to disable local-infile in the client, write a build script
184# and unset local_infile_configs
185local_infile_configs="--enable-local-infile"
186
187
188max_no_embedded_configs="$SSL_LIBRARY --with-plugins=max"
189max_no_ndb_configs="$SSL_LIBRARY --with-plugins=max-no-ndb --with-embedded-server"
190max_configs="$SSL_LIBRARY --with-plugins=max --with-embedded-server"
191
192#
193# CPU and platform specific compilation flags.
194#
195alpha_cflags="$check_cpu_cflags -Wa,-m$cpu_flag"
196amd64_cflags="$check_cpu_cflags"
197amd64_cxxflags=""  # If dropping '--with-big-tables', add here  "-DBIG_TABLES"
198pentium_cflags="$check_cpu_cflags"
199pentium64_cflags="$check_cpu_cflags -m64"
200ppc_cflags="$check_cpu_cflags"
201sparc_cflags=""
202
203if gmake --version > /dev/null 2>&1
204then
205  make=gmake
206else
207  make=make
208fi
209
210if test -z "$CC" ; then
211  CC=gcc
212fi
213
214if test -z "$CXX" ; then
215  CXX=g++
216fi
217
218# If ccache (a compiler cache which reduces build time)
219# (http://samba.org/ccache) is installed, use it.
220# We use 'grep' and hope 'grep' will work as expected
221# (returns 0 if finds lines)
222if test "$USING_GCOV" != "1"
223then
224  # Not using gcov; Safe to use ccache
225  CCACHE_GCOV_VERSION_ENABLED=1
226fi
227
228if ccache -V > /dev/null 2>&1 && test "$CCACHE_GCOV_VERSION_ENABLED" = "1"
229then
230  echo "$CC" | grep "ccache" > /dev/null || CC="ccache $CC"
231  echo "$CXX" | grep "ccache" > /dev/null || CXX="ccache $CXX"
232fi
233
234# gcov
235
236# The  -fprofile-arcs and -ftest-coverage options cause GCC to instrument the
237# code with profiling information used by gcov.
238# The -DHAVE_gcov enables code to write out coverage info even when crashing.
239
240gcov_compile_flags="-fprofile-arcs -ftest-coverage"
241gcov_compile_flags="$gcov_compile_flags -DMYSQL_SERVER_SUFFIX=-gcov -DHAVE_gcov"
242
243# GCC4 needs -fprofile-arcs -ftest-coverage on the linker command line (as well
244# as on the compiler command line), and this requires setting LDFLAGS for BDB.
245
246gcov_link_flags="-fprofile-arcs -ftest-coverage"
247
248gcov_configs="--with-gcov"
249
250# gprof
251
252gprof_compile_flags="-O2 -pg -g"
253
254gprof_link_flags="--disable-shared $static_link"
255
256