build_mccge.sh 50.7 KB
Newer Older
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
#!/bin/sh

die()
{
  echo "ERROR: $@"; exit 1;
}

get_key_value()
{
  echo "$1" | sed 's/^--[a-zA-Z_-]*=//'
}

developer_usage()
{
cat <<EOF

  This script can be used by developers of MySQL, early adopters wanting 
  to try out early versions of MySQL before binary versions are 
  available, anyone needing a version with a special patch included that 
  needs to be built from source code, or anyone else wanting to exercise 
  full control over the MySQL build process.

  This help text is targeted towards those that want to debug and test 
  MySQL using source code releases. If you have downloaded a source code 
  release and simply want to build a usable binary, you should read the 
  --sysadmin-help instead.

  The script is also designed to be used by anyone receiving a source 
  code release of MySQL Cluster Carrier Grade Edition. The default
  behaviour is to build the standard MySQL Cluster Carrier Grade Edition
  package. Three environment variables can be used to change the 
  default behaviour:

  MYSQL_DEVELOPER
    Defining this variable is similar to setting the --developer flag
  MYSQL_DEVELOPER_PACKAGE=package
    Defining this variable is similar to setting the --package=* 
    variable
  MYSQL_DEVELOPER_DEBUG
    Defining this variable sets the --with-debug flag

  Options used with this script always override any default behaviour. 
  The default package is MySQL Cluster Carrier Grade (standard) Edition. 
  For developers, the default package is MySQL Cluster Carrier Grade 
  Extended Edition, and the default build behaviour is to build with
  autotools. If you want to skip autotools and start from a source code
  release you can use the --no-autotools flag.

  More information for developers can be found in --help, 
  --sysadmin-help, and --extended-help.

  The most common usage for developers is to set the three variables 
  mentioned previously and then simply to run the script without any 
  additional parameters, using them only when needing to change some 
  things like not requiring debug build. If some of these environment 
  variables have already been set, you can use the corresponding options 
  to unset them and reverse their effects.
EOF
}

sysadmin_usage()
{
cat <<EOF

  This script can be used to build MySQL Cluster Carrier Grade Edition
66
  based on a source code release you received from MySQL. It can also
67 68
  be used to build many variants other variants of MySQL, in particular
  various performance-optimised versions of MySQL.
69 70

  It is assumed that you are building on a computer which is of the 
71
  same type as that on which you intend to run MySQL/MySQL Cluster.
72 73

  The simplest possible way to run this script is to allow it to use the 
74 75
  built-in defaults everywhere, invoking it simply as (from top-level
  MySQL directory):
76

77
  shell> BUILD/build_mccge.sh
78 79 80

  This performs the following operations:
    1) Detects the operating system. Currently, Linux, FreeBSD, Solaris 
81
      8/9/10/11, and Mac OS X are supported by this script.
82 83
    2) Detect the type of CPU being used. Currently supported processors 
      are: x86 for all supported operating systems, Itanium for Linux 
84 85
      with GCC, and x86 + SPARC for Solaris using the Forte compiler and
      finally x86 on Linux using the Intel compiler.
86
    3) Invokes the GCC compiler.
87
    4) Builds a set of MySQL/MySQL Cluster binaries; for
88
      more information about these, see --extended-help.
89
    5) Default compiler is always gcc.
90 91 92 93 94 95
  
  The default version assumes that you have a source code tarball from 
  which you are building, and thus autoconf and automake do not need to 
  be run. If you have downloaded a BitKeeper tree then you should read 
  --developer-help.

96
  If you are building MySQL/MySQL Cluster for commercial 
97 98 99 100 101
  use then you need to set the --commercial flag to ensure that the 
  commercial libraries are compiled in, rather than the GPL-only 
  libraries. The default is to build a GPL version of MySQL Cluster 
  Carrier Grade Edition.

102 103
  If your building on a Solaris SPARC machine and you want to compile
  using SunStudio you must set 
104 105 106
  --compiler=forte; if you want to build using the Intel compiler on 
  Linux, you need to set --compiler=icc.

107 108 109
  A synonym for forte is SunStudio, so one can also use
  --compiler=SunStudio.

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
  If you want to make sure that a 64-bit version is built then you 
  should add the flag --64. This is always set on Solaris machines and 
  when check-cpu is able to discover that a 64-bit CPU is being used. If 
  you want to ensure that a 32-bit binary is produced, use --32 instead.

  If you need the binaries to be installed in a different location from 
  /usr/local/mysql, then you should set --prefix to point to where you
  want the binaries installed.

  Using a data directory other than the default (PREFIX/data) can be 
  done when starting the MySQL Server, or by invoking this script with 
  the --datadir option.

  If you want your binaries stripped of surplus debug or other 
  information, use the --strip option.

  If you want debug information in the binary (for example, to be
  able to send gdb core dumps to MySQL Support), then you should add the 
  flag --with-debug; if you want a production build with only debugging 
  information in the binary then use --debug.

  If your aim is not to build MySQL Cluster Carrier Grade Edition, you 
132
  can also use this script to build MySQL Classic and MySQL Enterprise Pro 
133 134 135 136 137 138 139 140 141 142 143 144
  versions; see the --extended-help for descriptions of these packages.
EOF
}

usage()
{
cat <<EOF

Usage: $0 [options]
  --help                  Show this help message.
  --sysadmin-help         Show help for system administrators wishing 
                          to build MySQL Cluster Carrier Grade Edition
145
                          or other MySQL versions.
146 147 148 149 150
  --developer-help        Show help for developers trying to build MySQL
  --with-help             Show extended help on --with-xxx options to 
                          configure
  --extended-help         Show extended help message
  --without-debug         Build non-debug version
151 152
  --use-comment           Set the comment in the build
  --with-fast-mutexes     Use try/retry method of acquiring mutex
153
  --with-debug            Build debug version
154 155 156 157
  --with-link-time-optimizer
                          Link time optimizations enabled (Requires GCC 4.5
                          if GCC used), available for icc as well. This flag
                          is only considered if also fast is set.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
  --configure-only        Stop after running configure.
  --use-autotools         Start by running autoconf, automake,.. tools
  --no-autotools          Start from configure
  --print-only            Print commands that the script will execute, 
                          but do not actually execute
  --prefix=path           Build with prefix 'path'
  --datadir=path          Build with data directory set to non-standard 
                          'path'
  --debug                 Build normal version, but add debug 
                          information to binary
  --developer             Use extensions that most MySQL developers use
  --no-developer          Do not use extensions that most developers of 
                          MySQL use
  --commercial            Use commercial libraries
  --gpl                   Use gpl libraries
173 174
  --compiler=[gcc|icc|forte|SunStudio]        Select compiler
  --cpu=[x86|x86_64|sparc|itanium]            Select CPU type
175 176
                          x86 => x86 and 32-bit binary
                          x86_64 => x86 and 64 bit binary
177 178 179 180 181 182 183 184 185 186 187
  --warning-mode=[extra|pedantic|normal|no]   Set warning mode level
  --warnings              Set warning mode to normal
  --32                    Build a 32-bit binary even if CPU is 64-bit
  --64                    Build a 64-bit binary even if not sure a
                          64-bit CPU is being used
  --package=[cge|extended|pro|classic]        Select package to build
  --parallelism=number    Define parallelism in make
  --strip                 Strip binaries
  --error-inject          Enable error injection into MySQL Server and 
                          data nodes
  --valgrind              Build with valgrind
188
  --fast                  Optimise for CPU architecture built on
189
  --static-linking        Statically link system libraries into binaries
190
  --use-tcmalloc          Link with tcmalloc instead of standard malloc (Linux only)
191 192 193 194 195 196 197 198 199 200 201 202 203 204
  --with-flags *          Pass extra --with-xxx options to configure
EOF
  if test "x$1" != "x" ; then
    echo "Failure Message: $1"
  fi
}

