From d94b8582e580f7c110b64705b79aa6ae3748f0d1 Mon Sep 17 00:00:00 2001
From: zhangxianting <zhangxianting@uniontech.com>
Date: Wed, 10 Apr 2024 14:37:17 +0800
Subject: [PATCH 1/2] hts instead of bam , because samtools upgrade, remove /usr/lib64/libbam.a
	copy ax_hts.m4, base ax_bam.m4

---
 ax_hts.m4                           | 203 ++++++++++++++++++++++++++++
 configure.ac                        |   6 +-
 cufflinks.xcodeproj/project.pbxproj |   2 +-
 make_bin.sh                         |   8 +-
 src/Makefile.am                     |  32 ++---
 5 files changed, 227 insertions(+), 24 deletions(-)
 create mode 100644 ax_hts.m4

diff --git a/ax_hts.m4 b/ax_hts.m4
new file mode 100644
index 0000000..b5f7e78
--- /dev/null
+++ b/ax_hts.m4
@@ -0,0 +1,203 @@
+# SYNOPSIS
+#
+#   AX_HTS
+#
+# DESCRIPTION
+#
+#   Test for the HTS libraries of a particular version (or newer)
+#
+#   If no path to the installed hts library is given the macro searchs
+#   under /usr, /usr/local, /opt and /opt/local and evaluates the
+#   $HTS_ROOT environment variable. 
+#	Adapted from AX_BOOST_BASE
+#
+#   This macro calls:
+#
+#     AC_SUBST(HTS_CPPFLAGS) / AC_SUBST(HTS_LDFLAGS)
+#
+#   And sets:
+#
+#     HAVE_HTS
+#
+# LICENSE
+#
+#   Copyright (c) 2010 Cole Trapnell <cole@cs.umd.edu>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved.
+
+AC_DEFUN([AX_HTS],
+[
+AC_ARG_WITH([hts],
+	AS_HELP_STRING([--with-hts@<:@=DIR@:>@], [use HTS libraries (default is yes) - it is possible to specify the root directory for HTS (optional)]),
+	[
+    if test "$withval" = "no"; then
+		want_hts="no"
+    elif test "$withval" = "yes"; then
+        want_hts="yes"
+        ac_hts_path=""
+    else
+	    want_hts="yes"
+        ac_hts_path="$withval"
+	fi
+    ],
+    [want_hts="yes"])
+
+
+AC_ARG_WITH([hts-libdir],
+        AS_HELP_STRING([--with-hts-libdir=LIB_DIR],
+        [Force given directory for hts libraries. Note that this will overwrite library path detection, so use this parameter only if default library detection fails and you know exactly where your hts libraries are located.]),
+        [
+        if test -d $withval
+        then
+                ac_hts_lib_path="$withval"
+        else
+                AC_MSG_ERROR(--with-hts-libdir expected directory name)
+        fi
+        ],
+        [ac_hts_lib_path=""]
+)
+
+if test "x$want_hts" = "xyes"; then
+#	hts_lib_version_req=ifelse([$1], ,1.20.0,$1)
+#	hts_lib_version_req_shorten=`expr $hts_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
+#	hts_lib_version_req_major=`expr $hts_lib_version_req : '\([[0-9]]*\)'`
+#	hts_lib_version_req_minor=`expr $hts_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
+#	hts_lib_version_req_sub_minor=`expr $hts_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+#	if test "x$hts_lib_version_req_sub_minor" = "x" ; then
+#		hts_lib_version_req_sub_minor="0"
+#    	fi
+#	WANT_HTS_VERSION=`expr $htslib_version_req_major \* 100000 \+  $hts_lib_version_req_minor \* 100 \+ $hts_lib_version_req_sub_minor`
+	AC_MSG_CHECKING(for htslib)
+	succeeded=no
+
+	dnl first we check the system location for hts libraries
+	if test "$ac_hts_path" != ""; then
+		HTS_LDFLAGS="-L$ac_hts_path/lib"
+		HTS_CPPFLAGS="-I$ac_hts_path/include"
+	else
+		for ac_hts_path_tmp in /usr /usr/local /opt /opt/local ; do
+			if test -d "$ac_hts_path_tmp/include/htslib" && test -r "$ac_hts_path_tmp/include/htslib"; then
+				HTS_LDFLAGS="-L$ac_hts_path_tmp/lib"
+				HTS_CPPFLAGS="-I$ac_hts_path_tmp/include"
+				break;
+			fi
+		done
+	fi
+
+    dnl overwrite ld flags if we have required special directory with
+    dnl --with-hts-libdir parameter
+    if test "$ac_hts_lib_path" != ""; then
+       HTS_LDFLAGS="-L$ac_hts_lib_path"
+    fi
+
+	CPPFLAGS_SAVED="$CPPFLAGS"
+	CPPFLAGS="$CPPFLAGS $HTS_CPPFLAGS"
+	export CPPFLAGS
+
+	LDFLAGS_SAVED="$LDFLAGS"
+	LDFLAGS="$LDFLAGS $HTS_LDFLAGS"
+	export LDFLAGS
+
+	AC_LANG_PUSH(C++)
+     	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+	@%:@include <htslib/hts.h>
+	]], [[
+	]])],[
+        AC_MSG_RESULT(yes)
+	succeeded=yes
+	found_system=yes
+       	],[
+       	])
+	AC_LANG_POP([C++])
+
+	dnl if we found no hts with system layout we search for hts libraries
+	dnl built and installed without the --layout=system option or for a staged(not installed) version
+	if test "x$succeeded" != "xyes"; then
+		_version=0
+		if test "$ac_hts_path" != ""; then
+			if test -d "$ac_hts_path" && test -r "$ac_hts_path"; then
+				for i in `ls -d $ac_hts_path/include/hts* 2>/dev/null`; do
+					_version_tmp=`echo $i | sed "s#$ac_hts_path##" | sed 's/\/include\/hts-//' | sed 's/_/./'`
+					V_CHECK=`expr $_version_tmp \> $_version`
+					if test "$V_CHECK" = "1" ; then
+						_version=$_version_tmp
+					fi
+					VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
+					HTS_CPPFLAGS="-I$ac_hts_path/include/hts-$VERSION_UNDERSCORE"
+				done
+			fi
+		else
+			for ac_hts_path in /usr /usr/local /opt /opt/local ; do
+				if test -d "$ac_hts_path" && test -r "$ac_hts_path"; then
+					for i in `ls -d $ac_hts_path/include/hts-* 2>/dev/null`; do
+						_version_tmp=`echo $i | sed "s#$ac_hts_path##" | sed 's/\/include\/hts-//' | sed 's/_/./'`
+						V_CHECK=`expr $_version_tmp \> $_version`
+						if test "$V_CHECK" = "1" ; then
+							_version=$_version_tmp
+	               					best_path=$ac_hts_path
+						fi
+					done
+				fi
+			done
+
+			VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
+			HTS_CPPFLAGS="-I$best_path/include/hts-$VERSION_UNDERSCORE"
+           if test "$ac_hts_lib_path" = ""
+            then
+               HTS_LDFLAGS="-L$best_path/lib"
+            fi
+
+	    		if test "x$HTS_ROOT" != "x"; then
+				if test -d "$HTS_ROOT" && test -r "$HTS_ROOT" && test -d "$HTS_ROOT/stage/lib" && test -r "$HTS_ROOT/stage/lib"; then
+					version_dir=`expr //$HTS_ROOT : '.*/\(.*\)'`
+					stage_version=`echo $version_dir | sed 's/hts_//' | sed 's/_/./g'`
+			        	stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
+					V_CHECK=`expr $stage_version_shorten \>\= $_version`
+                    if test "$V_CHECK" = "1" -a "$ac_hts_lib_path" = "" ; then
+						AC_MSG_NOTICE(We will use a staged hts library from $HTS_ROOT)
+						HTS_CPPFLAGS="-I$HTS_ROOT"
+						HTS_LDFLAGS="-L$HTS_ROOT/stage/lib"
+					fi
+				fi
+	    		fi
+		fi
+
+		CPPFLAGS="$CPPFLAGS $HTS_CPPFLAGS"
+		export CPPFLAGS
+		LDFLAGS="$LDFLAGS $HTS_LDFLAGS"
+		export LDFLAGS
+
+		AC_LANG_PUSH(C++)
+	     	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+		@%:@include <htslib/version.hpp>
+		]], [[
+		]])],[
+        	AC_MSG_RESULT(yes)
+		succeeded=yes
+		found_system=yes
+       		],[
+	       	])
+		AC_LANG_POP([C++])
+	fi
+
+	if test "$succeeded" != "yes" ; then
+		if test "$_version" = "0" ; then
+			AC_MSG_ERROR([[We could not detect the hts libraries (version $hts_lib_version_req_shorten or higher). If you have a staged hts library (still not installed) please specify \$HTS_ROOT in your environment and do not give a PATH to --with-hts option.  If you are sure you have hts installed, then check your version number looking in <htslib/version.hpp>. See http://randspringer.de/hts for more documentation.]])
+		else
+			AC_MSG_NOTICE([Your hts libraries seem too old (version $_version).])
+		fi
+	else
+		HTS_LIB="-lhts"
+		AC_SUBST(HTS_CPPFLAGS)
+		AC_SUBST(HTS_LDFLAGS)
+		AC_SUBST(HTS_LIB)
+		AC_DEFINE(HAVE_HTS,,[define if the HTS library is available])
+	fi
+
+        CPPFLAGS="$CPPFLAGS_SAVED"
+       	LDFLAGS="$LDFLAGS_SAVED"
+fi
+
+])
diff --git a/configure.ac b/configure.ac
index ce9936f..eba4f7a 100755
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ m4_include([ax_boost_base.m4])
 m4_include([ax_boost_thread.m4])
 m4_include([ax_boost_system.m4])
 m4_include([ax_boost_serialization.m4])
-m4_include([ax_bam.m4])
+m4_include([ax_hts.m4])
 m4_include([ax_check_zlib.m4])
 m4_include([ax_check_eigen.m4])
 
@@ -33,7 +33,7 @@ AC_PROG_INSTALL
 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
 AM_PATH_PYTHON([2.4])
 AX_BOOST_BASE([1.47.0])
-AX_BAM
+AX_HTS
 AX_BOOST_SYSTEM
 AX_BOOST_SERIALIZATION
 AX_BOOST_THREAD
@@ -105,7 +105,7 @@ AC_ARG_ENABLE(profiling,      [  --enable-profiling        enable profiling with
 	  
 CFLAGS="${generic_CFLAGS} ${ext_CFLAGS} ${user_CFLAGS} ${debug_CFLAGS} ${OPENMP_CFLAGS}"
 CXXFLAGS="$CFLAGS"
-CXXFLAGS="${CXXFLAGS} ${BOOST_CPPFLAGS} ${BAM_CPPFLAGS} ${EIGEN_CPPFLAGS}"
+CXXFLAGS="${CXXFLAGS} ${BOOST_CPPFLAGS} ${HTS_CPPFLAGS} ${EIGEN_CPPFLAGS}"
 user_LDFLAGS="$LDFLAGS"
 LDFLAGS="${ext_LDFLAGS} ${user_LDFLAGS}"
 
diff --git a/cufflinks.xcodeproj/project.pbxproj b/cufflinks.xcodeproj/project.pbxproj
index ea9dce7..f021377 100644
--- a/cufflinks.xcodeproj/project.pbxproj
+++ b/cufflinks.xcodeproj/project.pbxproj
@@ -748,7 +748,7 @@
 		A2047A17191141C7007193FC /* libbam.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libbam.a; path = ../../../../opt/local/libIntel64/libbam.a; sourceTree = "<group>"; };
 		ED1C0C7111D7D9E500CFD663 /* ax_boost_base.m4 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ax_boost_base.m4; sourceTree = "<group>"; };
 		ED1C0C7211D7D9E500CFD663 /* ax_boost_thread.m4 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ax_boost_thread.m4; sourceTree = "<group>"; };
-		ED1C0C7411D7DA3200CFD663 /* ax_bam.m4 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ax_bam.m4; sourceTree = "<group>"; };
+		ED1C0C7411D7DA3200CFD663 /* ax_hts.m4 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ax_hts.m4; sourceTree = "<group>"; };
 		ED1C0CAA11D7E52400CFD663 /* ax_check_zlib.m4 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ax_check_zlib.m4; sourceTree = "<group>"; };
 		ED1C0D7911D7F94900CFD663 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
 		ED41B838127602C60000B5A2 /* cufflinks_xcode */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = cufflinks_xcode; sourceTree = BUILT_PRODUCTS_DIR; };
diff --git a/make_bin.sh b/make_bin.sh
index 32c2e6e..f4d3aa5 100755
--- a/make_bin.sh
+++ b/make_bin.sh
@@ -2,11 +2,11 @@
 #simple script to pack up a precompiled binary package, with the boost thread
 # library statically linked in; on x86_64 Linux, libstc++ and libgcc are linked statically also
 if [[ -z "$2" ]]; then
- echo -e "Usage:\n./make_bin.sh <package_base_name> <boost_prefix> [<bam_prefix> [<Eigen_prefix>]]"
+ echo -e "Usage:\n./make_bin.sh <package_base_name> <boost_prefix> [<hts_prefix> [<Eigen_prefix>]]"
  exit 1
 fi
 
-echo "packing up $1.tar.gz, using boost in $2, linking against $3 and using BAM in $4, using Eigen in $5"
+echo "packing up $1.tar.gz, using boost in $2, linking against $3 and using HTS in $4, using Eigen in $5"
 mkdir $1
 #make clean
 make distclean
@@ -38,8 +38,8 @@ fi
 # fi
 
 
-#./configure --enable-intel64 --with-boost=$l2 --with-boost-thread=$l3 --with-bam=$l4 --with-eigen=$l5
-./configure --with-boost=$l2 --with-boost-thread=$l2/lib/libboost_thread.a --with-boost-system=$l2/lib/libboost_system.a --with-bam=$l3 --with-eigen=$l4 --with-boost-serialization=$l2/lib/libboost_serialization.a
+#./configure --enable-intel64 --with-boost=$l2 --with-boost-thread=$l3 --with-hts=$l4 --with-eigen=$l5
+./configure --with-boost=$l2 --with-boost-thread=$l2/lib/libboost_thread.a --with-boost-system=$l2/lib/libboost_system.a --with-hts=$l3 --with-eigen=$l4 --with-boost-serialization=$l2/lib/libboost_serialization.a
 make
 cp src/cufflinks $1
 cp src/cuffcompare $1
diff --git a/src/Makefile.am b/src/Makefile.am
index b46137d..a900f19 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -206,8 +206,8 @@ CLEANFILES = $(bin_SCRIPTS)
 #	(echo '#!$(PYTHON)'; sed '/^#!/d' $<) > $@
 
 cufflinks_SOURCES = cufflinks.cpp  
-cufflinks_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB)  $(BOOST_SERIALIZATION_LIB)  $(BAM_LIB) 
-cufflinks_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(BAM_LDFLAGS) #$(ZLIB_LDFLAGS) 
+cufflinks_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB)  $(BOOST_SERIALIZATION_LIB)  $(HTS_LIB) 
+cufflinks_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(HTS_LDFLAGS) #$(ZLIB_LDFLAGS) 
 
 cuffcompare_SOURCES = cuffcompare.cpp
 cuffcompare_LDADD = libgc.a
