--- Makefile.orig	2018-10-22 16:47:31 UTC
+++ Makefile
@@ -481,68 +481,65 @@ endif
 
 
 ifeq (${OSTYPE}, FreeBSD)
-ifeq (${MACHINETYPE}, amd64)
-  CC       ?= gcc48
-  CXX      ?= g++48
 
-  #  GCC
-  CXXFLAGS  += -I/usr/local/include -D_GLIBCXX_PARALLEL -pthread -fopenmp -fPIC
-  LDFLAGS   += -L/usr/local/lib     -D_GLIBCXX_PARALLEL -pthread -fopenmp -rpath /usr/local/lib/gcc48 -lm -lexecinfo
+  ifeq (${CANU_BUILD_ENV}, ports)
 
-  #  CLANG
-  #CXXFLAGS  += -I/usr/local/include -D_GLIBCXX_PARALLEL -pthread -fPIC
-  #LDFLAGS   += -L/usr/local/lib     -D_GLIBCXX_PARALLEL -pthread -lm -lexecinfo -lgomp
+    #################################################
+    # If compiling within ports system (recommended)
+    #################################################
 
-  #CXXFLAGS  += -Wall -Wextra -Wformat  -Wno-unused   -Wno-parentheses
-  CXXFLAGS  += -Wall -Wextra -Wformat -Wno-unused-function -Wno-unused-parameter -Wno-unused-variable -Wno-char-subscripts -Wno-write-strings -Wno-sign-compare -Wno-format-truncation
+    # Use architecture as defined by ports rather than uname
+    # ${ARCH} matches uname -p, not uname -m
+    MACHINETYPE=${ARCH}
 
-  #  Google Performance Tools malloc and heapchecker (HEAPCHECK=normal)
-  #CXXFLAGS  +=
-  #LDFLAGS   += -ltcmalloc
+    # Take compiler and most flags from the env and make command line
+    CXXFLAGS  += -D_GLIBCXX_PARALLEL -fPIC -pthread -fopenmp
+    LDFLAGS   += -D_GLIBCXX_PARALLEL -pthread -fopenmp
 
-  #  Google Performance Tools cpu profiler (CPUPROFILE=/path)
-  #CXXFLAGS  +=
-  #LDFLAGS   += -lprofiler
+  else
 
-  #  callgrind
-  #CXXFLAGS  += -g3 -Wa,--gstabs -save-temps
+    ######################################################
+    # If compiling outside ports system (not recommended)
+    ######################################################
 
-  ifeq ($(BUILDOPTIMIZED), 1)
-  else
-    CXXFLAGS += -g3
-  endif
+    CC       ?= gcc48
+    CXX      ?= g++48
 
-  ifeq ($(BUILDDEBUG), 1)
-  else
-    CXXFLAGS += -O3 -funroll-loops -fexpensive-optimizations -finline-functions -fomit-frame-pointer
-  endif
-endif
-endif
+    #  GCC
+    CXXFLAGS  += -I/usr/local/include -D_GLIBCXX_PARALLEL -pthread -fopenmp -fPIC
+    LDFLAGS   += -L/usr/local/lib     -D_GLIBCXX_PARALLEL -pthread -fopenmp -rpath /usr/local/lib/gcc48 -lm -lexecinfo
 
+    #  CLANG
+    #CXXFLAGS  += -I/usr/local/include -D_GLIBCXX_PARALLEL -pthread -fPIC
+    #LDFLAGS   += -L/usr/local/lib     -D_GLIBCXX_PARALLEL -pthread -lm -lexecinfo -lgomp
 
-ifeq (${OSTYPE}, FreeBSD)
-ifeq (${MACHINETYPE}, arm)
-  CC       ?= gcc48
-  CXX      ?= g++48
+    #CXXFLAGS  += -Wall -Wextra -Wformat  -Wno-unused   -Wno-parentheses
+    CXXFLAGS  += -Wall -Wextra -Wformat -Wno-unused-function -Wno-unused-parameter -Wno-unused-variable -Wno-char-subscripts -Wno-write-strings -Wno-sign-compare -Wno-format-truncation
 
-  CXXFLAGS  += -I/usr/local/include -D_GLIBCXX_PARALLEL -pthread -fopenmp -fPIC
-  LDFLAGS   += -L/usr/local/lib     -D_GLIBCXX_PARALLEL -pthread -fopenmp -rpath /usr/local/lib/gcc48 -lm
+    #  Google Performance Tools malloc and heapchecker (HEAPCHECK=normal)
+    #CXXFLAGS  +=
+    #LDFLAGS   += -ltcmalloc
 
-  CXXFLAGS  += -Wall -Wextra -Wno-write-strings -Wno-unused -Wno-char-subscripts -Wno-sign-compare -Wformat -Wno-parentheses
-  CXXFLAGS  += -funroll-loops -fomit-frame-pointer
-  LDFLAGS   += 
+    #  Google Performance Tools cpu profiler (CPUPROFILE=/path)
+    #CXXFLAGS  +=
+    #LDFLAGS   += -lprofiler
 
-  ifeq ($(BUILDOPTIMIZED), 1)
-  else
-    CXXFLAGS += -g3
-  endif
+    #  callgrind
+    #CXXFLAGS  += -g3 -Wa,--gstabs -save-temps
 
-  ifeq ($(BUILDDEBUG), 1)
-  else
-    CXXFLAGS += -O4 -funroll-loops -fexpensive-optimizations -finline-functions -fomit-frame-pointer
-  endif
-endif
-endif
+    ifeq ($(BUILDOPTIMIZED), 1)
+    else
+      CXXFLAGS += -g3
+    endif
+
+    ifeq ($(BUILDDEBUG), 1)
+    else
+      CXXFLAGS += -O3 -funroll-loops -fexpensive-optimizations -finline-functions -fomit-frame-pointer
+    endif
+
+  endif		# CANU_BUILD_ENV
+
+endif		# FreeBSD
 
 
 ifneq (,$(findstring CYGWIN, ${OSTYPE}))