extended_usage()
{
  cat <<EOF

  Extended help text for this script:
  -----------------------------------
  This script is intended to make it easier for customers using MySQL
205 206
  Cluster Carrier Grade Edition, customers using performance-optimised
  MySQL versions and developers to build the product from source on 
207 208 209 210 211 212
  these platforms/compilers: Linux/x86 (32-bit and 64-bit) (either using
  gcc or icc), Linux Itanium, Solaris 8,9,10 and 11 x86 and SPARC using
  gcc or SunStudio and MacOSX/x86/gcc.

  The script automatically detects CPU type and operating system; The
  default compiler is always gcc.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232

  To build on other platforms you can use the --print-only option on a
  supported platform and edit the output for a proper set of commands on
  the specific platform you are using. MySQL also provides custom builds
  for any type of platform that is officially supported for MySQL
  Cluster. For a list of supported platforms, see
  http://www.mysql.com/support/supportedplatforms/cluster.html.

  Using the --package option, it is also possible to build a "classic"
  version of MySQL having only the MyISAM storage engine, a "Pro"
  package including all storage engines and other features except MySQL
  Cluster, and an "extended" package including these features plus MySQL
  Cluster (this is the default if the --developer option is used).

  Different MySQL storage engines are included in the build, depending
  on which --package option is used. The comment and version strong
  suffix are also set according to the package selected.

  --package=cge
    storage engines:
233
      ARCHIVE, BLACKHOLE, CSV, FEDERATED, MYISAM, NDB
234 235 236 237 238 239 240
      (All storage engines except InnoDB)
    comment: MySQL Cluster Carrier Grade Edition GPL/Commercial version 
             built from source
    version string suffix: -cge

  --package=extended
    storage engines:
241
      ARCHIVE, BLACKHOLE, CSV, FEDERATED, MYISAM, INNODB, NDB
242 243 244 245 246 247 248
      (All storage engines)
    comment: MySQL Cluster Carrier Grade Extended Edition GPL/Commercial 
             version built from source
    version string suffix: -cge-extended

  --package=pro
    storage engines:
249
      ARCHIVE, BLACKHOLE, CSV, FEDERATED, INNODB, MYISAM
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
      (All storage engines except NDB)
    comment: MySQL Pro GPL/Commercial version built from 
             source
    version string suffix: [none]

  --package=classic
    storage engines: CSV, MYISAM
    comment: MySQL Classic GPL/Commercial version built 
             from source
    version string suffix: [none]

  All packages except Classic include support for user-defined
  partitioning.

  If --with-debug is used, an additional "-debug" is appended to the
  version string.

  --commercial
    This flag prevents the use of GPL libraries which cannot be used
    under a commercial license, such as the readline library.

  --developer
    This option changes a number of things to make the version built
    more appropriate to the debugging and testing needs of developers. 
    It changes the default package to "extended". It also changes the 
    default warning mode from "none" to "normal", which allows an 
    extensive list of warnings to be generated.

  --error-inject
    This flag is used only when the --developer option is also used, and
    enables error injection in both the MySQL Server and in MySQL
    Cluster data nodes.

  The following is a list of the default configure options used for all
  packages:

  --prefix: /usr/local/mysql (can be overridden)

  --libexecdir: <prefix>/bin (can be overridden)

  --localstatedir: <prefix>/data, unless --datadir is used, in which
    case it defaults to <datadir>/data (can be overridden by setting
    --localstatedir explicitly).

  --enable-local-infile: Enable use of the LOAD DATA FROM  LOCAL INFILE
    command (cannot be overridden).

  --enable-thread-safe-client: Enable the multi-threaded mysql client
    library (cannot be overridden).

  --with-big-tables: Enable use of tables with more than 4G rows (cannot
    be overridden).

  --with-extra-charsets=all: Enable use of all character sets supported
    by MySQL (cannot be overridden).

  --with-ssl: Enable use of yaSSL library included in the MySQL source
307
    if possible (GCC and same CC and CXX).
308 309 310 311 312
    (cannot be overridden).

  --with-pic: Build all binaries using position independent assembler
    to avoid problems with dynamic linkers (cannot be overridden).

313 314
  --without-example-engine: Ensure that the example engine isn't built,
    it cannot do any useful things, it's merely intended as documentation.
315
    (cannot be overridden)
316

317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
  --with-csv-storage-engine: Ensure that the CSV storage engine is
    included in all builds. Since CSV is required for log tables in
    MySQL 5.1, this option cannot be overridden.

    (Note that MyISAM support is always built into the MySQL Server; the
    server *cannot* be built without MyISAM.)

  --with-mysqld-ldflags=-static
  --with-client-ldflags=-static
    Ensures that binaries for, respectively, the MySQL server and client
    are built with static libraries except for the system libraries,
    which use dynamically loaded libraries provided by the operating
    system. Building with --developer sets these to all-static instead, 
    to build everything statically.

  In addition there are some configure options that are specific to
  Linux operating systems:

  --enable-assembler
    Include assembler code optimisations for a number of mostly string
    methods. Used for x86 processors only.

  Neither of the preceding options can be disabled.

  MySQL Cluster Carrier Grade edition also adds the following options
  (also used by the extended package):

  --with-ndbcluster
    Include the NDB Cluster storage engine, its kernel, management
    server, and client, as well as support for the NDB and MGM APIs.

  --without-ndb-debug
    Do not include specific NDB debug code, not even in debug versions
    (cannot be overridden).

  Package-specific options:
  -------------------------
  --with-innodb
    Specifically included in the "pro" and "extended" packages, and not 
    in any of the others.

  --with-comment
    Sets the comment for the MySQL version, by package, as described
    above.

  --with-server-suffix
    Sets the server suffix on the MySQL version, by package, as
    described above.

  Other options used:
  -------------------
  --with-readline
    Use the GPL readline library for command editing functions; not
    available with commercial packages.

  --with-libedit
    Use the BSD licensed library for command editing functions; used for
    commercial packages.

  --with-zlib-dir=bundled
    Use the zlib package bundled with MySQL.

  --with-mysqld-libs=-lmtmalloc
    Used on Solaris to ensure that the proper malloc library is used.
381 382 383
    Investigations have shown mtmalloc to be the best choice on Solaris,
    also umem has good performance on Solaris but better debugging
    capabilities.
384 385 386 387

  Compiler options:
  -----------------

388 389
    This section describes the compiler options for each of the different
    platforms supported by this script.
390

391 392
    The --fast option adds -mtune=cpu_arg to the C/C++ flags (provides
    support for Nocona, K8, and other processors).
393

394
    Use of the --debug option adds -g to the C/C++ flags.
395

396 397 398
    In all cases it is possible to override the definition of CC and CXX
    by calling the script as follows:
    CC="/usr/local/bin/gcc" CXX="/usr/local/bin/gcc" BUILD/build_mccge.sh
399

400 401 402 403 404 405 406
  FreeBSD/x86/gcc
  ---------------
    No flags are used. Instead, configure determines the proper flags to 
    use.

  Linux/x86+Itanium/gcc
  -------------
407
    For debug builds -O is used and otherwise -O3 is used.Discovery of a
408 409 410 411 412 413 414 415
    Nocona or Core 2 Duo CPU causes a 64-bit binary to be built;
    otherwise, the binary is 32-bit. To build a 64-bit binary, -m64 is
    added to the C/C++ flags. (To build a 32-bit binary on a 64-bit CPU,
    use the --32 option as described previously.)

  Linux/x86+Itanium/icc
  -------------
    Flags used:
416 417
    CC  = icc -static-libgcc -static-intel
    C++ = icpc -static-libgcc -static-intel
418 419
    C/C++ flags = -mp -restrict

420
    On Itanium we also add -no-ftz and to CC and C++ flags.
421

422 423 424
    Note that if the user of this script sets CC or CXX explicitly then
    also -static-libgcc and -static-intel needs to be set in the CC and
    CXX.
425

426 427
    The non-debug versions also add the following:
      C/C++ flags += -O3 unroll2 -ip
428

429 430 431 432 433 434
    The fast version adds (if --with-link-time-optimizer is used):
      C/C++ flags += -ipo

    On discovery of a Core 2 Duo architecture while using icc, -xT is also 
    added to the C/C++ flags; this provides optimisations specific to Core 
    2 Duo. This is added only when the --fast flag is set.
435 436 437

  Solaris/x86/gcc
  ---------------
438
    All builds on Solaris are by default 64-bit, so -m64 is always used in
439
    the C/C++ flags. LDFLAGS is set to -m64 -O/-O2/-O3. If for
440 441 442 443
    some reason a 32-bit Solaris is used it is necessary to add the flag
    --32 to the script invocation. Due to bugs in compiling with -O3 on
    Solaris only -O2 is used by default, when --fast flag is used -O3 will
    be used instead.
444

445 446 447
    Sets -m64 (default) or -m32 (if specifically set) in LDFLAGS and
    C/C++ flags.

448 449
  Solaris/Sparc/Forte
  -------------------
450
    Uses cc as CC and CC as CXX
451 452
    Note that SunStudio uses different binaries for C and C++ compilers.

453 454
    Set -m64 (default) or -m32 (if specifically set) in ASFLAGS,
    LDFLAGS and C/C++ flags.
455 456 457 458 459

    Sets ASFLAGS=LDFLAGS=compiler flags=xarch=sparc, so that we compile
    Sparc v9 binaries, also -mt is set in all those since we're always
    building a multithreaded program.

460
    C flags   = -xstrconst    This flag is set only on SPARC
461 462
    C++ flags = -noex

463 464 465 466 467 468 469 470 471 472
    Set the following C/C++ flags:
    -fsimple=1
    -ftrap=%none
    -nofstore          This flag is set only on x86
    -xbuiltin=%all
    -xlibmil
    -xlibmopt

    Set the C++ flag:
    -noex
473
    -features=no%except    This flag is set only on x86
474

475 476
    When compiling with fast we set (-ipo only used if we have
    set --with-link-time-optimizer):
477 478 479 480 481 482 483 484 485 486 487
    C/C++ flags: -xtarget=native -xunroll=3 -xipo
    LDFLAGS: -xipo

    When not compiling with fast we always set -xtarget=generic

    When compiling with fast on SPARC we also set:
    C/C++ flags: -xbinopt=prepare
    LDFLAGS: -xbinopt=prepare

    When compiling with fast on x86 we also set:
    C/C++ flags: -xregs=frameptr
488 489 490 491 492
    When not compiling with fast we set on x86
    C/C++ flags: -xregs=no%frameptr

    On SPARC we set
    ASFLAGS = LDFLAGS = C/C++ flags = -xarch=sparc
493

494 495 496 497 498
    The optimisation level is
    -xO         Debug builds
    -xO2        Production build on SPARC
    -xO3        Production build on x86
    -xO4        Fast builds on SPARC/x86
499 500 501

  MacOSX/x86/gcc
  --------------
502 503
    C/C++ flags include -fno-common -arch i386.
    When 64-bits builds then i386 is replaced by x86_64.
504

505 506 507
    Non-debug versions also add -Os -felide-constructors, where "-Os"
    means the build is space-optimised as long as the space optimisations
    do not negatively affect performance. Debug versions use -O.
508
  
509 510 511
    Mac OS X builds will always be 32-bit by default, when --64 is added
    the build will be 64 bit instead. Thus the flag --m64 is added only
    when specifically given as an option.
512 513
EOF
}
514

