Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidated PR#4387 & PR#4368: Refactor Makefiles, Build Targets and fixed TAP tests linking #4395

Merged
merged 53 commits into from
Dec 22, 2023
Merged
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
cfb7599
refactor makefiles
mirostauder Oct 24, 2023
9185c96
fix conditional debug messages
mirostauder Oct 24, 2023
6c15528
use inludes from our deps intead of system
mirostauder Oct 24, 2023
0b1b7f0
more refactoring and fixes
mirostauder Oct 25, 2023
f43b507
more refactoring and fixes
mirostauder Oct 26, 2023
8ade3a6
more makefile fixes
mirostauder Oct 27, 2023
01586df
add external test deps to the main repo
mirostauder Oct 30, 2023
b939609
fix mysql includes
mirostauder Oct 31, 2023
c619b2d
more makefile fixes
mirostauder Nov 2, 2023
c9b5e01
Removed static ssl libs from shared tap library
rahim-kanji Nov 22, 2023
2f96438
Added proxysql/deps/openssl library path
rahim-kanji Nov 22, 2023
e512fad
revert broken symlinks
mirostauder Nov 22, 2023
bb0f472
fix typos
mirostauder Nov 22, 2023
0a2c79f
fix symlink creation
mirostauder Nov 22, 2023
fef6eea
Added ssl libs in fwd_eof_ok_query test
rahim-kanji Nov 22, 2023
e3c1d9b
refactor makefiles
mirostauder Oct 24, 2023
c92a93b
fix conditional debug messages
mirostauder Oct 24, 2023
c78819b
use inludes from our deps intead of system
mirostauder Oct 24, 2023
8720d39
more refactoring and fixes
mirostauder Oct 25, 2023
2dbcfc8
more refactoring and fixes
mirostauder Oct 26, 2023
a849b13
more makefile fixes
mirostauder Oct 27, 2023
8b06449
add external test deps to the main repo
mirostauder Oct 30, 2023
803510f
fix mysql includes
mirostauder Oct 31, 2023
06facee
more makefile fixes
mirostauder Nov 2, 2023
42ad092
revert broken symlinks
mirostauder Nov 22, 2023
7c8db3f
fix typos
mirostauder Nov 22, 2023
30c8847
fix symlink creation
mirostauder Nov 22, 2023
4c6765c
Merge branch 'v2.6.0-more-makefile-fixes' of https://github.com/sysow…
mirostauder Nov 23, 2023
b71b1e9
also clean test/deps
mirostauder Nov 25, 2023
4d614cf
build mysql-client from mysql-boost-5.7.x source
mirostauder Nov 25, 2023
1bcca12
fix mysql-client RelWithDebInfo build args
mirostauder Nov 25, 2023
68e256c
fix paths and deps
mirostauder Nov 26, 2023
bddf376
Removed curl static library from libtap.so
rahim-kanji Nov 27, 2023
d8d12f3
Few fixes
rahim-kanji Nov 27, 2023
2bf41ce
Fixed linking issue
rahim-kanji Nov 27, 2023
f9946f9
fix concurent dependency build, more cleanups
mirostauder Nov 28, 2023
398eb15
Merge remote-tracking branch 'Master/v2.6.0-more-makefile-fixes' into…
rahim-kanji Dec 5, 2023
ffe6df3
Fixed build_deps_debug compiler flags
rahim-kanji Dec 6, 2023
38cbba2
Removed invalid argument
rahim-kanji Dec 6, 2023
d437768
Remove libmysqlclient.a on clean
rahim-kanji Dec 6, 2023
2304113
Fixed dependencies
rahim-kanji Dec 6, 2023
30d1cb7
Addressed library linking issue, ensuring TAP tests consistently util…
rahim-kanji Dec 6, 2023
a52a3c7
Fixed memory leaks
rahim-kanji Dec 6, 2023
520d90e
Fixed libraries linking
rahim-kanji Dec 7, 2023
3bb51ee
Added TAP tests release build support
rahim-kanji Dec 7, 2023
4af5dd2
Merge remote-tracking branch 'Master/v2.x' into v2.x_testing_ci_test_…
rahim-kanji Dec 7, 2023
08832f1
When C++17 is present, the build_*_default (formerly build_*_clickhou…
rahim-kanji Dec 7, 2023
b046f50
Fixed deprecate_eof_support tests library linking.
rahim-kanji Dec 7, 2023
7b0e18d
Removed MySQL_Protocol.h
rahim-kanji Dec 7, 2023
6cb8064
Merge remote-tracking branch 'Master/v2.x' into v2.x_unified_makefile…
rahim-kanji Dec 8, 2023
9fa6615
Removed duplicate header file
rahim-kanji Dec 8, 2023
282aae7
Merge remote-tracking branch 'Master/v2.x' into v2.x_unified_makefile…
rahim-kanji Dec 8, 2023
38e9bc5
removed extra line
rahim-kanji Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add external test deps to the main repo
mirostauder committed Oct 31, 2023
commit 01586df482d42423111300f8e3c0f36d16a52232
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -110,6 +110,10 @@ heaptrack.*
#vscode
.vscode/

# test deps
test/deps/mariadb-connector-c/mariadb-connector-c-*/
test/deps/mysql-connector-c/mysql-connector-c-*src/

#tap tests
test/tap/tap/cpp-dotenv/cpp-dotenv-*
test/tap/tap/cpp-dotenv/static/cpp-dotenv-*
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -297,6 +297,7 @@ clean:
cd lib && ${MAKE} clean
cd src && ${MAKE} clean
cd test/tap && ${MAKE} clean
rm -f pkgroot || true

.PHONY: cleanall
cleanall:
@@ -307,6 +308,7 @@ cleanall:
rm -f binaries/*deb || true
rm -f binaries/*rpm || true
rm -f binaries/*id-hash || true
rm -rf pkgroot || true

.PHONY: cleanbuild
cleanbuild:
48 changes: 48 additions & 0 deletions test/deps/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/make -f


targets := mariadb_client mysql_client

.PHONY: default
default: $(targets)


### test deps targets

mariadb-connector-c/mariadb-connector-c/libmariadb/libmariadbclient.a:
cd mariadb-connector-c && rm -rf mariadb-connector-c-*/ || true
cd mariadb-connector-c && tar -zxf mariadb-connector-c-*.tar.gz
cd mariadb-connector-c/mariadb-connector-c && patch -p0 < ../CMakeLists.txt.patch
cd mariadb-connector-c/mariadb-connector-c && patch -p0 < ../ConnectorName.cmake.patch
cd mariadb-connector-c/mariadb-connector-c && cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPENSSL_ROOT_DIR=$(DEPS_PATH)/libssl/openssl/
cd mariadb-connector-c/mariadb-connector-c && CC=${CC} CXX=${CXX} ${MAKE} mariadbclient

mariadb_client: mariadb-connector-c/mariadb-connector-c/libmariadb/libmariadbclient.a


mysql-connector-c/mysql-connector-c/libmysql/libmysqlclient.a:
cd mysql-connector-c && rm -rf mysql-connector-c-*-src/ || true
cd mysql-connector-c && tar -zxf mysql-connector-c-*-src.tar.gz
cd mysql-connector-c/mysql-connector-c && patch -p0 < ../CMakeLists.txt.patch
cd mysql-connector-c/mysql-connector-c && patch -p0 < ../install_macros.cmake.patch
cd mysql-connector-c/mysql-connector-c && cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPENSSL_ROOT_DIR=$(DEPS_PATH)/libssl/openssl
cd mysql-connector-c/mysql-connector-c && CC=${CC} CXX=${CXX} ${MAKE} mysqlclient

mysql_client: mysql-connector-c/mysql-connector-c/libmysql/libmysqlclient.a


### clean targets

.SILENT: cleanall
.PHONY: cleanall
cleanall:
cd mariadb-connector-c && rm -rf mariadb-connector-c-*/ || true
cd mysql-connector-c && rm -rf mysql-connector-c-*-src/ || true

.SILENT: clean
.PHONY: clean
clean:
cd mariadb-connector-c/mariadb-connector-c && $(MAKE) clean || true
cd mariadb-connector-c/mariadb-connector-c && rm -f CMakeCache.txt
cd mysql-connector-c/mysql-connector-c && $(MAKE) clean || true
cd mysql-connector-c/mysql-connector-c && rm -f CMakeCache.txt
13 changes: 13 additions & 0 deletions test/deps/mariadb-connector-c/CMakeLists.txt.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- ./CMakeLists.txt 2020-02-27 15:01:10.993225716 +0100
+++ ./CMakeLists.txt 2020-02-27 15:00:57.705257256 +0100
@@ -132,8 +132,8 @@
# Disable dbug information for release builds
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DDBUG_OFF")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DDBUG_OFF")
-SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")
-SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DDBUG_OFF")
+SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DDBUG_OFF -ggdb -O0")
+SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DDBUG_OFF -ggdb -O0")

