From b8d104359aa83006e14129ca614a00eb9ca54d5d Mon Sep 17 00:00:00 2001 From: Raed Rizqie Date: Sat, 16 Nov 2024 02:45:59 +0800 Subject: [PATCH] Add MinGW support Add support for MinGW --- acx_pthread.m4 | 3 + builds/posix/Makefile.in | 42 ++++++--- builds/posix/Makefile.in.examples | 5 +- .../posix/Makefile.in.extauth | 18 +++- builds/posix/Makefile.in.plugins_examples | 22 +++-- builds/posix/make.defaults | 12 +-- builds/posix/make.rules | 4 +- builds/posix/make.shared.targets | 38 ++++++-- builds/posix/make.shared.variables | 25 ++++++ builds/posix/prefix.mingw | 87 +++++++++++++------ configure.ac | 13 ++- src/misc/writeBuildNum.sh | 6 +- 12 files changed, 210 insertions(+), 65 deletions(-) rename examples/extauth/Makefile => builds/posix/Makefile.in.extauth (86%) diff --git a/acx_pthread.m4 b/acx_pthread.m4 index bedf51c32af..8b7271fbf19 100644 --- a/acx_pthread.m4 +++ b/acx_pthread.m4 @@ -74,6 +74,9 @@ case "${host_cpu}-${host_os}" in acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags" ;; + *mingw*) + acx_pthread_flags="none" + ;; esac if test x"$acx_pthread_ok" = xno; then diff --git a/builds/posix/Makefile.in b/builds/posix/Makefile.in index d2871b3dca2..8fd479d238e 100644 --- a/builds/posix/Makefile.in +++ b/builds/posix/Makefile.in @@ -315,7 +315,7 @@ $(RE2_LIB): $(RE2_Objs) libcds: mkdir -p $(LIBCDS)/lib/$(TARGET) cd $(LIBCDS)/lib/$(TARGET); \ - cmake -DCMAKE_BUILD_TYPE=$(FB_CMAKE_BUILD_TYPE) -DCMAKE_CXX_COMPILER="$(CXX)" -DCMAKE_CXX_FLAGS=-fPIC $(LIBCDS) + cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=$(FB_CMAKE_BUILD_TYPE) -DCMAKE_CXX_COMPILER="$(CXX)" -DCMAKE_CXX_FLAGS=-fPIC $(LIBCDS) AR="$(AR)" $(MAKE) -C $(LIBCDS)/lib/$(TARGET) ifeq ($(TARGET),Debug) @@ -551,10 +551,15 @@ $(LIBIBUTIL_SO): $(UTIL_Objects) utilities: firebird_server fb_lock_print fbguard fbsvcmgr fbtracemgr gbak gfix gsec gsplit gstat isql nbackup udfsupport +ifeq ($(PLATFORM),win32) +.PHONY: instreg instsvc instclient +utilities +: instreg instsvc instclient +endif + firebird_server: $(FB_DAEMON) $(FB_DAEMON): $(Remote_Server_Objects) $(COMMON_LIB) - $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS) + $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ $(FIREBIRD_LIBRARY_LINK) $(LIB_GUI) $(LINK_LIBS) fb_lock_print: $(LOCKPRINT) @@ -564,7 +569,7 @@ $(LOCKPRINT): $(LOCKPRINT_Objects) $(COMMON_LIB) fbguard: $(FBGUARD) $(FBGUARD): $(FBGUARD_Objects) $(COMMON_LIB) - $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS) + $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ $(FIREBIRD_LIBRARY_LINK) $(LIB_GUI) $(LINK_LIBS) fbsvcmgr: $(FBSVCMGR) @@ -614,6 +619,21 @@ nbackup: $(NBACKUP) $(NBACKUP): $(NBACKUP_Objects) $(COMMON_LIB) $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS) +instreg: $(INSTREG) + +$(INSTREG): $(INSTREG_Objects) $(COMMON_LIB) + $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS) + +instsvc: $(INSTSVC) + +$(INSTSVC): $(INSTSVC_Objects) $(COMMON_LIB) + $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS) + +instclient: $(INSTCLIENT) + +$(INSTCLIENT): $(INSTCLIENT_Objects) $(COMMON_LIB) + $(EXE_LINK) $(EXE_LINK_OPTIONS) $^ -o $@ $(FIREBIRD_LIBRARY_LINK) $(LINK_LIBS) + #___________________________________________________________________________ # plugins - some of them are required to build examples, use separate entry for them @@ -636,6 +656,8 @@ ifeq ($(TARGET),Debug) BUILD_DEBUG:=auth_debug endif +PLUGIN_SONAME=$(notdir $@).0 + plugins: udr legacy_user_management legacy_auth_server srp_user_management trace $(BUILD_DEBUG) udf_compat chacha profiler udr: $(UDR_PLUGIN) $(PLUGINS)/udr_engine.conf @@ -644,31 +666,31 @@ $(PLUGINS)/udr_engine.conf: $(ROOT)/src/plugins/udr_engine/udr_engine.conf cp $^ $@ $(UDR_PLUGIN): $(UDRENG_Objects) $(COMMON_LIB) - $(LINK_UDRENG) $(call LIB_LINK_SONAME,$(notdir $@).0) -o $@ $^ $(LINK_UDRENG_LIBS) $(FIREBIRD_LIBRARY_LINK)\ + $(LINK_UDRENG) $(call LIB_LINK_SONAME,$(PLUGIN_SONAME)) -o $@ $^ $(LINK_UDRENG_LIBS) $(FIREBIRD_LIBRARY_LINK)\ $(call LIB_LINK_DARWIN_INSTALL_NAME,plugins/libudr_engine.$(SHRLIB_EXT)) legacy_user_management: $(LEGACY_USER_MANAGER) $(LEGACY_USER_MANAGER): $(LEGACY_USERS_MANAGE_Objects) $(COMMON_LIB) - $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(notdir $@).0) -o $@ $^ $(LINK_PLUG_LIBS) $(RE2LIB) $(FIREBIRD_LIBRARY_LINK)\ + $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(PLUGIN_SONAME)) -o $@ $^ $(LINK_PLUG_LIBS) $(RE2LIB) $(FIREBIRD_LIBRARY_LINK)\ $(call LIB_LINK_DARWIN_INSTALL_NAME,plugins/libLegacy_UserManager.$(SHRLIB_EXT)) chacha: $(CHACHA) $(CHACHA): $(Chacha_Objects) $(COMMON_LIB) - $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(notdir $@).0) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK)\ + $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(PLUGIN_SONAME)) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK)\ $(call LIB_LINK_DARWIN_INSTALL_NAME,plugins/libChaCha.$(SHRLIB_EXT)) legacy_auth_server: $(LEGACY_AUTH_SERVER) $(LEGACY_AUTH_SERVER): $(LEGACY_AUTH_SERVER_Objects) $(COMMON_LIB) - $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(notdir $@).0) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK)\ + $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(PLUGIN_SONAME)) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK)\ $(call LIB_LINK_DARWIN_INSTALL_NAME,plugins/libLegacy_Auth.$(SHRLIB_EXT)) profiler: $(PROFILER) $(PROFILER): $(Profiler_Objects) $(COMMON_LIB) - $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(notdir $@).0) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK)\ + $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(PLUGIN_SONAME)) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK)\ $(call LIB_LINK_DARWIN_INSTALL_NAME,plugins/libDefault_Profiler.$(SHRLIB_EXT)) trace: $(FBTRACE) @@ -679,13 +701,13 @@ $(FBTRACE): $(FBTRACE_UTIL_Objects) $(COMMON_LIB) auth_debug: $(AUTH_DEBUGGER) $(AUTH_DEBUGGER): $(AUTH_DEBUGGER_Objects) $(COMMON_LIB) - $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(notdir $@).0) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK)\ + $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(PLUGIN_SONAME)) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK)\ $(call LIB_LINK_DARWIN_INSTALL_NAME,plugins/libAuth_Debug.$(SHRLIB_EXT)) srp_user_management: $(SRP_USER_MANAGER) $(SRP_USER_MANAGER): $(SRP_USERS_MANAGE_Objects) $(COMMON_LIB) - $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(notdir $@).0) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK)\ + $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(PLUGIN_SONAME)) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK)\ $(call LIB_LINK_DARWIN_INSTALL_NAME,plugins/libSrp.$(SHRLIB_EXT)) udf_compat: $(UDF_BACKWARD_COMPATIBILITY) $(COMPAT_SQL) diff --git a/builds/posix/Makefile.in.examples b/builds/posix/Makefile.in.examples index d0f89738301..86a9cf256b6 100644 --- a/builds/posix/Makefile.in.examples +++ b/builds/posix/Makefile.in.examples @@ -67,8 +67,11 @@ export PATH #endif GPRE_FLAGS= -m -z -n +ifneq ($(PLATFORM),win32) +LIB_PREFIX = lib LIB_LINK_RPATH = $(call LIB_PLATFORM_RPATH,$(if $(subst intl,,$(1)),$(LIB),$(LIB)/../intl)) LINK_DARWIN_RPATH = -Wl,-rpath,@loader_path/../$(TARGET)/firebird +endif LIB_LINK_MAPFILE = EXAMPLES_DEST= $(GEN_ROOT)/examples @@ -91,7 +94,7 @@ EMPLOYEE_DB= $(EXAMPLES_DEST)/employee.fdb FINAL_EMPDB= $(EXAMPLES_FB)/empbuild/employee.fdb INTLEMP_DB= $(EXAMPLES_DEST)/intlemp.fdb -EXTAUTH_PLUGIN= $(EXAMPLES_FB)/prebuilt/libfbSampleExtAuth.$(SHRLIB_EXT) +EXTAUTH_PLUGIN= $(EXAMPLES_FB)/prebuilt/$(LIB_PREFIX)fbSampleExtAuth.$(SHRLIB_EXT) .PHONY: all examples diff --git a/examples/extauth/Makefile b/builds/posix/Makefile.in.extauth similarity index 86% rename from examples/extauth/Makefile rename to builds/posix/Makefile.in.extauth index 9da7bbd357f..933ef28c10a 100644 --- a/examples/extauth/Makefile +++ b/builds/posix/Makefile.in.extauth @@ -28,7 +28,9 @@ BIN=$(ROOT)/bin LIB=$(ROOT)/lib LIB_PREFIX=lib -SHRLIB_EXT=so +SHRLIB_EXT=@SHRLIB_EXT@ +EXEC_EXT=@EXEEXT@ +PLATFORM=@PLATFORM@ ifndef INTERMED INTERMED=. @@ -42,7 +44,12 @@ else OUT_PLUG=. endif +ifeq ($(PLATFORM),win32) +LIB_PREFIX= +TOMCRYPT_COMPILE=-DUSE_LTM -DLTM_DESC +else TOMCRYPT_COMPILE=-DLTC_PTHREAD -DUSE_LTM -DLTM_DESC +endif OwnInclude=$(shell [ -d tomcrypt.include ] && echo Yes || echo No) ifeq ($(OwnInclude), Yes) TOMCRYPT_COMPILE += -Itomcrypt.include @@ -53,7 +60,7 @@ SIMPLE_KEY_AUTH_NAME=$(LIB_PREFIX)fbSampleExtAuth.$(SHRLIB_EXT) BLD_SIMPLE_KEY_AUTH=$(OUT_PLUG)/$(SIMPLE_KEY_AUTH_NAME) SIMPLE_KEY_AUTH=$(PLUGINS)/$(SIMPLE_KEY_AUTH_NAME) -KEYGEN_NAME=fbSampleExtAuthKeygen +KEYGEN_NAME=fbSampleExtAuthKeygen$(EXEC_EXT) BLD_KEYGEN=$(OUT_BIN)/$(KEYGEN_NAME) KEYGEN=$(BIN)/$(KEYGEN_NAME) @@ -61,8 +68,13 @@ KEYGEN_objects=$(INTERMED)/keygen.o TCWRAP_objects=$(INTERMED)/TcWrapper.o KEY_AUTH_objects=$(INTERMED)/ExtAuth.o -CXXFLAGS=-std=c++11 -pthread -I$(ROOT)/include -fPIC $(TOMCRYPT_COMPILE) +ifeq ($(PLATFORM),win32) +CXXFLAGS=-std=c++17 -I$(ROOT)/include $(TOMCRYPT_COMPILE) +LDFLAGS=-L$(LIB) +else +CXXFLAGS=-std=c++17 -pthread -I$(ROOT)/include -fPIC $(TOMCRYPT_COMPILE) LDFLAGS=-pthread -L$(LIB) -Wl,-rpath,'$$ORIGIN/../lib' $(TOMCRYPT_LINK) +endif LINK_LIBS=-lfbclient -ltomcrypt -ltommath diff --git a/builds/posix/Makefile.in.plugins_examples b/builds/posix/Makefile.in.plugins_examples index 641c5104884..1a95e4a27f7 100644 --- a/builds/posix/Makefile.in.plugins_examples +++ b/builds/posix/Makefile.in.plugins_examples @@ -60,6 +60,16 @@ include $(ROOT)/gen/make.shared.variables all: udrcpp_example dc_example kh_example crypt_app +ifeq ($(PLATFORM),win32) +PLUGIN_SONAME=$(notdir $@) +PLUGINS_DIR=$(FIREBIRD)/examples/prebuilt/plugins +SAMPLES_DIR=$(FIREBIRD)/examples/prebuilt/bin +makePluginName=$(PLUGINS_DIR)/$(1).$(SHRLIB_EXT) +else +PLUGIN_SONAME=$(notdir $@).0 +PLUGINS_DIR=$(PLUGINS) +SAMPLES_DIR=$(BIN) +endif UDR_Objects = $(call dirObjects,../examples/udr) UDR_Plugin = $(PLUGINS)/udr/$(LIB_PREFIX)udrcpp_example.$(SHRLIB_EXT) @@ -72,7 +82,7 @@ ifeq ($(PLATFORM),DARWIN) $(LIB_LINK) $(LIB_BUNDLE_OPTIONS) -o $@ $^ @PTHREAD_CFLAGS@ @PTHREAD_LIBS@ \ $(FIREBIRD_LIBRARY_LINK) else - $(LIB_LINK) $(LIB_LINK_OPTIONS) $(LIB_LINK_SONAME)udrcpp_example.$(SHRLIB_EXT) \ + $(LIB_LINK) $(LIB_LINK_OPTIONS) $(call LIB_LINK_SONAME,udrcpp_example.$(SHRLIB_EXT)) \ $(LIB_PATH_OPTS) -o $@ $^ $(THR_LIBS) \ $(FIREBIRD_LIBRARY_LINK) endif @@ -85,8 +95,8 @@ AllObjects += $(DC_Objects) dc_example: $(DC_Plugin) $(DC_Plugin): $(DC_Objects) - $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(notdir $@).0) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK) - $(CP) $(EXA_ROOT)/dbcrypt/fbSampleDbCrypt.conf $(PLUGINS) + $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(PLUGIN_SONAME)) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK) + $(CP) $(EXA_ROOT)/dbcrypt/fbSampleDbCrypt.conf $(PLUGINS_DIR) KH_Objects = $(call makeObjects,../examples/dbcrypt,CryptKeyHolder.cpp) @@ -96,12 +106,12 @@ AllObjects += $(KH_Objects) kh_example: $(KH_Plugin) $(KH_Plugin): $(KH_Objects) - $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(notdir $@).0) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK) - $(CP) $(EXA_ROOT)/dbcrypt/fbSampleKeyHolder.conf $(PLUGINS) + $(LINK_PLUGIN) $(call LIB_LINK_SONAME,$(PLUGIN_SONAME)) -o $@ $^ $(LINK_PLUG_LIBS) $(FIREBIRD_LIBRARY_LINK) + $(CP) $(EXA_ROOT)/dbcrypt/fbSampleKeyHolder.conf $(PLUGINS_DIR) CA_Objects = $(call makeObjects,../examples/dbcrypt,CryptApplication.cpp) -CRYPT_APP = $(BIN)/fbSampleDbCryptApp$(EXEC_EXT) +CRYPT_APP = $(SAMPLES_DIR)/fbSampleDbCryptApp$(EXEC_EXT) AllObjects += $(CA_Objects) crypt_app: $(CRYPT_APP) diff --git a/builds/posix/make.defaults b/builds/posix/make.defaults index 3c28683f6f8..e472d624cbb 100755 --- a/builds/posix/make.defaults +++ b/builds/posix/make.defaults @@ -172,7 +172,7 @@ INLINE_EDIT_SED:= -i SH= sh -c RM= rm -f -RM_R= rm -rf +RM_R= rm -rf CHMOD= chmod CHMOD_6= chmod 666 CHMOD_7= chmod 777 @@ -196,6 +196,7 @@ CXX = @CXX@ LD = @CXX@ OBJCOPY = @OBJCOPY@ READELF = @READELF@ +WINDRES = @WINDRES@ AC_CFLAGS = @CFLAGS@ AC_CXXFLAGS = @CXXFLAGS@ @@ -215,7 +216,7 @@ SO_LINK_LIBS = @LIBS@ $(DECLIB) $(I128LIB) ARCH_EXT= .a EXEC_EXT= @EXEEXT@ -SHRLIB_EXT=@SHRLIB_EXT@ +SHRLIB_EXT= @SHRLIB_EXT@ LIB_PREFIX= lib SHRLIB_FOREIGN_EXT= $(SHRLIB_EXT) @@ -233,7 +234,7 @@ include $(ROOT)/gen/Make.Version vpath %.so $(LIB) vpath %.a $(LIB) -vpath %.dll $(LIB) +vpath %.dll $(BIN) #_____________________________________________________________________________ @@ -357,7 +358,7 @@ endif LIB_PATH_OPTS = $(call LIB_LINK_RPATH,lib) $(call LIB_LINK_RPATH,intl) LIB_LINK_SONAME= -Wl,-soname,$(1) LIB_LINK_MAPFILE= -Wl,--version-script,$(1) -FIREBIRD_LIBRARY_LINK= -L$(LIB) -L$(STATIC_LIB) -lfbclient $(MATHLIB) $(CRYPTLIB) +FIREBIRD_LIBRARY_LINK= -L$(LIB) -L$(STATIC_LIB) -lfbclient $(CRYPTLIB) $(MATHLIB) EXE_LINK_OPTIONS= $(LDFLAGS) $(THR_FLAGS) $(UNDEF_FLAGS) $(LIB_PATH_OPTS) $(call LINK_DARWIN_RPATH,..) $(LINK_EMPTY_SYMBOLS) LIB_LINK_OPTIONS= $(LDFLAGS) $(THR_FLAGS) -shared @@ -383,7 +384,7 @@ LINK_TRACE_LIBS = -L$(LIB) -L$(STATIC_LIB) $(SO_LINK_LIBS) LINK_FIREBIRD = $(LIB_LINK) $(LINK_FIREBIRD_SYMBOLS) $(LIB_LINK_OPTIONS) $(LIB_FIREBIRD_OPTIONS) $(UNDEF_FLAGS)\ $(call LIB_LINK_SONAME,$(LibrarySoName)) $(call LIB_LINK_RPATH,lib) $(call LINK_DARWIN_RPATH,..) -LINK_FIREBIRD_LIBS = -L$(LIB) -L$(STATIC_LIB) $(LIB_GUI) $(SO_LINK_LIBS) $(MATHLIB) +LINK_FIREBIRD_LIBS = -L$(LIB) -L$(STATIC_LIB) $(LIB_GUI) $(SO_LINK_LIBS) $(CRYPTLIB) $(MATHLIB) LINK_ENGINE = $(LIB_LINK) $(LINK_PLUGIN_SYMBOLS) $(LIB_LINK_OPTIONS) $(LIB_FIREBIRD_OPTIONS) $(UNDEF_FLAGS)\ $(call LIB_LINK_SONAME,$(EngineSoName)) $(call LIB_LINK_RPATH,lib) $(call LINK_DARWIN_RPATH,..) @@ -414,6 +415,7 @@ RUN_GFIX = $(RBIN)/gfix$(EXEC_EXT) FBGUARD = $(BIN)/fbguard$(EXEC_EXT) INSTREG = $(BIN)/instreg$(EXEC_EXT) INSTSVC = $(BIN)/instsvc$(EXEC_EXT) +INSTCLIENT = $(BIN)/instclient$(EXEC_EXT) SECURITY_FDB = $(FIREBIRD)/security6.fdb diff --git a/builds/posix/make.rules b/builds/posix/make.rules index 3bbd2580fea..82c150249bb 100644 --- a/builds/posix/make.rules +++ b/builds/posix/make.rules @@ -147,8 +147,8 @@ $(OBJ)/%.o: $(ROOT)/%.cpp # Rules for making resource files -$(GEN_ROOT)/%.res: $(SRC_ROOT)/%.rc - windres --output-format=coff --include-dir=$($Mini cat >$TestCpp < typedef unsigned short USHORT; +#ifdef __MINGW32__ +#include "miniods.h" +#else #include "$Mini" +#endif int main() { return ODS_VERSION; } eof -[ -z "$CXX" ] && CXX=g++ +[ -z "$CXX" ] && CXX=g++ && CXX=c++ $CXX -std=c++17 $TestCpp -o $AOut if [ -x $AOut ]