515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
with_usage()
{
  cat <<EOF

  To obtain extended help on the --with-* options available, run this
  script with --configure-only to create a configuration file. Then
  issue the command ./configure --help to get an extensive list of
  possible configure options.

  The remainder of this text focuses on those options which are useful
  in building binaries for MySQL Cluster Carrier Grade Edition.

  --with-ndb-sci=/opt/DIS
    Used to build a MySQL Cluster Carrier Grade Edition that can use the
    SCI Transporter. The Dolphin SCI installation must be completed
    first (see 
    http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-interconnects.html
    for more information).

  --with-ndb-test
    Compile the MySQL Cluster test programs.

  --with-ndb-port=PORT
    Change the default port for the MySQL Cluster management server.

  --with-ndb-port-base=PORT
    Change the default port base for MySQL Cluster data nodes.

  --without-query-cache
    Build the MySQL Server without the query cache, which is often not
    of value in MySQL Cluster applications.

  --with-atomic-ops=rwlocks|smp|up
                          Implement atomic operations using pthread
                          rwlocks or atomic CPU instructions for
                          multi-processor (default) or single-processor
                          configurations.

  --without-geometry      Do not build geometry-related portions of the
                          MySQL Server. Seldom used in MySQL Cluster
                          applications.

  --with-ndb-cc-flags=FLAGS
    This option can be used to build MySQL Cluster with error injection
    on the data nodes. It can be used to pass special options to
    programs in the NDB kernel for special test builds.
    The option for enabling data node error injection is -DERROR_INSERT.
EOF
}

parse_package()
{
  case "$package" in
    classic )
      package="classic"
      ;;
    pro )
      package="pro"
      ;;
    extended )
575
      package="extended"
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
      ;;
    cge )
      package="cge"
      ;;
    *)
      echo "Unknown package '$package'"
      exit 1
      ;;
  esac
}

parse_warning_mode()
{
  case "$warning_mode" in
    pedantic )
      warning_mode="pedantic"
      ;;
    extra_warnings | extra-warnings | extra )
      warning_mode="extra"
      ;;
    no )
      warning_mode=
      ;;
    normal )
      warning_mode="normal"
      ;;
    *)
      echo "Unknown warning mode '$warning_mode'"
      exit 1
      ;;
  esac
}

#
# We currently only support x86, Itanium and UltraSparc processors.
#
parse_cpu_type()
{
  case "$cpu_type" in
    x86 )
      cpu_type="x86"
617
      if test "x$m64" = "x" ; then
618 619
        m64="no"
      fi
620 621 622
      ;;
    x86_64 )
      cpu_type="x86"
623
      if test "x$m64" = "x" ; then
624 625
        m64="yes"
      fi
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
      ;;
    itanium )
      cpu_type="itanium"
      ;;
    sparc )
      cpu_type="sparc"
      ;;
    * )
      echo "Unknown CPU type $cpu_type"
      exit 1
      ;;
  esac
  return
}

