From: Michael R. Crusoe <michael.crusoe@gmail.com>
Subject: Enable cross building
Forwarded: https://github.com/benedictpaten/sonLib/pull/41
Forwarded: https://github.com/yoheirosen/sublinear-Li-Stephens/pull/7
Forwarded: https://github.com/benedictpaten/sonLib/pull/42
Forwarded: https://github.com/vgteam/cpp_progress_bar/pull/2
Forwarded: https://github.com/vgteam/libvgio/pull/24
Forwarded: https://github.com/vgteam/gfakluge/pull/6
Forwarded: https://github.com/jltsiren/gbwtgraph/pull/8
Forwarded: https://github.com/vgteam/DYNAMIC/pull/3

--- a/source_me.sh
+++ b/source_me.sh
@@ -9,8 +9,8 @@ export LD_INCLUDE_PATH=`pwd`/include:$LD
 export CFLAGS="-I $(pwd)/include ${CFLAGS}"
 export CXXFLAGS="-I $(pwd)/include -I$(pwd)/include/dynamic ${CXXFLAGS}"
 export PATH=`pwd`/bin:`pwd`/scripts:$PATH
-export CC=$(which gcc)
-export CXX=$(which g++)
+export CC="${CC:=gcc}"
+export CXX="${CXX:=g++}"
 
 #
 #  disable until file arguments work as in normal bash :(
--- a/deps/sonLib/include.mk
+++ b/deps/sonLib/include.mk
@@ -3,6 +3,7 @@ HOSTNAME = $(shell hostname)
 MACH = $(shell uname -m)
 SYS =  $(shell uname -s)
 
+CC ?= gcc
 #C compiler. FIXME: for some reason the cxx variable is used, which
 #typically means C++ compiler.
 ifeq (${CC},cc)
@@ -13,7 +14,7 @@ ifeq (${CC},cc)
   else ifeq ($(SYS),Darwin) #This is to deal with the Mavericks replacing gcc with clang fully
 	cxx = clang -std=c99 
   else
-    cxx = gcc -std=c99
+    cxx = ${CC} -std=c99
   endif
 else
   cxx = ${CC} -std=c99
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,4 @@
+PKG_CONFIG ?= pkg-config
 DEP_DIR:=./deps
 SRC_DIR:=src
 ALGORITHMS_SRC_DIR:=$(SRC_DIR)/algorithms