IF(CMAKE_COMPILER_IS_GNUCC)
INCLUDE(CheckCCompilerFlag)
11 changes: 11 additions & 0 deletions test/deps/mariadb-connector-c/ConnectorName.cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- cmake/ConnectorName.cmake 2020-10-29 22:16:20.000000000 +0000
+++ cmake/ConnectorName.cmake 2022-11-06 08:31:22.615513943 +0000
@@ -22,7 +22,7 @@
SET(MACHINE_NAME "x64")
ELSE()
SET(MACHINE_NAME "32")
- END()
+ ENDIF()
ENDIF()

SET(product_name "mysql-connector-c-${CPACK_PACKAGE_VERSION}-${PLATFORM_NAME}${CONCAT_SIGN}${MACHINE_NAME}")
1 change: 1 addition & 0 deletions test/deps/mariadb-connector-c/mariadb-connector-c
Binary file not shown.
16 changes: 16 additions & 0 deletions test/deps/mysql-connector-c/CMakeLists.txt.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--- ./CMakeLists.txt 2017-07-13 06:55:32.000000000 +0000
+++ ./CMakeLists.txt 2023-10-30 15:24:21.614898571 +0000
@@ -262,11 +262,11 @@
SET(CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} ${SAN_OPT} -O1 -Wno-error -fPIC")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO
- "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${SAN_OPT} -fPIC")
+ "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${SAN_OPT} -O0 -ggdb -fPIC")
SET(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} ${SAN_OPT} -O1 -Wno-error -fPIC")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO
- "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SAN_OPT} -fPIC")
+ "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${SAN_OPT} -O0 -ggdb -fPIC")
SET(${RESULT} 1)
ELSE()
SET(${RESULT} 0)
13 changes: 13 additions & 0 deletions test/deps/mysql-connector-c/install_macros.cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--- cmake/install_macros.cmake 2017-07-13 06:55:32.000000000 +0000
+++ cmake/install_macros.cmake 2023-10-30 14:41:22.788965914 +0000
@@ -362,8 +362,8 @@
CONFIGURATIONS Release RelWithDebInfo
COMPONENT ${ARG_COMPONENT}
OPTIONAL)
- ENDIF()
- ENDFOREACH()
+ ENDFOREACH()
+ ENDIF()