#
# We currently only support gcc, icc and Forte.
#
parse_compiler()
{
  case "$compiler" in
    gcc )
      compiler="gcc"
      ;;
    icc )
      compiler="icc"
      ;;
653
    forte | SunStudio | sunstudio )
654 655
      compiler="forte"
      ;;
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
    *)
      echo "Unknown compiler '$compiler'"
      exit 1
      ;;
  esac
}

parse_options()
{
  while test $# -gt 0
  do
    case "$1" in
    --prefix=*)
      prefix=`get_key_value "$1"`
      ;;
    --datadir=*)
      datadir=`get_key_value "$1"`
      ;;
674 675 676
    --with-link-time-optimizer)
      with_link_time_optimizer="yes"
      ;;
677 678 679 680 681 682
    --without-debug)
      with_debug_flag="no"
      if test "x$fast_flag" != "xyes" ; then
        fast_flag="generic"
      fi
      ;;
683 684 685 686 687 688
    --use-comment)
      without_comment="no"
      ;;
    --with-fast-mutexes)
      with_fast_mutexes="yes"
      ;;
689 690 691
    --use-tcmalloc)
      use_tcmalloc="yes"
      ;;
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
    --with-debug)
      with_debug_flag="yes"
      fast_flag="no"
      ;;
    --debug)
      compile_debug_flag="yes"
      ;;
    --no-developer)
      developer_flag="no"
      ;;
    --developer)
      developer_flag="yes"
      ;;
    --commercial)
      gpl="no"
      ;;
    --gpl)
      gpl="yes"
      ;;
    --compiler=*)
      compiler=`get_key_value "$1"`
      parse_compiler
      ;;
    --cpu=*)
      cpu_type=`get_key_value "$1"`
      parse_cpu_type
      ;;
    --warning-mode=*)
      warning_mode=`get_key_value "$1"`
      parse_warning_mode
      ;;
    --warnings)
      warning_mode="normal"
      ;;
    --32)
727
      if test "x$explicit_size_set" != "x" ; then
728 729 730
        echo "Cannot set both --32 and --64"
        exit 1
      fi
731
      explicit_size_set="yes"
732
      m64="no"
733 734
      ;;
    --64)
735
      if test "x$explicit_size_set" != "x" ; then
736 737 738
        echo "Cannot set both --32 and --64"
        exit 1
      fi
739
      explicit_size_set="yes"
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
      m64="yes"
      ;;
    --package=*)
      package=`get_key_value "$1"`
      parse_package
      ;;
    --parallelism=*)
      parallelism=`get_key_value "$1"`
      ;;
    --use-autotools)
      use_autotools="yes"
      ;;
    --no-autotools)
      use_autotools="no"
      ;;
    --configure-only)
      just_configure="yes"
      ;;
    --print-only)
      just_print="yes"
      ;;
    --static-linking)
      static_linking_flag="yes"
      ;;
    --strip)
      strip_flag="yes"
      ;;
    --error-inject)
      error_inject_flag="yes"
      ;;
    --valgrind)
      valgrind="yes"
      ;;
    --fast)
      fast_flag="yes"
      ;;
    --with-flags)
      shift
      break
      ;;
    --with-help)
      with_usage
      exit 0
      ;;
    --sysadmin-help)
      sysadmin_usage
      exit 0
      ;;
    --developer-help)
      developer_usage
      exit 0
      ;;
    --extended-help)
      extended_usage
      exit 0
      ;;
    --help)
      usage
      exit 0
      ;;
    *)
      echo "Unknown option '$1'"
      exit 1
      ;;
    esac
    shift
  done
  for flag in $@
  do
    with_flags="$with_flags $flag"
  done
}

#
# We currently only support Linux, FreeBSD/OpenBSD, Mac OS X and Solaris
#
check_os()
{
  case "`uname -s`" in
    Linux)
      os="linux"
      ;;
    FreeBSD|OpenBSD)
      os="bsd"
      ;;
    Darwin)
      os="MacOSX"
      ;;
    SunOS)
      os="Solaris"
      ;;
    *)
      os="Unknown"
      ;;
  esac

}

set_cpu_base()
{
  if test "x$cpu_type" = "x" ; then
    if test "x$cpu_arg" = "x" ; then
      usage "CPU type not discovered, cannot proceed"
843
      exit 1
844 845 846
    fi
    case "$cpu_arg" in
      core2 | nocona | prescott | pentium* | i*86 )
847
        # Intel CPU
848 849
        cpu_base_type="x86"
        ;;
850 851
      athlon* | opteron* | k6 | k8 )
        # AMD CPU
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869
        cpu_base_type="x86"
        ;;
      sparc )
        cpu_base_type="sparc"
        ;;
      itanium )
        cpu_base_type="itanium"
        ;;
      * )
        usage "CPU type $cpu_arg not handled by this script"
        exit 1
        ;;
    esac
  else
    cpu_base_type="$cpu_type"
    check_cpu_cflags=""
  fi
  if test "x$os" = "xMacOSX" ; then
870
    if test "x$m64" = "x" ; then
871 872
      m64="no"
    fi
873
  elif test "x$os" = "xSolaris" ; then
874
    if test "x$m64" = "x" ; then
875 876
      m64="yes"
    fi
877
  elif test "x$m64" = "x" ; then
878 879 880
    if test "x$cpu_arg" = "xnocona" || test "x$cpu_arg" = "xcore2" || \
       test "x$cpu_arg" = "xathlon64" || test "x$cpu_arg" = "xopteron" ; then
      m64="yes"
881
    else
882 883 884 885 886 887
      m64="no"
    fi
  fi
  echo "Discovered CPU of type $cpu_base_type ($cpu_arg) on $os"
  if test "x$m64" = "xyes" ; then
    echo "Will compile 64-bit binaries"
888
  else
889
    echo "Will compile 32-bit binaries"
890 891 892 893 894 895 896 897 898 899 900 901 902
  fi
  return 0
}

#
# Add to the variable commands with the configure command
# 
init_configure_commands()
{
  cflags="$c_warnings $base_cflags $compiler_flags"
  cxxflags="$cxx_warnings $base_cxxflags $compiler_flags"
  configure="./configure $base_configs $with_flags"

903
  env_flags="CC=\"$CC\" CFLAGS=\"$cflags\" CXX=\"$CXX\" CXXFLAGS=\"$cxxflags\""
904
  if test "x$LDFLAGS" != "x" ; then
905
    env_flags="$env_flags LDFLAGS=\"$LDFLAGS\""
906 907
  fi
  if test "x$ASFLAGS" != "x" ; then
908
    env_flags="$env_flags ASFLAGS=\"$ASFLAGS\""
909 910
  fi
  commands="$commands
911
    $env_flags $configure"
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
} 

#
# Initialise the variable commands with the commands needed to generate
# the configure script.
#
init_auto_commands()
{
  set_libtoolize_version
  commands="\
  $make -k maintainer-clean || true
  /bin/rm -rf */.deps/*.P configure config.cache
  /bin/rm -rf  storage/*/configure storage/*/config.cache autom4te.cache
  /bin/rm -rf storage/*/autom4te.cache;"
#
# --add-missing instructs automake to install missing auxiliary files
# and --force to overwrite them if they already exist
#
  commands="$commands
  aclocal || die \"Can't execute aclocal\"
  autoheader || die \"Can't execute autoheader\"
  $LIBTOOLIZE --automake --copy --force || die \"Can't execute libtoolize\"
  automake --add-missing --copy --force || die \"Can't execute automake\"
  autoconf || die \"Can't execute autoconf\""
}

