build_mccge.sh 52.6 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
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
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
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
575
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
617
618
619
620
621
622
623
624
625
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
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
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
727
728
729
730
731
732
733
734
735
736
737
738
739
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
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
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
#!/bin/sh

# Copyright (c) 2008, 2010, Oracle.
# Copyright (c) 2009-2011 Monty Program Ab
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; version 2
# of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA

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 MariaDB wanting to try out
  early versions 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 build process.

  This help text is targeted towards those that want to debug and test
  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.

  Three environment variables can be used to define 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. 

  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

  It is assumed that you are building on a computer which is of the 
  same type as that on which you intend to run the program.

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

  shell> BUILD/build_mccge.sh

  This performs the following operations:
    1) Detects the operating system. Currently, Linux, FreeBSD, Solaris 
      8/9/10/11, and Mac OS X are supported by this script.
    2) Detect the type of CPU being used. Currently supported processors 
      are: x86 for all supported operating systems, Itanium for Linux 
      with GCC, and x86 + SPARC for Solaris using the Forte compiler and
      finally x86 on Linux using the Intel compiler.
    3) Invokes the GCC compiler.
    4) Builds a set of of binaries ; for more information about these,
       see --extended-help.
    5) Default compiler is always gcc.
  
  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 launchpad tree then you should read 
  --developer-help.

  If your building on a Solaris SPARC machine and you want to compile
  using SunStudio you must set 
  --compiler=forte; if you want to build using the Intel compiler on 
  Linux, you need to set --compiler=icc. If you want to use the AMD
  compiler Open64 set --compiler=open64.

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

  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 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 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.
EOF
}