ENDFUNCTION()

1 change: 1 addition & 0 deletions test/deps/mysql-connector-c/mysql-connector-c
Binary file not shown.
17 changes: 14 additions & 3 deletions test/tap/tap/Makefile
Original file line number Diff line number Diff line change
@@ -55,6 +55,8 @@ endif
OPT := $(STDCPP) -O2 -ggdb -Wl,--no-as-needed


### main targets

.PHONY: default
default: all

@@ -65,6 +67,8 @@ debug: OPT := $(STDCPP) -O0 -DDEBUG -ggdb -Wl,--no-as-needed $(WASAN)
debug: libtap.a libtap.so


### helper targets

command_line.o: command_line.cpp cpp-dotenv/static/cpp-dotenv/libcpp_dotenv.a libcurl.so libssl.so.3 libcrypto.so.3 libcpp_dotenv.so
g++ -fPIC -c command_line.cpp $(IDIRS) $(OPT)

@@ -80,6 +84,9 @@ libtap.a: tap.cpp tap.h command_line.cpp command_line.h utils.cpp utils.h tap.o
libtap.so: libtap.a cpp-dotenv/dynamic/cpp-dotenv/libcpp_dotenv.so
gcc -shared -o libtap.so -Wl,--whole-archive libtap.a ../../../deps/curl/curl/lib/.libs/libcurl.a ../../../deps/libssl/openssl/libcrypto.a ../../../deps/libssl/openssl/libssl.a -Wl,--no-whole-archive


