# Description: link with libatomic_ops on platforms that need it
# Author: Damyan Ivanov <dmn@debian.org>
--- a/configure.in
+++ b/configure.in
@@ -211,6 +211,7 @@ dnl CPU_TYPE=ppc64
     SHRLIB_EXT=so
     STD_EDITLINE=true
     STD_ICU=true
+    ATOMIC_LIBS=-latomic_ops
     ;;
 
   sparc*-*-linux* | sparc*-*-gnu* | sparc*-*-k*bsd*-gnu)
@@ -220,6 +221,7 @@ dnl CPU_TYPE=ppc64
     AC_DEFINE(LINUX, 1, [Define this if OS is Linux])
     EDITLINE_FLG=Y
     SHRLIB_EXT=so
+    ATOMIC_LIBS=-latomic_ops
     ;;
 
   powerpc*-*-linux*)
@@ -257,6 +259,7 @@ dnl CPU_TYPE=ppc64
     LOCK_MANAGER_FLG=Y
     EDITLINE_FLG=Y
     SHRLIB_EXT=so
+    ATOMIC_LIBS=-latomic_ops
     ;;
 
 
@@ -269,6 +272,7 @@ dnl CPU_TYPE=ppc64
     LOCK_MANAGER_FLG=Y
     EDITLINE_FLG=Y
     SHRLIB_EXT=so
+    ATOMIC_LIBS=-latomic_ops
     ;;
 
   hppa*-*-linux*)
@@ -423,6 +427,7 @@ AC_SUBST(SHRLIB_EXT)
 AC_SUBST(ICU_PLATFORM)
 AC_DEFINE(CASE_SENSITIVITY, false, [Define this if paths are case sensitive])
 AC_SUBST(RPM64)
+AC_SUBST(ATOMIC_LIBS)
 
 
 dnl Some controllable options