usage()
{
cat <<EOF

Usage: $0 [options]
  --help                  Show this help message.
  --sysadmin-help         Show help for system administrators wishing 
                          to build MariaDB
  --developer-help        Show help for developers trying to build MariaDB
  --with-help             Show extended help on --with-xxx options to 
                          configure
  --extended-help         Show extended help message
  --without-debug         Build non-debug version
  --use-comment           Set the comment in the build
  --with-fast-mutexes     Use try/retry method of acquiring mutex
  --without-fast-mutexes  Don't use try/retry method of acquiring mutex
  --without-perfschema    Don't build with performance schema
  --generate-feedback path Compile with feedback using the specified directory
                          to store the feedback files
  --use-feedback path     Compile using feedback information from the specified
                          directory
  --with-debug            Build debug version
  --extra-debug-flag flag Add -Dflag to compiler flags
                          InnoDB supports the following debug flags,
                          UNIV_DEBUG, UNIV_SYNC_DEBUG, UNIV_MEM_DEBUG,
                          UNIV_DEBUG_THREAD_CREATION, UNIV_DEBUG_LOCK_VALIDATE,
                          UNIV_DEBUG_PRINT, UNIV_DEBUG_FILE_ACCESS,
                          UNIV_LIGHT_MEM_DEBUG, UNIV_LOG_DEBUG,
                          UNIV_IBUF_COUNT_DEBUG, UNIV_SEARCH_DEBUG,
                          UNIV_LOG_LSN_DEBUG, UNIV_ZIP_DEBUG, UNIV_AHI_DEBUG,
                          UNIV_DEBUG_VALGRIND, UNIV_SQL_DEBUG, UNIV_AIO_DEBUG,
                          UNIV_BTR_DEBUG, UNIV_LRU_DEBUG, UNIV_BUF_DEBUG,
                          UNIV_HASH_DEBUG, UNIV_LIST_DEBUG, UNIV_IBUF_DEBUG
  --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.
  --with-mso              Special flag used by Open64 compiler (requres at
                          least version 4.2.3) that enables optimisations
                          for multi-core scalability.
  --configure-only        Stop after running 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 MariaDB developers use
  --no-developer          Do not use extensions that most developers of 
                          MariaDB use
  --compiler=[gcc|icc|forte|SunStudio|open64] Select compiler
  --cpu=[x86|x86_64|sparc|itanium]            Select CPU type
                          x86 => x86 and 32-bit binary
                          x86_64 => x86 and 64 bit binary
  --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=[pro|classic] Select package to build
  --parallelism=number    Define parallelism in make
  --strip                 Strip binaries
  --error-inject          Enable error injection into MariaDB Server and 
                          data nodes
  --valgrind              Build with valgrind
  --fast                  Optimise for CPU architecture built on
  --static-linking        Statically link system libraries into binaries
  --use-tcmalloc          Link with tcmalloc instead of standard malloc (Linux only)
  --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 to build
  performance-optimised MariaDB versions from source on 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.

  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.

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

  Different MariaDB 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=pro
    storage engines:
      ARCHIVE, BLACKHOLE, CSV, FEDERATED, INNODB, MYISAM
      (All storage engines except NDB)
    comment: Pro versions
    version string suffix: [none]

  --package=classic
    storage engines: CSV, MYISAM
    comment: Version without InnoDB and Maria
    version string suffix: [none]

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

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

  --with-debug[=full]
    This option will ensure that the version is built with debug
    information enabled; the optimisation level is decreased to -O.

  --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
    if possible (GCC and same CC and CXX).
    (cannot be overridden).

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

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

  --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" package.

  --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.

  --with-libedit
    Use the BSD licensed library for command editing functions.

  --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.
    Investigations have shown mtmalloc to be the best choice on Solaris,
    also umem has good performance on Solaris but better debugging
    capabilities.

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

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

    The --fast option adds -mtune=cpu_arg to the C/C++ flags (provides
    support for Nocona, K8, and other processors), this option is valid
    when gcc is the compiler.

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

    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

  Feedback profiler on gcc
  ------------------------
  Using gcc --generate-feedback=path causes the following flags to be added
  to the compiler flags.

  --fprofile-generate
  --fprofile-dir=path

  Using gcc with --use-feedback=path causes the following flags to be added
  to the compiler flags. --fprofile-correction indicates MySQL is a multi-
  threaded application and thus counters can be inconsistent with each other
  and the compiler should take this into account.

  --fprofile-use
  --fprofile-dir=path
  --fprofile-correction

  Feedback compilation using Open64
  ---------------------------------

  Using Open64 with --generate-feedback=path causes the following flags to
  be added to the compiler flags.

  -fb-create path/feedback

  Using Open64 with --use-feedback=path causes the following flags to be
  added to the compiler flags.

  --fb-opt path/feedback

  Linux/x86+Itanium/gcc
  -------------
    For debug builds -O is used and otherwise -O3 is used.Discovery of a
    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.)

    When gcc 4.5 is used and the user set --with-link-time-optimizer then
    also --flto is added to compiler flags and linker flags.

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

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

    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.

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

    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.

  Linux/x86/Open64
  ----------------
    For normal builds use -O3, when fast flag is set one also adds
    --march=auto to generate optimized builds for the CPU used. If
    --with-link-time-optimizer is set also -ipa is set. There is also
    a special flag --with-mso which can be set to get --mso set which
    activates optimisation for multi-core scalability.

  FreeBSD/x86/gcc
  ---------------
    No flags are used. Instead, configure determines the proper flags to 
    use.

  Solaris/x86/gcc
  ---------------
    All builds on Solaris are by default 64-bit, so -m64 is always used in
    the C/C++ flags. LDFLAGS is set to -m64 -O/-O2/-O3. If for
    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.

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

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

    Set -m64 (default) or -m32 (if specifically set) in ASFLAGS,
    LDFLAGS and C/C++ flags.

    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.

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

    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
    -features=no%except    This flag is set only on x86

    When compiling with fast we set (-ipo only used if we have
    set --with-link-time-optimizer):
    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
    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

    The optimisation level is
    -xO         Debug builds
    -xO2        Production build on SPARC
    -xO3        Production build on x86
    -xO4        Fast builds on SPARC/x86

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

    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.
  
    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.