### tap deps targets

libssl.so.3: $(DEPS_PATH)/libssl/openssl/libssl.so.3
cp -a $(DEPS_PATH)/libssl/openssl/libssl.so* .

@@ -109,8 +116,12 @@ cpp-dotenv/dynamic/cpp-dotenv/libcpp_dotenv.so:
cd cpp-dotenv/dynamic/cpp-dotenv && CC=${CC} CXX=${CXX} ${MAKE}


### clean targets

.SILENT: clean
.PHONY: clean
clean:
rm -f *.o libtap.a libtap.so || true
find cpp-dotenv/dynamic -name '*.o' -or -name '*.a' -delete || true
find cpp-dotenv/static -name '*.o' -or -name '*.a' -delete || true
find . -name '*.a' -delete || true
find . -name '*.o' -delete || true
find . -name '*.so' -delete || true
find . -name '*.so.*' -delete || true
36 changes: 25 additions & 11 deletions test/tap/tests/Makefile
Original file line number Diff line number Diff line change
@@ -82,11 +82,21 @@ TAP_PATH := ../tap
TAP_IDIR := ../tap
TAP_LDIR := ../tap

DOTENV_DYN_DIR := ../tap/cpp-dotenv/dynamic/cpp-dotenv
DOTENV_DYN_IDIR := $(DOTENV_DYN_DIR)/include
#DOTENV_DYN_LDIR := $(DOTENV_DYN_DIR)
DOTENV_DYN_PATH := $(TAP_LDIR)/cpp-dotenv/dynamic/cpp-dotenv
DOTENV_DYN_IDIR := $(DOTENV_DYN_PATH)/include
#DOTENV_DYN_LDIR := $(DOTENV_DYN_PATH)
DOTENV_DYN_LDIR := $(TAP_LDIR)

TEST_DEPS_PATH := $(PROXYSQL_PATH)/test/deps

TEST_MARIADB_PATH := $(TEST_DEPS_PATH)/mariadb-connector-c/mariadb-connector-c
TEST_MARIADB_IDIR := $(TEST_MARIADB_PATH)/include
TEST_MARIADB_LDIR := $(TEST_MARIADB_PATH)/libmariadb

TEST_MYSQL_PATH := $(TEST_DEPS_PATH)/mysql-connector-c/mysql-connector-c
TEST_MYSQL_IDIR := $(TEST_MYSQL_PATH)/include
TEST_MYSQL_LDIR := $(TEST_MYSQL_PATH)/libmysql

LIBPROXYSQLAR := $(PROXYSQL_LDIR)/libproxysql.a

ODIR := $(PROXYSQL_PATH)//obj
@@ -139,7 +149,7 @@ ifeq ($(WITHASAN),1)
WASAN := -fsanitize=address -DTEST_WITHASAN
endif

OPT := $(STDCPP) -O2 -ggdb -Wl,--no-as-needed $(WGCOV) -DGITVERSION=\"$(GIT_VERSION)\"
OPT := $(STDCPP) -O2 -ggdb -Wl,--no-as-needed -Wl,-rpath,$(TAP_LDIR) $(WGCOV) -DGITVERSION=\"$(GIT_VERSION)\"


### main targets
@@ -150,7 +160,7 @@ default: all
.PHONY: all
all: tests

debug: OPT := $(STDCPP) -O0 -DDEBUG -ggdb -Wl,--no-as-needed $(WGCOV) $(WASAN) -DGITVERSION=\"$(GIT_VERSION)\"
debug: OPT := $(STDCPP) -O0 -DDEBUG -ggdb -Wl,--no-as-needed -Wl,-rpath,$(TAP_LDIR) $(WGCOV) $(WASAN) -DGITVERSION=\"$(GIT_VERSION)\"
debug: tests