#
# Add to the variable commands the make command and possibly also
# strip commands
#
add_make_commands()
{
  AM_MAKEFLAGS="-j $parallelism"
  commands="$commands
  $make $AM_MAKEFLAGS"

  if test "x$strip_flag" = "xyes" ; then
    commands="$commands
    mkdir -p tmp
    nm --numeric-sort sql/mysqld  > tmp/mysqld.sym
    objdump -d sql/mysqld > tmp/mysqld.S
    strip sql/mysqld
    strip storage/ndb/src/kernel/ndbd
    strip storage/ndb/src/mgmsrv/ndb_mgmd
    strip storage/ndb/src/mgmclient/ndb_mgm"
  fi
}

#
# Set make version, but only gmake is supported :)
#
set_make_version()
{
  if gmake --version > /dev/null 2>&1
  then
    make=gmake
  else
    make=make
  fi
  if test "x`$make --version | grep GNU`" = "x" ; then
    die "Only gmake is supported"
  fi
}

#
# Find a libtoolize binary, both libtoolize and glibtoolize are
# ok, use first found.
#
set_libtoolize_version()
{
  LIBTOOLIZE=not_found
  save_ifs="$IFS"; IFS=':'
  for dir in $PATH
  do
    if test -x $dir/libtoolize
    then
      LIBTOOLIZE=libtoolize
      echo "Found libtoolize in $dir"
      break
    fi
    if test -x $dir/glibtoolize
    then
      LIBTOOLIZE=glibtoolize
      echo "Found glibtoolize in $dir"
      break
    fi
  done
  IFS="$save_ifs"
  if test "x$LIBTOOLIZE" = "xnot_found" ; then
    die "Found no libtoolize version, quitting here"
  fi
  return
}

#
# If ccache (a compiler cache which reduces build time)
# (http://samba.org/ccache) is installed, use it.
# We use 'grep' and hope that 'grep' works as expected
# (returns 0 if finds lines)
# We do not use ccache when gcov is used. Also only when
# gcc is used.
#
1014
set_ccache_usage()
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
{
  if test "x$compiler" = "xgcc" ; then
    if ccache -V > /dev/null 2>&1 && test "$USING_GCOV" != "1"
    then
      echo "$CC" | grep "ccache" > /dev/null || CC="ccache $CC"
      echo "$CXX" | grep "ccache" > /dev/null || CXX="ccache $CXX"
    fi
  fi
}

#
# Set flags for various build configurations.
# Used in -valgrind builds
#
set_valgrind_flags()
{
  if test "x$valgrind_flag" = "xyes" ; then
1032
    loc_valgrind_flags="-UFORCE_INIT_OF_VARS -DHAVE_purify "
1033 1034
    loc_valgrind_flags="$loc_valgrind_flags -DMYSQL_SERVER_SUFFIX=-valgrind-max"
    compiler_flags="$compiler_flags $loc_valgrind_flags"
1035
    with_flags="$with_flags --with-valgrind"
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
  fi
}

#
# Set up warnings; default is to use no warnings, but if warning_mode
# is used a lot of warning flags are set up. These flags are valid only
# for gcc, so for other compilers we ignore the warning_mode.
#
set_warning_flags()
{
  if test "x$developer_flag" = "xyes" && test "x$warning_mode" = "x" ; then
    warning_mode="normal"
  fi
  if test "x$compiler" = "xgcc" ; then
    if test "x$warning_mode" = "normal" || test "x$warning_mode" = "extra" ; then
# Both C and C++ warnings
      warnings="$warnings -Wimplicit -Wreturn-type -Wswitch -Wtrigraphs"
      warnings="$warnings -Wcomment -W"
      warnings="$warnings -Wchar-subscripts -Wformat -Wparentheses -Wsign-compare"
      warnings="$warnings -Wwrite-strings -Wunused-function -Wunused-label"
      warnings="$warnings -Wunused-value -Wunused-variable"

      if test "x$warning_mode" = "extra" ; then
        warnings="$warnings -Wshadow"
      fi
# C warnings
      c_warnings="$warnings -Wunused-parameter"
# C++ warnings
      cxx_warnings="$warnings -Woverloaded-virtual -Wsign-promo -Wreorder"
      cxx_warnings="$warnings -Wctor-dtor-privacy -Wnon-virtual-dtor"
1066
      compiler_flags="$compiler_flags -Wuninitialized"
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
    elif test "x$warning_mode" = "xpedantic" ; then
      warnings="-W -Wall -ansi -pedantic -Wno-long-long -D_POSIX_SOURCE"
      c_warnings="$warnings"
      cxx_warnings="$warnings -std=c++98"
# Reset CPU flags (-mtune), they don't work in -pedantic mode
     check_cpu_cflags=""
    fi
  fi
}

#
# Used in -debug builds
#
set_with_debug_flags()
{
  if test "x$with_debug_flag" = "xyes" ; then
    if test "x$developer_flag" = "xyes" ; then
      loc_debug_flags="-DUNIV_MUST_NOT_INLINE -DEXTRA_DEBUG -DFORCE_INIT_OF_VARS "
      compiler_flags="$compiler_flags $loc_debug_flags"
    fi
  fi
}

#
# Flag for optimizing builds for developers.
#
set_no_omit_frame_pointer_for_developers()
{
  if test "x$fast_flag" != "xno" ; then
    if test "x$developer_flag" = "xyes" && test "x$compiler" = "xgcc" ; then
# Be as fast as we can be without losing our ability to backtrace.
      compiler_flags="$compiler_flags -fno-omit-frame-pointer"
    fi
  fi
}

#
# Add -g to all builds that requested debug information in build
#
set_debug_flag()
{
  if test "x$compile_debug_flags" = "xyes" ; then
    compiler_flags="$compiler_flags -g"
  fi
}

1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
#
# We compile in SSL support if we can, this isn't possible if CXX
# and CC aren't the same and we're not using GCC.
# 
set_ssl()
{
  if test "x$compiler" = "xgcc" && \
     test "x$CC" = "x$CXX" ; then
    base_configs="$base_configs --with-ssl"
  fi
}

1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
#
# Base options used by all packages
#
# SSL library to use. --with-ssl selects the bundled yaSSL
# implementation of SSL. To use openSSL, you must point out the location
# of the openSSL headers and libs on your system.
# For example: --with-ssl=/usr
#
set_base_configs()
{
  base_configs="$base_configs --prefix=$prefix"
  base_configs="$base_configs --libexecdir=$prefix/bin"
  base_configs="$base_configs --with-zlib-dir=bundled"
  if test "x$datadir" = "x" ; then
    base_configs="$base_configs --localstatedir=$prefix/data"
  else
    base_configs="$base_configs --localstatedir=$datadir"
  fi
  if test "x$with_debug_flag" = "xyes" ; then
1144
    base_configs="$base_configs --with-debug"
1145 1146 1147 1148 1149
  fi
  base_configs="$base_configs --enable-local-infile"
  base_configs="$base_configs --enable-thread-safe-client"
  base_configs="$base_configs --with-big-tables"
  base_configs="$base_configs --with-extra-charsets=all"
1150 1151 1152
  if test "x$with_fast_mutexes" = "xyes" ; then
    base_configs="$base_configs --with-fast-mutexes"
  fi
1153 1154
  base_configs="$base_configs --with-pic"
  base_configs="$base_configs --with-csv-storage-engine"
1155
  base_configs="$base_configs --with-perfschema"
1156 1157 1158 1159 1160 1161 1162 1163 1164
}