--- a/builds/posix/Makefile.in.client.util
+++ b/builds/posix/Makefile.in.client.util
@@ -174,13 +174,13 @@ $(FBSVCMGR):	$(FBSVCMGR_Objects) $(LIBFB
 fbtracemgr: $(FBTRACEMGR)
 
 $(FBTRACEMGR):	$(FBTRACEMGR_Objects) $(LIBFBCLIENT_SO)
-	$(EXE_LINK) $(LINK_EMPTY_SYMBOLS) $(LINK_OPTS) $^ -o $@ -L$(LIB)
+	$(EXE_LINK) $(LINK_EMPTY_SYMBOLS) $(LINK_OPTS) $^ -o $@ -L$(LIB) $(ATOMIC_LIBS)
 
 
 fbguard: $(LIBFBCLIENT_SO) $(FBGUARD)
 
 $(FBGUARD):	$(FBGUARD_Objects) $(FBCOMMON_Objects) $(FBCLASSES_Objects)
-	$(EXE_LINK) $(LINK_EMPTY_SYMBOLS) $(LINK_OPTS) $^ -o $@ -L$(LIB) -lfbclient $(LIB_GUI)
+	$(EXE_LINK) $(LINK_EMPTY_SYMBOLS) $(LINK_OPTS) $^ -o $@ -L$(LIB) -lfbclient $(LIB_GUI) $(ATOMIC_LIBS)
 
 
 ibguard: $(LIBFBCLIENT_SO) $(IBGUARD)
--- a/builds/posix/Makefile.in.embed.util
+++ b/builds/posix/Makefile.in.embed.util
@@ -169,7 +169,7 @@ $(FBSVCMGR):	$(FBSVCMGR_Objects) $(LIBFB
 fbtracemgr: $(FBTRACEMGR)
 
 $(FBTRACEMGR):	$(FBTRACEMGR_Objects) $(LIBFBEMBED_SO)
-	$(EXE_LINK) $(LINK_EMPTY_SYMBOLS) $(LINK_OPTS) $^ -o $@ $(FBEMBED_LINK)
+	$(EXE_LINK) $(LINK_EMPTY_SYMBOLS) $(LINK_OPTS) $^ -o $@ $(FBEMBED_LINK) $(ATOMIC_LIBS)
 
 
 gds_relay: $(GDS_RELAY)
@@ -187,7 +187,7 @@ $(GSEC):	$(GSEC_Objects) $(CLUMPLETS_Obj
 fbguard: $(LIBFBCLIENT_SO) $(FBGUARD)
 
 $(FBGUARD):	$(FBGUARD_Objects) $(FBCOMMON_Objects) $(FBCLASSES_Objects)
-	$(EXE_LINK) $(LINK_EMPTY_SYMBOLS) $(LINK_OPTS) $^ -o $@ -L$(LIB) -lfbclient $(LIB_GUI)
+	$(EXE_LINK) $(LINK_EMPTY_SYMBOLS) $(LINK_OPTS) $^ -o $@ -L$(LIB) -lfbclient $(LIB_GUI) $(ATOMIC_LIBS)
 
 
 ibmgr_bin: $(IBMGR_BIN)
--- a/builds/posix/Makefile.in.inet_server
+++ b/builds/posix/Makefile.in.inet_server
@@ -52,7 +52,7 @@ Dependencies = $(AllObjects:.o=.d)
 fb_inet_server : $(LIBFBEMBED_SO) $(FB_CLASSIC_SERVER)
 
 $(FB_CLASSIC_SERVER):	$(SERVER_Objects)
-	$(EXE_LINK) $(LINK_EMPTY_SYMBOLS) $(LINK_OPTS) $^ -o $@ $(FBEMBED_LINK) $(LIB_GUI)
+	$(EXE_LINK) $(LINK_EMPTY_SYMBOLS) $(LINK_OPTS) $^ -o $@ $(FBEMBED_LINK) $(LIB_GUI) $(ATOMIC_LIBS)
 
 include $(ROOT)/gen/make.shared.targets
 
--- a/builds/posix/make.defaults
+++ b/builds/posix/make.defaults
@@ -151,7 +151,8 @@ CLIENTLIB_LINK:= @CC@ $(GLOB_OPTIONS) $(
 EXE_LINK:= @CXX@ $(GLOB_OPTIONS) $(CXXFLAGS) $(THR_FLAGS)
 STATICEXE_LINK:= @CXX@ $(GLOB_OPTIONS) $(CXXFLAGS) $(THR_FLAGS)
 
-LINK_LIBS = @LIBS@
+ATOMIC_LIBS = @ATOMIC_LIBS@
+LINK_LIBS = @LIBS@ $(ATOMIC_LIBS)
 ICU_LIBS = -licuuc
 STATICLINK_LIBS = @LIBS@
 SO_LINK_LIBS = @LIBS@
@@ -294,11 +295,11 @@ LINK_TRACE_LIBS = -L$(LIB) $(SO_LINK_LIB
 
 LINK_CLIENT = $(CLIENTLIB_LINK) $(LINK_FIREBIRD_CLIENT_SYMBOLS) $(LIB_LINK_OPTIONS)\
  $(LIB_LINK_IMPLIB) $(call LIB_LINK_SONAME,$(ClientLibrarySoName)) $(call LIB_LINK_RPATH,lib) $(THR_LIBS) $(THR_FLAGS)
-LINK_CLIENT_LIBS = $(SO_LINK_LIBS) $(STATIC_CXXSUPPORT_LIB)
+LINK_CLIENT_LIBS = $(SO_LINK_LIBS) $(STATIC_CXXSUPPORT_LIB) $(ATOMIC_LIBS)
 
 LINK_EMBED = $(LIB_LINK) $(LINK_FIREBIRD_EMBED_SYMBOLS) $(LIB_LINK_OPTIONS) $(LIB_EMBED_LINK_OPTIONS)\
  $(call LIB_LINK_SONAME,$(SharedLibrarySoName)) $(call LIB_LINK_RPATH,lib) $(THR_LIBS) $(THR_FLAGS)
-LINK_EMBED_LIBS = -L$(LIB) $(LIB_GUI) $(SO_LINK_LIBS) $(ICU_LIBS)
+LINK_EMBED_LIBS = -L$(LIB) $(LIB_GUI) $(SO_LINK_LIBS) $(ICU_LIBS) $(ATOMIC_LIBS)
 
 # From utilities 
 CREATE_DB	= $(BIN)/create_db$(EXEC_EXT)