tests: tests-cpp tests-php tests-py \
@@ -242,22 +252,22 @@ reg_test_3504-change_user_libmariadb_helper: reg_test_3504-change_user_helper.cp
$(CXX) $< $(IDIRS) $(LDIRS) $(OPT) $(MYLIBS) $(STATIC_LIBS) -o $@

reg_test_3504-change_user_libmysql_helper: reg_test_3504-change_user_helper.cpp $(TAP_LDIR)/libtap.so
$(CXX) -DLIBMYSQL_HELPER $< -I/usr/include/mysql $(CUSTOMARGS) -lmysqlclient -o $@
$(CXX) -DLIBMYSQL_HELPER $< -I$(TEST_MYSQL_IDIR) -L$(TEST_MYSQL_LDIR) -lmysqlclient $(CUSTOMARGS) -o $@

test_clickhouse_server_libmysql-t: test_clickhouse_server-t.cpp $(TAP_LDIR)/libtap.so
$(CXX) -DLIBMYSQL_HELPER $< -I/usr/include/mysql $(CUSTOMARGS) -lmysqlclient -o $@
$(CXX) -DLIBMYSQL_HELPER $< -I$(TEST_MYSQL_IDIR) -L$(TEST_MYSQL_LDIR) -lmysqlclient $(CUSTOMARGS) -o $@

reg_test_stmt_resultset_err_no_rows_libmysql-t: reg_test_stmt_resultset_err_no_rows-t.cpp $(TAP_LDIR)/libtap.so
$(CXX) -DLIBMYSQL_HELPER $< -I/usr/include/mysql $(CUSTOMARGS) -lmysqlclient -o $@
$(CXX) -DLIBMYSQL_HELPER $< -I$(TEST_MYSQL_IDIR) -L$(TEST_MYSQL_LDIR) -lmysqlclient $(CUSTOMARGS) -o $@

reg_test_mariadb_stmt_store_result_libmysql-t: reg_test_mariadb_stmt_store_result-t.cpp $(TAP_LDIR)/libtap.so
$(CXX) -DLIBMYSQL_HELPER $< -I/usr/include/mysql $(CUSTOMARGS) -lmysqlclient -o $@
$(CXX) -DLIBMYSQL_HELPER $< -I$(TEST_MYSQL_IDIR) -L$(TEST_MYSQL_LDIR) -lmysqlclient $(CUSTOMARGS) -o $@

reg_test_mariadb_stmt_store_result_async-t: reg_test_mariadb_stmt_store_result-t.cpp $(TAP_LDIR)/libtap.so
$(CXX) -DASYNC_API $< $(IDIRS) $(LDIRS) $(OPT) $(MYLIBS) $(STATIC_LIBS) -o $@

prepare_statement_err3024_libmysql-t: prepare_statement_err3024-t.cpp $(TAP_LDIR)/libtap.so
$(CXX) -DLIBMYSQL_HELPER $< -I/usr/include/mysql $(CUSTOMARGS) -lmysqlclient -o $@
$(CXX) -DLIBMYSQL_HELPER $< -I$(TEST_MYSQL_IDIR) -L$(TEST_MYSQL_LDIR) -lmysqlclient $(CUSTOMARGS) -o $@

prepare_statement_err3024_async-t: prepare_statement_err3024-t.cpp $(TAP_LDIR)/libtap.so
$(CXX) -DASYNC_API $< $(IDIRS) $(LDIRS) $(OPT) $(MYLIBS) $(STATIC_LIBS) -o $@
@@ -268,6 +278,10 @@ test_wexecvp_syscall_failures-t: test_wexecvp_syscall_failures-t.cpp $(TAP_LDIR)

### clean targets

.SILENT: clean
.PHONY: clean
clean:
rm -f *-t galera_1_timeout_count galera_2_timeout_no_count aurora generate_set_session_csv set_testing-240.csv clickhouse_php_conn-t reg_test_3992_fast_forward_malformed_packet-pymysql-t || true
rm -f *-t || true
rm -f galera_1_timeout_count galera_2_timeout_no_count aurora || true
rm -f generate_set_session_csv set_testing-240.csv || true
rm -f *.gcda *.gcno || true
128 changes: 58 additions & 70 deletions test/tap/tests_with_deps/deprecate_eof_support/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
#!/bin/make -f