#
# Add all standard engines and partitioning (included as part of MySQL
# Cluster storage engine as well) as part of MySQL Server. These are 
# added in all packages except the classic package.
#
set_base_engines()
{
1165
  engine_configs="--with-archive-storage-engine"
1166
  engine_configs="$engine_configs --with-blackhole-storage-engine"
1167
  engine_configs="$engine_configs --without-example-storage-engine"
1168 1169
  engine_configs="$engine_configs --with-federated-storage-engine"
  engine_configs="$engine_configs --with-partition"
1170
  base_configs="$base_configs $engine_configs"
1171 1172
}

1173
set_innodb_engine()
1174 1175
{
  base_configs="$base_configs --with-innodb"
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185
}

set_ndb_engine()
{
  base_configs="$base_configs --with-ndbcluster"
  base_configs="$base_configs --without-ndb-debug"
}

set_pro_package()
{
1186 1187 1188
  if test "x$without_comment" != "xyes" ; then
    base_configs="$base_configs --with-comment=\"MySQL Enterprise Pro $version_text built from source\""
  fi
1189 1190 1191 1192 1193 1194 1195
  if test "x$with_debug_flag" = "xyes" ; then
    base_configs="$base_configs --with-server-suffix=\"-debug\""
  fi
}

set_cge_extended_package()
{
1196 1197
  if test "x$without_comment" != "xyes" ; then
    base_configs="$base_configs --with-comment=\"MySQL Cluster Carrier Grade Extended Edition $version_text built from source\""
1198 1199 1200 1201
  fi
  if test "x$with_debug_flag" = "xyes" ; then
    base_configs="$base_configs --with-server-suffix=\"-cge-extended-debug\""
  else
1202
    base_configs="$base_configs --with-server-suffix=\"-cge-extended\""
1203 1204 1205 1206 1207
  fi
}

set_cge_package()
{
1208 1209 1210
  if test "x$without_comment" != "xyes" ; then
    base_configs="$base_configs --with-comment=\"MySQL Cluster Carrier Grade Edition $version_text built from source\""
  fi
1211 1212 1213
  if test "x$with_debug_flag" = "xyes" ; then
    base_configs="$base_configs --with-server-suffix=\"-cge-debug\""
  else
1214
    base_configs="$base_configs --with-server-suffix=\"-cge\""
1215 1216 1217 1218 1219
  fi
}

set_classic_package()
{
1220 1221 1222
  if test "x$without_comment" != "xyes" ; then
    base_configs="$base_configs --with-comment=\"MySQL Classic $version_text built from source\""
  fi
1223 1224 1225
  if test "x$with_debug_flag" = "xyes" ; then
    base_configs="$base_configs --with-server-suffix=\"-debug\""
  fi
1226
  base_configs="$base_configs --without-example-storage-engine"
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253
}

#
# Special handling of readline; use readline from the MySQL
# distribution if building a GPL version, otherwise use libedit.
#
set_readline_package()
{
  if test -d "$path/../cmd-line-utils/readline" && test "x$gpl" = "xyes" ; then
    base_configs="$base_configs --with-readline"
  elif test -d "$path/../cmd-line-utils/libedit" ; then
    base_configs="$base_configs --with-libedit"
  fi
}

#
# If fast flag set by user we also add architecture as discovered to 
# compiler flags to make binary optimised for architecture at hand. 
# We use this feature on gcc compilers.
#
set_gcc_special_options()
{
  if test "x$fast_flag" = "xyes" && test "x$compiler" = "xgcc" ; then
    compiler_flags="$compiler_flags $check_cpu_cflags"
  fi
}

1254 1255 1256
set_cc_and_cxx_for_gcc()
{
  if test "x$CC" = "x" ; then
1257
    CC="gcc -static-libgcc -fno-exceptions"
1258 1259
  fi
  if test "x$CXX" = "x" ; then
1260
    CXX="gcc -static-libgcc -fno-exceptions"
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
  fi
}

set_cc_and_cxx_for_icc()
{
  if test "x$CC" = "x" ; then
    CC="icc -static-intel -static-libgcc"
  fi
  if test "x$CXX" = "x" ; then
    CXX="icpc -static-intel -static-libgcc"
  fi
}

set_cc_and_cxx_for_forte()
{
  if test "x$CC" = "x" ; then
1277
    CC="cc"
1278 1279
  fi
  if test "x$CXX" = "x" ; then
1280
    CXX="CC"
1281 1282 1283
  fi
}

1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
#
# If we discover a Core 2 Duo architecture and we have enabled the fast
# flag, we enable a compile especially optimised for Core 2 Duo. This
# feature is currently available on Intel's icc compiler only.
#
set_icc_special_options()
{
  if test "x$fast_flag" = "xyes" && test "x$cpu_arg" = "xcore2" && \
     test "x$compiler" = "xicc" ; then
    compiler_flags="$compiler_flags -xT"
  fi
}

#
# FreeBSD Section
#
set_bsd_configs()
{
  if test "x$cpu_base_type" != "xx86" ; then
    usage "Only x86 CPUs supported for FreeBSD"
    exit 1
  fi
  if test "x$compiler" != "xgcc" ; then
    usage "Only gcc supported for FreeBSD"
    exit 1
  fi
  base_configs="$base_configs --enable-assembler"
1311 1312 1313
  if test "x$fast_flag" != "xno" ; then
    compiler_flags="$compiler_flags -O3"
  else
1314
    compiler_flags="$compiler_flags -O0"
1315 1316
  fi
  set_cc_and_cxx_for_gcc
1317 1318
}

1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
check_64_bits()
{
  echo "Checking for 32/64-bits compilation"
  echo "int main() { return 0; }" > temp_test.c
  if test "x$m64" = "xyes" ; then
    cmd="$CC $compile_flags -m64 temp_test.c"
    if ! $cmd 2>1 ; then
      m64="no"
      echo "Changing to 32-bits since 64-bits didn't work"
    else
      echo "Will use 64-bits"
    fi
  else
    cmd="$CC $compile_flags -m32 temp_test.c"
    if ! $cmd 2>1 ; then
      m64="yes"
      echo "Changing to 64-bits since 32-bits didn't work"
    else
      echo "Will use 32-bits"
    fi
  fi
  rm temp_test.c
1341 1342
}

1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
#
# Get GCC version
#
get_gcc_version()
{
  # check if compiler is gcc and dump its version
  cc_verno=`$cc -dumpversion 2>/dev/null`
  if test "x$?" = "x0" ; then
    set -- `echo $cc_verno | tr '.' ' '`
    cc_ver="GCC"
    cc_major=$1
    cc_minor=$2
    cc_patch=$3
    gcc_version=`expr $cc_major '*' 100 '+' $cc_minor`
  fi
}