EOF
}

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 )
      package="extended"
      ;;
    *)
      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"
      if test "x$m64" = "x" ; then
        m64="no"
      fi
      ;;
    x86_64 )
      cpu_type="x86"
      if test "x$m64" = "x" ; then
        m64="yes"
      fi
      ;;
    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"
      ;;
    forte | SunStudio | sunstudio )
      compiler="forte"
      ;;
    open64 | Open64 )
      compiler="open64"
      ;;
    *)
      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"`
      ;;
    --with-link-time-optimizer)
      with_link_time_optimizer="yes"
      ;;
    --without-debug)
      with_debug_flag="no"
      if test "x$fast_flag" != "xyes" ; then
        fast_flag="generic"
      fi
      ;;
    --use-comment)
      without_comment="no"
      ;;
    --with-fast-mutexes)
      with_fast_mutexes="yes"
      ;;
    --without-fast-mutexes)
      with_fast_mutexes="no"
      ;;
    --without-perfschema)
      with_perfschema="no"
      ;;
    --with-mso)
      with_mso="yes"
      ;;
    --use-tcmalloc)
      use_tcmalloc="yes"
      ;;
    --with-debug)
      with_debug_flag="yes"
      fast_flag="no"
      ;;
    --extra-debug-flag)
      shift
      extra_debug_flags="$extra_debug_flags -D$1"
      ;;
    --debug)
      compile_debug_flag="yes"
      ;;
    --no-developer)
      developer_flag="no"
      ;;
    --developer)
      developer_flag="yes"
      ;;
    --compiler=*)
      compiler=`get_key_value "$1"`
      parse_compiler
      ;;
    --generate-feedback)
      shift
      GENERATE_FEEDBACK_PATH="$1"
      ;;
    --use-feedback)
      shift
      USE_FEEDBACK_PATH="$1"
      ;;
    --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)
      if test "x$explicit_size_set" != "x" ; then
        echo "Cannot set both --32 and --64"
        exit 1
      fi
      explicit_size_set="yes"
      m64="no"
      ;;
    --64)
      if test "x$explicit_size_set" != "x" ; then
        echo "Cannot set both --32 and --64"
        exit 1
      fi
      explicit_size_set="yes"
      m64="yes"
      ;;
    --package=*)
      package=`get_key_value "$1"`
      parse_package
      ;;
    --parallelism=*)
      parallelism=`get_key_value "$1"`
      ;;
    --configure-only)
      just_configure="yes"
      ;;
    --print-only|--just-print)
      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"
      exit 1
    fi
    case "$cpu_arg" in
      core2 | nocona | prescott | pentium* | i*86 )
        # Intel CPU
        cpu_base_type="x86"
        ;;
      athlon* | opteron* | k6 | k8 )
        # AMD CPU
        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
    if test "x$m64" = "x" ; then
      m64="no"
    fi
  elif test "x$os" = "xSolaris" ; then
    if test "x$m64" = "x" ; then
      m64="yes"
    fi
  elif test "x$m64" = "x" ; then
    if test "x$cpu_arg" = "xnocona" || test "x$cpu_arg" = "xcore2" || \
       test "x$cpu_arg" = "xathlon64" || test "x$cpu_arg" = "xopteron" ; then
      m64="yes"
    else
      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"
  else
    echo "Will compile 32-bit binaries"
  fi
  return 0
}

#
# Add to the variable commands with the configure command
# 
init_configure_commands()
{
  path=`dirname $0`
  cp $path/cmake_configure.sh $path/../configure
  chmod +x $path/../configure
  cflags="$c_warnings $base_cflags $compiler_flags"
  cxxflags="$cxx_warnings $base_cxxflags $compiler_flags"
  configure="./configure $base_configs $with_flags"

  env_flags="CC=\"$CC\" CFLAGS=\"$cflags\" CXX=\"$CXX\" CXXFLAGS=\"$cxxflags\""
  if test "x$LDFLAGS" != "x" ; then
    env_flags="$env_flags LDFLAGS=\"$LDFLAGS\""
  fi
  if test "x$ASFLAGS" != "x" ; then
    env_flags="$env_flags ASFLAGS=\"$ASFLAGS\""
  fi
  commands="$commands
    $env_flags $configure"
} 

#
# 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
}

#