summaryrefslogtreecommitdiff
path: root/libmysqlclient/README-DEV
blob: b69995cbaa10877c365b1149513243074a73e7ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
This document describes how libmysqlclient was packaged for build2. In
particular, this understanding will be useful when upgrading to a new upstream
version. See ../README-DEV for general notes on MySQL packaging.

Symlink the required upstream components and provide our own implementations
for auto-generated headers:

$ ln -s ../upstream/LICENSE
$ ln -s ../../upstream/{vio,sql,mysys,mysys_ssl,libbinlogevents,libmysql} mysql
$ ln -s ../../upstream/include mysql/mysql
$ ln -s mysql/mysql_version.h.in mysql/version.h.in

Also make sure all source files are UTF-8-encoded:

$ mkdir -p mysql/strings
$ pushd mysql/strings
$ ln -s ../../../upstream/strings/{README,*.{cc,h}} .
$ mv ctype-czech.cc ctype-czech.cc.orig
$ iconv -f ISO-8859-2 -t UTF-8 ctype-czech.cc.orig >ctype-czech.cc
$ mv decimal.cc decimal.cc.orig
$ iconv -f UTF-8 -t UTF-8 -c decimal.cc.orig >decimal.cc
$ popd

Also add missing <limits> include to sql-common/sql_string.cc:

$ mkdir -p mysql/sql-common
$ pushd mysql/sql-common
$ ln -s ../../../upstream/sql-common/*.{cc,h} .
$ mv sql_string.cc sql_string.cc.orig
$ cp sql_string.cc.orig sql_string.cc
# Edit sql_string.cc, adding missing <limits> include.
$ popd

Note that we unable to generate mysql_version.h directly from the template as
it is included as "mysql_version.h" in upstream's source code, which makes
impossible using the header-generating machinery. That's why we create
mysql/mysql_version.h that includes <mysql/version.h> that we auto-generate
from upstream's mysql_version.h.in.

$ ln -s libbinlogevents/binlog_config.h.cmake mysql/binlog_config.h.cmake.orig

Use mysql/binlog_config.h.cmake.orig for creating mysql/binlog_config.h
manually, defining/undefining macros introduced with #cmakedefine.

$ ln -s ../../upstream/config.h.cmake mysql/config.h.cmake.orig

Use mysql/config.h.cmake.orig for creating mysql/my_config.h and
mysql/config.h.in, defining/undefining macros introduced with #cmakedefine.

Most of the macro values in mysql/my_config.h can be determined at the
preprocessing time using the pre-defined macros. To obtain the pre-defined
macros for gcc and clang run:

$ gcc -dM -E - < /dev/null
$ clang -dM -E - < /dev/null

Some macro values can not be easily determined at the preprocessing time. We
define them based on the supported platform tests and add mysql/assert.c,
containing compile-time assertions for the macros in question.

mysql/config.h.in defines macros that depend on the version and build2
configuration variables.

Note that if it is uneasy to define a macro, you may check if you really need
to, grepping for its usages, for example:

grep -e CPU_LEVEL1_DCACHE_LINESIZE `find -L . -name '*.c*' -o -name '*.h*'`

And it may become obvious that the macro is not used in libmysqlclient and
mysql-client.

Re-creating mysql/my_config.h from scratch every time we upgrade to a new
upstream version would be a real pain. Instead we can only (un)define the
newly introduced macros, comparing the already defined and currently used
macro sets:

$ for m in `cat mysql/{config,binlog_config}.h.cmake.orig | \
            sed -n 's/.*#\s*\(define\|cmakedefine\)\s\{1,\}\([_a-zA-Z0-9]\{1,\}\)\(\s.*\)\{0,1\}$/\2/p' | sort -u`; do
    if grep -q -e "\b$m\b" `find -L . ../mysql-client -name '*.h' -a ! -name my_config.h -a ! -name config.h -o -name '*.c' -o -name '*.cc' -a ! -name mysqld.cc -o -name '*.cpp' -o -name '*.hpp'`; then
      echo "$m"
    fi
  done >used-macros

$ cat mysql/my_config.h mysql/config.h.in mysql/binlog_config.h |
  sed -n 's/#\s*\(define\|undef\)\s\{1,\}\([_a-zA-Z0-9]\{1,\}\)\(\s.*\)\{0,1\}$/\2/p' |
  sort -u >defined-macros

$ diff defined-macros used-macros >diff-macros

Create mysql/libmysql_exports.def, containing the exported names list. For
that purpose grep through libmysql/CMakeLists.txt to see how the .def file is
generated for Windows. The corresponding code normally looks like:

MERGE_LIBRARIES_SHARED(libmysql ${LIBS_TO_MERGE}
  EXPORTS ${CLIENT_API_FUNCTIONS} ${CLIENT_API_FUNCTIONS_UNDOCUMENTED}
  COMPONENT SharedLibraries)

If that's the case, collect names that get assigned to the
CLIENT_API_FUNCTIONS and CLIENT_API_FUNCTIONS_UNDOCUMENTED variables.

Extract the auto-generated mysqld_error.h from Fedora's community-mysql-devel
package and copy it into mysql/:

$ wget https://rpmfind.net/linux/fedora/linux/development/rawhide/Everything/aarch64/os/Packages/c/community-mysql-devel-8.0.15-1.fc30.aarch64.rpm
$ rpm2cpio community-mysql-devel-8.0.15-1.fc30.aarch64.rpm | cpio -idv ./usr/include/mysql/mysqld_error.h

Deducing the source file set and compilation/linking options can probably be
performed by analyzing the root and component-specific CMakeLists.txt files
(see libmysql/, etc) and .cmake files under the upstream's cmake/
subdirectory. In practice, however, you may also need to refer to
cmake-generated flags.make files or, as a last resort, to see the actual
compiler and linker command lines in the build log (see ../README-DEV for
details).