TEST_DEPS_PATH ?= /var/lib/jenkins/scripts/test-scripts/deps

MARIADB_BASE_FOLDER := $(TEST_DEPS_PATH)/mariadb-client-library-3.1.9/
MARIADB_TEST_DEP := $(TEST_DEPS_PATH)/mariadb-client-library-3.1.9/mariadb-connector-c

BASE_DIR_EXIST := $(shell if [ -d $(MARIADB_BASE_FOLDER) ]; then echo 1; else echo 0; fi)
DEP_FOLDER_EMPTY := $(shell if [ -f $(MARIADB_TEST_DEP)/CMakeLists.txt ]; then echo 1; else echo 0; fi)


ifeq ($(BASE_DIR_EXIST),1)

ifeq ($(DEP_FOLDER_EMPTY),0)
$(error "Dependency folder '$(MARIADB_TEST_DEP)' is empty. Make sure folder is initialized.")
endif


GIT_VERSION ?= $(shell git describe --long --abbrev=7)
ifndef GIT_VERSION
$(error GIT_VERSION is not set)
@@ -36,6 +20,16 @@ TAP_PATH := ../../tap
TAP_IDIR := $(TAP_PATH)
TAP_LDIR := $(TAP_PATH)

TEST_DEPS_PATH := $(PROXYSQL_PATH)/test/deps

TEST_MARIADB_PATH := $(TEST_DEPS_PATH)/mariadb-connector-c/mariadb-connector-c
TEST_MARIADB_IDIR := $(TEST_MARIADB_PATH)/include
TEST_MARIADB_LDIR := $(TEST_MARIADB_PATH)/libmariadb

TEST_MYSQL_PATH := $(TEST_DEPS_PATH)/mysql-connector-c/mysql-connector-c
TEST_MYSQL_IDIR := $(TEST_MYSQL_PATH)/include
TEST_MYSQL_LDIR := $(TEST_MYSQL_PATH)/libmysql

### detect compiler support for c++11/17
CPLUSPLUS := $(shell ${CC} -std=c++17 -dM -E -x c++ /dev/null 2>/dev/null | grep -F __cplusplus | grep -Po '\d\d\d\d\d\dL')
ifneq ($(CPLUSPLUS),201703L)
@@ -56,7 +50,7 @@ ifeq ($(WITHASAN),1)
WASAN := -fsanitize=address
endif

OPT := $(STDCPP) -O2 -ggdb -Wl,--no-as-needed $(WGCOV)
OPT := $(STDCPP) -O2 -ggdb -Wl,--no-as-needed -Wl,-rpath,$(TAP_LDIR) $(WGCOV)

IDIRS := -I$(PROXYSQL_PATH)/include
IDIRS += -I$(DEPS_PATH)/sqlite3/sqlite3
@@ -69,91 +63,85 @@ IDIRS += -I$(DEPS_PATH)/libhttpserver/libhttpserver/src
IDIRS += -I$(DEPS_PATH)/libmicrohttpd/libmicrohttpd/src/include/
IDIRS += -I$(DEPS_PATH)/re2/re2
IDIRS += -I$(DEPS_PATH)/libev/libev
IDIRS += -I$(MARIADB_TEST_DEP)/include
IDIRS += -I$(DEPS_PATH)/curl/curl/include

TESTS_DEPS := $(TAP_LDIR)/libtap.so $(MARIADB_TEST_DEP)/libmariadb/libmariadbclient.a

### main targets

.PHONY: default
default: all

.PHONY: all
all: build_deps tests
all: build_test_deps tests

.PHONY: debug
debug: DEBUG := -DDEBUG
debug: OPT := $(STDCPP) -O0 -DDEBUG -ggdb -Wl,--no-as-needed $(WGCOV) $(WASAN)
debug: build_deps tests
debug: OPT := $(STDCPP) -O0 -DDEBUG -ggdb -Wl,--no-as-needed -Wl,-rpath,$(TAP_LDIR) $(WGCOV) $(WASAN)
debug: build_test_deps tests


$(MARIADB_TEST_DEP)/libmariadb/libmariadbclient.a:
cd $(MARIADB_BASE_FOLDER) && CC=${CC} CXX=${CXX} ${MAKE} mariadb_client
### test deps targets