@@ -216,30 +216,30 @@ gffread_SOURCES = gffread.cpp
 gffread_LDADD = libgc.a
 
 cuffdiff_SOURCES = cuffdiff.cpp
-cuffdiff_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(BAM_LIB)
-cuffdiff_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(BAM_LDFLAGS) 
+cuffdiff_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(HTS_LIB)
+cuffdiff_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(HTS_LDFLAGS) 
 
 cuffquant_SOURCES = cuffquant.cpp
-cuffquant_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(BAM_LIB)
-cuffquant_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(BAM_LDFLAGS) 
+cuffquant_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(HTS_LIB)
+cuffquant_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(HTS_LDFLAGS) 
 
 cuffnorm_SOURCES = cuffnorm.cpp
-cuffnorm_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(BAM_LIB)
-cuffnorm_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(BAM_LDFLAGS)
+cuffnorm_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(HTS_LIB)
+cuffnorm_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(HTS_LDFLAGS)
 
 
 gtf_to_sam_SOURCES = gtf_to_sam.cpp
-gtf_to_sam_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(BAM_LIB)
-gtf_to_sam_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(BAM_LDFLAGS) 
+gtf_to_sam_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(HTS_LIB)
+gtf_to_sam_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(HTS_LDFLAGS) 
 
 #cuffcluster_SOURCES = cuffcluster.cpp
-#cuffcluster_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(BAM_LIB)
-#cuffcluster_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(BAM_LDFLAGS) 
+#cuffcluster_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(HTS_LIB)
+#cuffcluster_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(HTS_LDFLAGS) 
 
 compress_gtf_SOURCES = compress_gtf.cpp
-compress_gtf_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(BAM_LIB)
-compress_gtf_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(BAM_LDFLAGS) 
+compress_gtf_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(HTS_LIB)
+compress_gtf_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(HTS_LDFLAGS) 
 
 #gtf_reads_SOURCES = gtf_reads.cpp
-#gtf_reads_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(BAM_LIB) 
-#gtf_reads_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(BAM_LDFLAGS) #$(ZLIB_LDFLAGS)
+#gtf_reads_LDADD = libcufflinks.a libgc.a $(BOOST_THREAD_LIB) $(BOOST_SYSTEM_LIB) $(BOOST_SERIALIZATION_LIB) $(HTS_LIB) 
+#gtf_reads_LDFLAGS =  $(LDFLAGS) $(BOOST_LDFLAGS) $(HTS_LDFLAGS) #$(ZLIB_LDFLAGS)
-- 
2.33.0

