From: Michael R. Crusoe <michael.crusoe@gmail.com>
Subject: Enable cross building
--- vg.orig/source_me.sh
+++ vg/source_me.sh
@@ -9,8 +9,8 @@
 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 :(
--- vg.orig/deps/sonLib/include.mk
+++ vg/deps/sonLib/include.mk
@@ -3,6 +3,7 @@
 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 @@
   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
--- vg.orig/Makefile
+++ vg/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 @@
 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 -I$(CWD)/$(INC_DIR)/sonLib $(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 -I$(CWD)/$(INC_DIR)/sonLib $(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
-# Use pkg-config to find Cairo and all the libs it uses
-LD_LIB_FLAGS += $(shell pkg-config --libs cairo jansson)
+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)
 
 # 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)/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
--- vg.orig/deps/progress_bar/makefile
+++ vg/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 @@
 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)
--- vg.orig/src/preflight.cpp
+++ vg/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);
-    }
     
 }
 
--- vg.orig/src/preflight.hpp
+++ vg/src/preflight.hpp
@@ -14,11 +14,7 @@
 /// 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.
--- vg.orig/src/crash.cpp
+++ vg/src/crash.cpp
@@ -168,7 +168,7 @@
         *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];
--- vg.orig/deps/dozeu/dozeu.h
+++ vg/deps/dozeu/dozeu.h
@@ -115,15 +115,7 @@
 #define dz_ut_sel(a, b, c)			( (DZ_UNITTEST_INDEX == 0) ? (a) : ((DZ_UNITTEST_INDEX == 1) ? (b) : (c)) )
 
 /* vectorize */
-#ifndef __x86_64__
-#  error "x86_64 is required"
-#endif
-#ifndef __SSE4_1__
-#  warning "SSE4.1 is automatically enabled in dozeu.h, please check compatibility to the system."
-#  define __dz_vectorize			__attribute__(( target( "sse4.1" ) ))
-#else
-#  define __dz_vectorize			/* follow the compiler options */
-#endif
+#define __dz_vectorize			/* follow the compiler options */
 
 /* inlining (FIXME: add appropriate __force_inline flag) */
 #define __dz_force_inline			inline
@@ -142,11 +134,7 @@
 #define dz_loadu_u64(p)				({ uint8_t const *_p = (uint8_t const *)(p); *((uint64_t const *)_p); })
 #define dz_storeu_u64(p, e)			{ uint8_t *_p = (uint8_t *)(p); *((uint64_t *)(_p)) = (e); }
 
-#ifdef __SSE4_1__
-#  define dz_is_all_zero(x)			( simde_mm_test_all_zeros((x), (x)) == 1 )
-#else
-#  define dz_is_all_zero(x)			( simde_mm_movemask_epi8((x)) == 0 )
-#endif
+#define dz_is_all_zero(x)			( simde_mm_test_all_zeros((x), (x)) == 1 )
 
 #define DZ_MEM_MARGIN_SIZE			( 256 )
 #define DZ_MEM_ALIGN_SIZE			( 16 )