.PHONY: build_deps
build_deps: $(TESTS_DEPS)
build_test_deps: $(TAP_LDIR)/libtap.so $(TEST_MARIADB_LDIR)/libmariadbclient.a $(TEST_MYSQL_LDIR)/libmysqlclient.a

$(TAP_LDIR)/libtap.so:
cd $(TAP_PATH) && CC=${CC} CXX=${CXX} ${MAKE}

tests: $(patsubst %.cpp,%,$(wildcard *-t.cpp)) fwd_eof_query fwd_eof_ok_query
$(TEST_MARIADB_LDIR)/libmariadbclient.a:
cd $(TEST_DEPS_PATH) && CC=${CC} CXX=${CXX} ${MAKE} mariadb_client

$(TEST_MYSQL_LDIR)/libmysqlclient.a:
cd $(TEST_DEPS_PATH) && CC=${CC} CXX=${CXX} ${MAKE} mysql_client

COMMONARGS := $(OPT) -I$(TAP_IDIR) -L$(TAP_LDIR) -ltap -lcpp_dotenv -Wl,--no-as-needed -lz -ldl -lpthread -DGITVERSION=\"$(GIT_VERSION)\"

ok_packet_mixed_queries-t: eof_packet_mixed_queries-t.cpp $(TESTS_DEPS)
$(CXX) $< $(IDIRS) $(COMMONARGS) -o $@
### test and helper targets

eof_packet_mixed_queries-t: eof_packet_mixed_queries-t.cpp $(TESTS_DEPS)
$(CXX) -DNON_EOF_SUPPORT $< $(IDIRS) -L$(MARIADB_TEST_DEP)/libmariadb -lmariadbclient $(COMMONARGS) -o $@
tests: $(patsubst %.cpp,%,$(wildcard *-t.cpp)) fwd_eof_query fwd_eof_ok_query

fwd_eof_query: fwd_eof_query.cpp $(TESTS_DEPS)
$(CXX) -DNON_EOF_SUPPORT $< $(IDIRS) -L$(MARIADB_TEST_DEP)/libmariadb -lmariadbclient $(COMMONARGS) -o $@
COMMONARGS := $(OPT) -I$(TAP_IDIR) -L$(TAP_LDIR) -ltap -lcpp_dotenv -lz -ldl -lpthread -DGITVERSION=\"$(GIT_VERSION)\"

# NOTE: Compilation with 'libmysql' instead of 'libmariadb' client to confirm packet sequence id isn't check by 'libmariadb'
fwd_eof_ok_query: fwd_eof_query.cpp $(TAP_LDIR)/libtap.so
$(CXX) $< $(IDIRS) -I$(MARIADB_IDIR) -I/usr/include/mysql/ -lmysqlclient -L/usr/lib/x86_64-linux-gnu/ $(COMMONARGS) -o $@
# NOTE end
ok_packet_mixed_queries-t: eof_packet_mixed_queries-t.cpp build_test_deps
$(CXX) $< $(IDIRS) -I$(TEST_MARIADB_IDIR) -L$(TEST_MARIADB_LDIR) -lmariadbclient $(COMMONARGS) -o $@

deprecate_eof_cache-t: deprecate_eof_cache-t.cpp $(TESTS_DEPS)
$(CXX) $< $(IDIRS) -L$(MARIADB_TEST_DEP)/libmariadb -lmariadbclient -L$(PROXYSQL_LDIR) -lproxysql $(COMMONARGS) -o $@
eof_packet_mixed_queries-t: eof_packet_mixed_queries-t.cpp build_test_deps
$(CXX) -DNON_EOF_SUPPORT $< $(IDIRS) -I$(TEST_MARIADB_IDIR) -L$(TEST_MARIADB_LDIR) -lmariadbclient $(COMMONARGS) -o $@