#
# Link Time Optimizer in GCC (LTO) uses a parameter -flto
# which was added to GCC 4.5, if --with-link-time-optimizer
# is set then use this feature
#
check_for_link_time_optimizer()
{
  get_gcc_version
  if test "$gcc_version" -ge 405 && \
     test "x$with_link_time_optimizer" = "xyes" ; then
    compiler_flags="$compiler_flags -flto"
    LDFLAGS="$LDFLAGS -flto"
  fi
}
1374 1375 1376 1377 1378 1379 1380
#
# Linux Section
#
set_linux_configs()
{
  if test "x$cpu_base_type" != "xx86" && \
     test "x$cpu_base_type" != "xitanium" ; then
1381
    usage "Only x86 and Itanium CPUs supported for Linux"
1382 1383
    exit 1
  fi
1384 1385 1386
  if test "x$use_tcmalloc" = "xyes" ; then
    base_configs="$base_configs --with-mysqld-libs=-ltcmalloc_minimal"
  fi
1387 1388 1389 1390
  if test "x$cpu_base_type" = "xx86" ; then
    base_configs="$base_configs --enable-assembler"
  fi
  if test "x$compiler" = "xgcc" ; then
1391 1392
    set_cc_and_cxx_for_gcc
    if test "x$fast_flag" != "xno" ; then
1393 1394
      if test "x$fast_flag" = "xyes" ; then
        compiler_flags="$compiler_flags -O3"
1395
        check_for_link_time_optimizer
1396 1397 1398
      else
        compiler_flags="$compiler_flags -O2"
      fi
1399
    else
1400
      compiler_flags="$compiler_flags -O0"
1401
    fi
1402
    check_64_bits
1403 1404
    if test "x$m64" = "xyes" ; then
      compiler_flags="$compiler_flags -m64"
1405 1406
    else
      compiler_flags="$compiler_flags -m32"
1407 1408 1409 1410
    fi
# configure will set proper compiler flags for gcc on Linux
  elif test "x$compiler" = "xicc" ; then
    compiler_flags="$compiler_flags -mp -restrict"
1411
    set_cc_and_cxx_for_icc
1412 1413 1414 1415 1416
    if test "x$cpu_base_type" = "xitanium" ; then
      compiler_flags="$compiler_flags -no-ftz"
    fi
    if test "x$fast_flag" != "xno" ; then
      compiler_flags="$compiler_flags -O3 -unroll2 -ip"
1417 1418
      if test "x$fast_flag" = "xyes" && \
         test "x$with_link_time_optimizer" = "xyes" ; then
1419
        compiler_flags="$compiler_flags -ipo"
1420
        LDFLAGS="$LDFLAGS -ipo"
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433
      fi
    fi
  else
    usage "Only gcc and icc compilers supported for Linux"
    exit 1
  fi
}

#
# Solaris Section
#
set_solaris_configs()
{
1434
# Use mtmalloc as malloc, see Tim Cook blog
1435 1436 1437
# For information on optimal compiler settings, see article at
# http://developers.sun.com/solaris/articles/mysql_perf_tune.html
# by Luojia Chen at Sun.
1438
  base_configs="$base_configs --with-named-curses=-lcurses"
1439
  case "`uname -a`" in
1440 1441
    *5.8* | *5.9* )
      ;;
1442

1443 1444
    *5.10* | *5.11*)
      base_configs="$base_configs --with-mysqld-libs=-lmtmalloc"
1445 1446
      ;;
    *)
1447 1448
      usage "Only versions 8,9, 10 and 11 supported for Solaris"
      exit 1
1449 1450 1451 1452 1453 1454
  esac
  if test "x$cpu_base_type" != "xx86" && \
     test "x$cpu_base_type" != "xsparc" ; then
    usage "Only x86 and Sparc CPUs supported for Solaris"
    exit 1
  fi
1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468
  if test "x$compiler" != "xgcc" && \
     test "x$compiler" != "xforte" ; then
    usage "Only gcc and Forte compilers supported for Solaris"
    exit 1
  fi
  if test "x$m64" = "xyes" ; then
    compiler_flags="$compiler_flags -m64"
    LDFLAGS="-m64"
    ASFLAGS="$ASFLAGS -m64"
  else
    compiler_flags="$compiler_flags -m32"
    LDFLAGS="-m32"
    ASFLAGS="$ASFLAGS -m32"
  fi
1469
  if test "x$compiler" = "xgcc" ; then
1470
    set_cc_and_cxx_for_gcc
1471
    if test "x$cpu_base_type" != "xx86" ; then
1472 1473
      usage "gcc currently not supported for Solaris on SPARC"
      exit 1
1474
    fi
1475 1476 1477
    if test "x$fast_flag" = "xyes" ; then
      LDFLAGS="$LDFLAGS -O3"
      compiler_flags="$compiler_flags -O3"
1478
      check_for_link_time_optimizer
1479
    else
1480 1481 1482 1483
      if test "x$fast_flag" = "xgeneric" ; then
        LDFLAGS="$LDFLAGS -O2"
        compiler_flags="$compiler_flags -O2"
      else
1484 1485
        LDFLAGS="$LDFLAGS -O0"
        compiler_flags="$compiler_flags -O0"
1486
      fi
1487
    fi
1488 1489
  else
#Using Forte compiler (SunStudio)
1490
    set_cc_and_cxx_for_forte
1491
    compiler_flags="$compiler_flags -mt"
1492
    LDFLAGS="$LDFLAGS -mt"
1493 1494 1495 1496 1497 1498 1499 1500
    compiler_flags="$compiler_flags -fsimple=1"
    compiler_flags="$compiler_flags -ftrap=%none"
    compiler_flags="$compiler_flags -xbuiltin=%all"
    compiler_flags="$compiler_flags -xlibmil"
    compiler_flags="$compiler_flags -xlibmopt"
    if test "x$fast_flag" = "xyes" ; then
      compiler_flags="$compiler_flags -xtarget=native"
      compiler_flags="$compiler_flags -xunroll=3"
1501 1502 1503 1504
      if test "x$with_link_time_optimizer" = "xyes" ; then
        compiler_flags="$compiler_flags -xipo"
        LDFLAGS="$LDFLAGS -xipo"
      fi
1505 1506 1507
    else
      compiler_flags="$compiler_flags -xtarget=generic"
    fi
1508
    if test "x$cpu_base_type" = "xx86" ; then
1509
      compiler_flags="$compiler_flags -nofstore"
1510
      base_cxx_flags="$base_cxx_flags -features=no%except"
1511 1512 1513 1514
      if test "x$fast_flag" = "xyes" ; then
        compiler_flags="$compiler_flags -xregs=frameptr"
        compiler_flags="$compiler_flags -xO4"
      else
1515 1516 1517 1518 1519 1520
        compiler_flags="$compiler_flags -xregs=no%frameptr"
        if test "x$fast_flag" = "xgeneric" ; then
          compiler_flags="$compiler_flags -xO2"
        else
          compiler_flags="$compiler_flags -xO0"
        fi
1521
      fi
1522 1523
    else
#Using SPARC cpu with SunStudio (Forte) compiler
1524 1525
      ASFLAGS="$ASFLAGS -xarch=sparc"
      LDFLAGS="$LDFLAGS -xarch=sparc"
1526 1527
      base_cxxflags="$base_cxxflags -noex"
      base_cflags="$base_cflags -xstrconst"
1528 1529 1530 1531 1532 1533
      compiler_flags="$compiler_flags -xarch=sparc"
      if test "x$fast_flag" = "xyes" ; then
        compiler_flags="$compiler_flags -xbinopt=prepare"
        LDFLAGS="$LDFLAGS -xbinopt=prepare"
        compiler_flags="$compiler_flags -xO4"
      elif test "x$fast_flag" = "xgeneric" ; then
1534
        compiler_flags="$compiler_flags -xO3"
1535
      else
1536
        compiler_flags="$compiler_flags -xO0"
1537
      fi