@@ -32,14 +33,14 @@ include $(wildcard $(UNITTEST_OBJ_DIR)/*
 CXXFLAGS := -O3 -Werror=return-type -std=c++14 -ggdb -g -MMD -MP $(CXXFLAGS)
 
 # Set include flags. All -I options need to go in here, so the first directory listed is genuinely searched first.
-INCLUDE_FLAGS:=$(shell pkg-config --cflags libfastahack) -I$(CWD)/$(INC_DIR) -I. -I$(CWD)/$(SRC_DIR) -I$(CWD)/$(UNITTEST_SRC_DIR) -I$(CWD)/$(SUBCOMMAND_SRC_DIR) -I$(CWD)/$(INC_DIR)/dynamic $(shell pkg-config --cflags cairo jansson) $(shell pkg-config --cflags libsmithwaterman) $(shell pkg-config --cflags libvcflib)
+INCLUDE_FLAGS:=$(shell $(PKG_CONFIG) --cflags libfastahack) -I$(CWD)/$(INC_DIR) -I. -I$(CWD)/$(SRC_DIR) -I$(CWD)/$(UNITTEST_SRC_DIR) -I$(CWD)/$(SUBCOMMAND_SRC_DIR) -I$(CWD)/$(INC_DIR)/dynamic $(shell $(PKG_CONFIG) --cflags cairo jansson) $(shell $(PKG_CONFIG) --cflags libsmithwaterman) $(shell $(PKG_CONFIG) --cflags libvcflib)
 
 # Define libraries to link against. Make sure to always link statically against
 # htslib and libdeflate and Protobuf so that we can use position-dependent code
 # there for speed.
-LD_LIB_FLAGS:= -L$(CWD)/$(LIB_DIR) $(CWD)/$(LIB_DIR)/libvgio.a -lz -lgssw -lssw -lprotobuf -lsublinearLS -ldeflate -lpthread -ljansson -lncurses -lgcsa2 -lgbwtgraph -lgbwt -ldivsufsort -ldivsufsort64 -lraptor2 -lpinchesandcacti -l3edgeconnected -lsonlib -lfml -llz4 -lstructures -lvw -lboost_program_options -lallreduce -lbdsg -lxg -lsdsl -lhandlegraph $(shell pkg-config --libs libfastahack) $(shell pkg-config --libs libsmithwaterman) $(shell pkg-config --libs libvcflib) $(shell pkg-config --libs htslib) -ltabixpp
+LD_LIB_FLAGS:= -L$(CWD)/$(LIB_DIR) $(CWD)/$(LIB_DIR)/libvgio.a -lz -lgssw -lssw -lprotobuf -lsublinearLS -ldeflate -lpthread -ljansson -lncurses -lgcsa2 -lgbwtgraph -lgbwt -ldivsufsort -ldivsufsort64 -lraptor2 -lpinchesandcacti -l3edgeconnected -lsonlib -lfml -llz4 -lstructures -lvw -lboost_program_options -lallreduce -lbdsg -lxg -lsdsl -lhandlegraph $(shell $(PKG_CONFIG) --libs libfastahack) $(shell $(PKG_CONFIG) --libs libsmithwaterman) $(shell $(PKG_CONFIG) --libs libvcflib) $(shell $(PKG_CONFIG) --libs htslib) -ltabixpp
 # Use pkg-config to find Cairo and all the libs it uses
-LD_LIB_FLAGS += $(shell pkg-config --libs cairo jansson)
+LD_LIB_FLAGS += $(shell $(PKG_CONFIG) --libs cairo jansson)
 
 # Travis needs -latomic for all builds *but* GCC on Mac
 ifeq ($(strip $(shell $(CXX) -latomic /dev/null -o/dev/null 2>&1 | grep latomic | wc -l)), 0)
@@ -408,7 +409,7 @@ $(INC_DIR)/lru_cache.h: $(DEP_DIR)/lru_c
 $(INC_DIR)/dynamic/dynamic.hpp: $(DYNAMIC_DIR)/include/*.hpp $(DYNAMIC_DIR)/include/internal/*.hpp
 	rm -Rf $(INC_DIR)/dynamic.hpp $(INC_DIR)/dynamic
 	# annoyingly doesn't have an install option on the cmake, so we manually move their external dependency headers
-	cd $(CWD)/$(DYNAMIC_DIR) && rm -Rf build && mkdir -p build && cd build && export CXXFLAGS="$(CPPFLAGS) $(CXXFLAGS)" && cmake -DCMAKE_VERBOSE_MAKEFILE=ON .. && make
+	cd $(CWD)/$(DYNAMIC_DIR) && rm -Rf build && mkdir -p build && cd build && export CXXFLAGS="$(CPPFLAGS) $(CXXFLAGS)" && cmake -DCMAKE_VERBOSE_MAKEFILE=ON .. && $(MAKE)
 	# Do the copy of the main file last so we can tell if this recipe failed and redo it.
 	# Otherwise we get dynamic.hpp without its deps
 	mkdir -p $(INC_DIR)/dynamic && cp -r $(CWD)/$(DYNAMIC_DIR)/include/* $(INC_DIR)/dynamic
--- a/deps/progress_bar/makefile
+++ b/deps/progress_bar/makefile
@@ -1,4 +1,4 @@
-CC = g++
+CXX ?= g++
 CPPFLAGS += -std=c++11
 TARGET = progress_bar
 OBJ = main.o progress_bar.o
@@ -6,16 +6,13 @@ OBJ = main.o progress_bar.o
 all : progress_bar
 
 progress_bar : $(OBJ)
-	@echo "<***Linking***> $@"
-	@$(CC) $(CPPFLAGS) $(OBJ) -o $(TARGET)
+	$(CXX) $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(OBJ) -o $(TARGET) $(LOADLIBES) $(LDLIBS)
 
 main.o : main.cpp
-	@echo "<**Compiling**> $@"
-	@$(CC) $(CPPFLAGS) -c $^
+	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $^
 
 progress_bar.o : progress_bar.cpp
-	@echo "<**Compiling**> $@"
-	@$(CC) $(CPPFLAGS) -c $^
+	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $^
 
 clean :
 	@rm -rf progress_bar $(OBJ)
--- a/src/preflight.cpp
+++ b/src/preflight.cpp
@@ -1,32 +1,11 @@
 #include "preflight.hpp"
 
-#include <iostream>
-#include <cstdlib>
-#include <cpuid.h>
-
 namespace vg {
 
 using namespace std;
 
 void preflight_check() {
     
-    // We assume we are on x86_64 on POSIX (and not Windows).
-    // We use the method of dlib's dlib/simd/simd_check.h
-    
-    // Define a place to put the cpuid info
-    unsigned int cpuid_info[4];
-    
-    // Call cpuid function 1 (which reports SSE4.2, and other stuff up to original AVX)
-    __cpuid(1, cpuid_info[0], cpuid_info[1], cpuid_info[2], cpuid_info[3]);
-    
-    // Bit 20 of result 2 is the SSE 4.2 flag.
-    bool have_sse4_2 = cpuid_info[2] & (1 << 20);
-    
-    if (!have_sse4_2) {
-        cerr << "error[vg::preflight_check]: The CPU does not support SSE4.2 instructions. VG cannot run here. "
-            << "Please use a system with SSE4.2 support." << endl;
-        exit(1);
-    }
     
 }
 
--- a/src/preflight.hpp
+++ b/src/preflight.hpp
@@ -14,11 +14,7 @@ namespace vg {
 /// Define a macro to tell things to be built for every architecture, if possible.
 /// This *doesn't* work on Mac with GNU GCC and Apple libc++, because functions
 /// for x86-64 can't use std::endl, so we exclude that combination.
-#if (!defined(__GNUC__) || !defined(_LIBCPP_VERSION) || !defined(__APPLE__))
-    #define VG_PREFLIGHT_EVERYWHERE __attribute__((__target__("arch=x86-64")))
-#else
-    #define VG_PREFLIGHT_EVERYWHERE
-#endif
+#define VG_PREFLIGHT_EVERYWHERE
 
 /// Run a preflight check to make sure that the system is usable for this build of vg.
 /// Aborts with a helpful message if this is not the case.
--- a/src/crash.cpp
+++ b/src/crash.cpp
@@ -168,7 +168,7 @@ void emit_stacktrace(int signalNumber, s
         *out << "Caught signal " << signalNumber << " raised at address " << ip << endl;
         // Do our own tracing because backtrace doesn't really work on all platforms.
         stacktrace_manually(*out, signalNumber, ip, bp);
-    #else
+    #elif __x86_64__
         // Linux 64 bit does it this way
         ip = (void*)context->uc_mcontext.gregs[REG_RIP];
         bp = (void**)context->uc_mcontext.gregs[REG_RBP];