eof_cache_mixed_flags-t: eof_cache_mixed_flags-t.cpp $(TESTS_DEPS)
$(CXX) $< $(IDIRS) -L$(MARIADB_TEST_DEP)/libmariadb -lmariadbclient $(COMMONARGS) -o $@
fwd_eof_query: fwd_eof_query.cpp build_test_deps
$(CXX) -DNON_EOF_SUPPORT $< $(IDIRS) -I$(TEST_MARIADB_IDIR) -L$(TEST_MARIADB_LDIR) -lmariadbclient $(COMMONARGS) -o $@

eof_mixed_flags_queries-t: eof_mixed_flags_queries-t.cpp $(TESTS_DEPS)
$(CXX) $< $(IDIRS) -L$(MARIADB_TEST_DEP)/libmariadb -lmariadbclient $(COMMONARGS) -o $@
# NOTE: Compilation with 'libmysql' instead of 'libmariadb' client to confirm packet sequence id isn't check by 'libmariadb'
fwd_eof_ok_query: fwd_eof_query.cpp build_test_deps
$(CXX) $< $(IDIRS) -I$(MARIADB_IDIR) -I$(TEST_MYSQL_IDIR) -L$(TEST_MYSQL_LDIR) -lmysqlclient $(COMMONARGS) -o $@
# NOTE end

eof_conn_options_check-t: eof_conn_options_check-t.cpp $(TESTS_DEPS)
$(CXX) $< $(IDIRS) -L$(MARIADB_TEST_DEP)/libmariadb -lmariadbclient $(COMMONARGS) -o $@
deprecate_eof_cache-t: deprecate_eof_cache-t.cpp build_test_deps
$(CXX) $< $(IDIRS) -I$(TEST_MARIADB_IDIR) -L$(TEST_MARIADB_LDIR) -lmariadbclient -L$(PROXYSQL_LDIR) -lproxysql $(COMMONARGS) -o $@

eof_fast_forward-t: eof_fast_forward-t.cpp $(TESTS_DEPS)
$(CXX) $< $(IDIRS) -L$(MARIADB_TEST_DEP)/libmariadb -lmariadbclient $(COMMONARGS) -o $@
eof_cache_mixed_flags-t: eof_cache_mixed_flags-t.cpp build_test_deps
$(CXX) $< $(IDIRS) -I$(TEST_MARIADB_IDIR) -L$(TEST_MARIADB_LDIR) -lmariadbclient $(COMMONARGS) -o $@

eof_mixed_flags_queries-t: eof_mixed_flags_queries-t.cpp build_test_deps
$(CXX) $< $(IDIRS) -I$(TEST_MARIADB_IDIR) -L$(TEST_MARIADB_LDIR) -lmariadbclient $(COMMONARGS) -o $@

$(TAP_LIBDIR)/libtap.a:
cd ../../tap && CC=${CC} CXX=${CXX} ${MAKE}
eof_conn_options_check-t: eof_conn_options_check-t.cpp build_test_deps
$(CXX) $< $(IDIRS) -I$(TEST_MARIADB_IDIR) -L$(TEST_MARIADB_LDIR) -lmariadbclient $(COMMONARGS) -o $@

eof_fast_forward-t: eof_fast_forward-t.cpp build_test_deps
$(CXX) $< $(IDIRS) -I$(TEST_MARIADB_IDIR) -L$(TEST_MARIADB_LDIR) -lmariadbclient $(COMMONARGS) -o $@

.PHONY: clean
clean:
rm -f *-t
rm -f fwd_eof_query
rm -f fwd_eof_ok_query
rm -f *.a *.o
cd $(MARIADB_BASE_FOLDER) && ${MAKE} clean

### clean targets

else
.PHONY: all
all:
$(warning The required deps were not found. Tests 'deprecate_eof_support' wont be build)

.PHONY: debug
debug:
$(warning The required deps were not found. Tests 'deprecate_eof_support' wont be build)
.SILENT: cleanall
.PHONY: cleanall
cleanall: clean
cd $(TEST_DEPS_PATH) && ${MAKE} cleanall

.SILENT: clean
.PHONY: clean
clean:
rm -f *-t
rm -f fwd_eof_query
rm -f fwd_eof_ok_query
rm -f *.a *.o
endif
rm -f *-t || true
rm -f fwd_eof_query || true
rm -f fwd_eof_ok_query || true
rm -f *.a *.o || true
rm -f *.gcda *.gcno || true