1538 1539 1540 1541 1542 1543 1544 1545 1546
    fi
  fi
}

#
# Mac OS X Section
#
set_macosx_configs()
{
1547
  if test "x$cpu_base_type" != "xx86" || test "x$compiler" != "xgcc" ; then
1548 1549 1550 1551 1552 1553 1554
    usage "Only gcc/x86 supported for Mac OS X"
    exit 1
  fi
#
# Optimize for space as long as it doesn't affect performance, use some
# optimisations also when not in fast mode.
#
1555
  base_cxxflags="$base_cxxflags -felide-constructors"
1556
  compiler_flags="$compiler_flags -fno-common"
1557 1558 1559 1560
  if test "x$m64" = "xyes" ; then
    compiler_flags="$compiler_flags -m64"
    compiler_flags="$compiler_flags -arch x86_64"
  else
1561
    compiler_flags="$compiler_flags -m32"
1562 1563
    compiler_flags="$compiler_flags -arch i386"
  fi
1564 1565 1566
  if test "x$fast_flag" != "xno" ; then
    compiler_flags="$compiler_flags -Os"
  else
1567
    compiler_flags="$compiler_flags -O0"
1568
  fi
1569
  set_cc_and_cxx_for_gcc
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649
}

#
# Use static linking for own modules and dynamic linking for system
# modules unless specifically requested to do everything statically.
# Should normally not be used; static_linking_flag kept in case someone 
# really needs it. Available only if developer flag is also set.
#
set_static_link_configs()
{
  if test "x$static_linking_flag" = "xyes" && test "x$developer_flag" = "xyes" ; then
    loc_static_link="--with-mysqld-ldflags=\"-all-static\""
    loc_static_link="$loc_static_link --with-client-ldflags=\"-all-static\""
  else
    loc_static_link="--with-mysqld-ldflags=\"-static\""
    loc_static_link="$loc_static_link --with-client-ldflags=\"-static\""
  fi
  base_configs="$base_configs $loc_static_link"
}

#
# Enable error injection in MySQL Server (for developer build only -
# extra check for developer flag required).
#
set_error_inject_configs()
{
  if test "x$error_inject_flag" = "xyes" && test "x$developer_flag" = "xyes" ; then
    base_configs="$base_configs --with-error-inject"
    if test "x$package" = "xndb" || test "x$package" = "xextended" ; then
      base_configs="$base_configs --with-ndb-ccflags='-DERROR_INSERT'"
    fi
  fi
}

set_default_package()
{
  if test "x$package" = "x" ; then
    if test "x$developer_flag" = "xyes" ; then
      package="extended"
    else
      package="cge"
    fi
  fi
}

set_autotool_flags()
{
  if test "x$use_autotools" = "x" ; then
    if test "x$developer_flag" = "xno" ; then
      use_autotools="no"
    else
      use_autotools="yes"
    fi
  fi
}

set_defaults_based_on_environment()
{
  if test ! -z "$MYSQL_DEVELOPER" ; then
    developer_flag="yes"
  fi
  if test ! -z "$MYSQL_DEVELOPER_DEBUG" ; then
    with_debug_flag="yes"
    fast_flag="no"
  fi
  if test ! -z "$MYSQL_DEVELOPER_PACKAGE" ; then
    package="$MYSQL_DEVELOPER_PACKAGE"
    parse_package
  fi
}

########################################################################

if test ! -f sql/mysqld.cc ; then
  die "You must run this script from the MySQL top-level directory"
fi

cpu_type=
package=
prefix="/usr/local/mysql"
1650
parallelism="8"
1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677
fast_flag="generic"
compiler="gcc"
gpl="yes"
version_text=
developer_flag="no"
just_configure=
warning_mode=
with_flags=
error_inject_flag=
with_debug_flag=
compile_debug_flag=
strip_flag=
valgrind_flag=
static_linking_flag=
compiler_flags=
os=
cpu_base_type=
warnings=
c_warnings=
cflags=
base_cflags=
cxx_warnings=
base_cxxflags=
base_configs=
debug_flags=
cxxflags=
m64=
1678
explicit_size_set=
1679 1680 1681
datadir=
commands=
use_autotools=
1682 1683 1684
engine_configs=
ASFLAGS=
LDFLAGS=
1685
use_tcmalloc=
1686 1687 1688 1689
without_comment="yes"
with_fast_mutexes=
with_link_time_optimizer=
gcc_version="0"
1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705

set_defaults_based_on_environment

parse_options "$@"

set_autotool_flags
set_default_package

set -e

#
# Check for the CPU and set up CPU specific flags. We may reset them
# later.
# This call sets the cpu_arg and check_cpu_args parameters
#
path=`dirname $0`
1706 1707 1708
if test "x$compiler" = "xgcc" ; then
  compiler=
fi
1709
. "$path/check-cpu"
1710 1711 1712
if test "x$compiler" = "x" ; then
  compiler="gcc"
fi
1713
check_os
1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746
set_cpu_base
if test "x$?" = "x1" ; then
  exit 1
fi

#
# Set up c_warnings and cxx_warnings; add to compiler_flags.
# Possibly reset check_cpu_flags.
#
set_warning_flags

#
# Add to compiler_flags.
#
set_valgrind_flags
set_with_debug_flags
set_no_omit_frame_pointer_for_developers
set_debug_flag
set_gcc_special_options
set_icc_special_options

#
# Definitions of various packages possible to compile. The default is to
# build a source variant of MySQL Cluster Carrier Grade Edition 
# including all storage engines except InnoDB, and to use GPL libraries.
#
set_base_configs
if test "x$gpl" = "xyes" ; then
  version_text="GPL version"
else
  version_text="Commercial version"
fi
if test "x$package" = "xpro" ; then
1747 1748
  set_base_engines
  set_innodb_engine
1749 1750
  set_pro_package
elif test "x$package" = "xextended" ; then
1751 1752 1753
  set_base_engines
  set_ndb_engine
  set_innodb_engine
1754 1755
  set_cge_extended_package
elif test "x$package" = "xcge" ; then
1756 1757
  set_base_engines
  set_ndb_engine
1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783
  set_cge_package
elif test "x$package" = "xclassic" ; then
  set_classic_package
else
  die "No supported package was used, internal error"
fi
set_readline_package
set_static_link_configs
set_error_inject_configs

#
# This section handles flags for specific combinations of compilers,
# operating systems, and processors.
#

if test "x$os" = "xlinux" ; then
  set_linux_configs
elif test "x$os" = "xSolaris" ; then
  set_solaris_configs
elif test "x$os" = "xMacOSX" ; then
  set_macosx_configs
elif test "x$os" = "xbsd" ; then
  set_bsd_configs
else
  die "Operating system not supported by this script"
fi
1784
set_ssl
1785 1786 1787 1788 1789
#
# Final step before setting up commands is to set up proper make and
# proper libtoolize versions, and to determine whether to use ccache.
#
set_make_version
1790
set_ccache_usage
1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813

#
# Set up commands variable from variables prepared for base 
# configurations, compiler flags, and warnings flags.
# 
if test "x$use_autotools" = "xyes" ; then
  init_auto_commands
fi
init_configure_commands

if test "x$just_configure" != "xyes" ; then
  add_make_commands
fi

#
# The commands variable now contains the entire command to be run for
# the build; we either execute it, or merely print it out.
#
if test "x$just_print" = "xyes" ; then
  echo "$commands"
else
  eval "set -x; $commands"
fi