--- CMakeLists.txt.orig	2023-07-21 14:03:31 UTC
+++ CMakeLists.txt
@@ -310,14 +310,16 @@ endif()
 #  Grab pufferfish source --- DURING CONFIGURE TIME!
 #
 ####
-if(NOT FETCHED_PUFFERFISH)
+
+# Fetched by GH_TUPLE in FreeBSD port
+# if(NOT FETCHED_PUFFERFISH)
   exec_program(${CMAKE_CURRENT_SOURCE_DIR}/scripts/fetchPufferfish.sh RETURN_VALUE FETCH_PF_SCRIPT_RET)
   message(STATUS "fetch PUFFERFISH exit code ${FETCH_PF_SCRIPT_RET}")
   if(NOT (FETCH_PF_SCRIPT_RET EQUAL 0))
     message(FATAL_ERROR "Could not fetch pufferfish source [fetchPufferfish.sh returned exit code ${FETCH_PF_SCRIPT_RET}].")
   endif()
   set(FETCHED_PUFFERFISH TRUE CACHE BOOL "Has pufferfish been fetched?" FORCE)
-endif()
+# endif()
 
 ##
 # Super-secret override
@@ -364,7 +366,10 @@ if(NOT Iconv_IS_BUILT_IN)
   set(ICONV_LIB Iconv::Iconv)
 endif()
 
-find_package(LibLZMA)
+# lzma is in FreeBSD base
+# find_package(LibLZMA)
+set(LIBLZMA_FOUND TRUE)
+set(LIBLZMA_LIBRARIES /usr/lib/liblzma.a /usr/lib/libmd.a)
 if(NOT LIBLZMA_FOUND)
   message("Will attempt to fetch and build liblzma")
   message("=======================================")
@@ -381,8 +386,8 @@ externalproject_add(liblzma
   INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/install
   BUILD_IN_SOURCE TRUE
   CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/external/xz-5.2.2/configure --prefix=<INSTALL_DIR> CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} CFLAGS=${EXTRA_CMAKE_INCLUDE_FLAGS} CPPFLAGS=${EXTRA_CMAKE_INCLUDE_FLAGS} LDFLAGS=${EXTRA_CMAKE_LIBRARY_FLAGS}
-  BUILD_COMMAND make ${QUIET_MAKE}
-  INSTALL_COMMAND make ${QUIET_MAKE} install
+  BUILD_COMMAND gmake ${QUIET_MAKE}
+  INSTALL_COMMAND gmake ${QUIET_MAKE} install
 )
 
 # Tell cmake that the external project generated a library so we can
@@ -411,8 +416,8 @@ externalproject_add(libbz2
   INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/install
   BUILD_IN_SOURCE TRUE
   CONFIGURE_COMMAND ""
-  BUILD_COMMAND make ${QUIET_MAKE} CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER}
-  INSTALL_COMMAND make ${QUIET_MAKE} install PREFIX=<INSTALL_DIR>
+  BUILD_COMMAND gmake ${QUIET_MAKE} CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER}
+  INSTALL_COMMAND gmake ${QUIET_MAKE} install PREFIX=<INSTALL_DIR>
 )
 # Tell cmake that the external project generated a library so we can
 # add dependencies here instead of later
@@ -609,9 +614,11 @@ if (NOT CEREAL_FOUND)
 endif()
 
 ## Try and find TBB first
-find_package(TBB 2021.4
-  HINTS ${TBB_ROOT_SEARCH}
-  COMPONENTS tbb tbbmalloc tbbmalloc_proxy)
+# find_package(TBB 2021.4
+#   HINTS ${TBB_ROOT_SEARCH}
+#   COMPONENTS tbb tbbmalloc tbbmalloc_proxy)
+# tbbmalloc_proxy is rolled into tbbmalloc in FreeBSD ports
+find_package(TBB 2021.4 COMPONENTS tbb tbbmalloc)
 
 if (${TBB_FOUND})
   if (${TBB_VERSION} VERSION_GREATER_EQUAL 2021.4)
@@ -791,22 +798,16 @@ endif()
 if (NOT LIBSTADENIO_FOUND)
   message("Build system will compile Staden IOLib")
   message("==================================================================")
+  # stadenio is downloaded by GH_TUPLE in FreeBSD port
   externalproject_add(libstadenio
-    DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external
-    DOWNLOAD_COMMAND curl -k -L https://github.com/jkbonfield/io_lib/releases/download/io_lib-1-14-15/io_lib-1.14.15.tar.gz -o staden-io_lib-v1.14.15.tar.gz &&
-      ${SHASUM} 20814c4365e1e2fe6630fb11d0df370dec4c5688af3871de7f1cb0129671401e staden-io_lib-v1.14.15.tar.gz &&
-      mkdir -p staden-io_lib-1.14.15 &&
-      tar -xzf staden-io_lib-v1.14.15.tar.gz --strip-components=1 -C staden-io_lib-1.14.15 &&
-      rm -fr staden-io_lib &&
-      mv -f staden-io_lib-1.14.15 staden-io_lib
     SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/staden-io_lib
     INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/install
     CONFIGURE_COMMAND ./configure --enable-shared=no --without-libcurl --prefix=<INSTALL_DIR> LDFLAGS=${LIBSTADEN_LDFLAGS} CFLAGS=${LIBSTADEN_CFLAGS} CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER}
-    BUILD_COMMAND make ${QUIET_MAKE} CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} CFLAGS+=${STADEN_INC} CFLAGS+=${STADEN_LIB} LDFLAGS+=${EXTRA_CMAKE_LIBRARY_FLAGS} CFLAGS+=${EXTRA_CMAKE_INCLUDE_FLAGS} CFLAGS+=${LZFLAG} CFLAGS+=${SCHAR_FLAG}
+    BUILD_COMMAND gmake ${QUIET_MAKE} CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} CFLAGS+=${STADEN_INC} CFLAGS+=${STADEN_LIB} LDFLAGS+=${EXTRA_CMAKE_LIBRARY_FLAGS} CFLAGS+=${EXTRA_CMAKE_INCLUDE_FLAGS} CFLAGS+=${LZFLAG} CFLAGS+=${SCHAR_FLAG}
 
 
     BUILD_IN_SOURCE 1
-    INSTALL_COMMAND make install
+    INSTALL_COMMAND gmake install
   )
   if(NOT LIBLZMA_FOUND)
   	ExternalProject_Add_StepDependencies(libstadenio build liblzma)
@@ -820,23 +821,9 @@ if (ASAN_BUILD)
   set(FAST_MALLOC_LIB "")
   set(HAVE_FAST_MALLOC TRUE)
 else()
-  set(FAST_MALLOC_LIB "")
-  set(HAVE_FAST_MALLOC FALSE)
-
-  # See if we have Jemalloc
-  find_package(Jemalloc)
-  if(Jemalloc_FOUND)
-    ##
-    # Don't be so stringent about the version yet
-    ##
-    #if (NOT (${JEMALLOC_VERSION} VERSION_LESS 5.2.1))
-      message("Found Jemalloc library --- using this memory allocator")
-      set(FAST_MALLOC_LIB ${JEMALLOC_LIBRARIES})
-      set(HAVE_FAST_MALLOC TRUE)
-    #else()
-    #  message("Fond Jemalloc version ${JEMALLOC_VERSION}, but require >= 5.2.1. Downloading newer version")
-    #endif()
-  endif()
+  # jemalloc is default on FreeBSD
+  set(FAST_MALLOC_LIB "/usr/lib/libc.so")
+  set(HAVE_FAST_MALLOC TRUE)
 endif()
 
 if(CONDA_BUILD)
