auto-configure linux/osx build differences
authorEvan Shelhamer <shelhamer@imaginarynumber.net>
Tue, 8 Apr 2014 22:41:29 +0000 (15:41 -0700)
committerEvan Shelhamer <shelhamer@imaginarynumber.net>
Tue, 8 Apr 2014 22:45:00 +0000 (15:45 -0700)
- set cxx as needed (clang++ on os x)
- set stdlib flag for os x 10.9 (CUDA libc++ workaround)
- link ATLAS properly for non-MKL installation whether linux or os x

Makefile
Makefile.config.example
docs/installation.md

index 71b19b0..26dcac5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -142,6 +142,33 @@ ALL_BUILD_DIRS := $(sort \
                $(PROTO_BUILD_DIR) $(PROTO_BUILD_INCLUDE_DIR) $(PY_PROTO_BUILD_DIR) \
                $(DISTRIBUTE_SUBDIRS))
 
+##############################
+# Configure build
+##############################
+
+# Determine platform
+UNAME := $(shell uname -s)
+ifeq ($(UNAME), Linux)
+       LINUX := 1
+else ifeq ($(UNAME), Darwin)
+       OSX := 1
+endif
+
+ifeq ($(LINUX), 1)
+       CXX := /usr/bin/g++
+endif
+
+# OS X:
+# clang++ instead of g++
+# libstdc++ instead of libc++ for CUDA compatibility on 10.9
+ifeq ($(OSX), 1)
+       CXX := /usr/bin/clang++
+       ifneq ($(findstring $(shell sw_vers -productVersion), 10.9),)
+               CXXFLAGS += -stdlib=libstdc++
+       endif
+endif
+
+# Debugging
 DEBUG ?= 0
 ifeq ($(DEBUG), 1)
        COMMON_FLAGS := -DDEBUG -g -O0
@@ -149,15 +176,22 @@ else
        COMMON_FLAGS := -DNDEBUG -O2
 endif
 
-# MKL switch (default = non-MKL)
+# MKL switch (default = non-MKL = ATLAS)
 USE_MKL ?= 0
 ifeq ($(USE_MKL), 1)
-  LIBRARIES += mkl_rt
-  COMMON_FLAGS += -DUSE_MKL
-  INCLUDE_DIRS += $(MKL_INCLUDE_DIR)
-  LIBRARY_DIRS += $(MKL_LIB_DIR)
+       LIBRARIES += mkl_rt
+       COMMON_FLAGS += -DUSE_MKL
+       INCLUDE_DIRS += $(MKL_INCLUDE_DIR)
+       LIBRARY_DIRS += $(MKL_LIB_DIR)
 else
-  LIBRARIES += cblas atlas
+       ifeq ($(LINUX), 1)
+               # Linux simply has cblas and atlas
+               LIBRARIES += cblas atlas
+       else ifeq ($(OSX), 1)
+               # OS X packages atlas as the vecLib framework
+               LIBRARIES += cblas
+               LDFLAGS += -framework vecLib
+       endif
 endif
 
 COMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
index 58881ec..6dba0d4 100644 (file)
@@ -10,7 +10,9 @@ CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
                -gencode arch=compute_30,code=sm_30 \
                -gencode arch=compute_35,code=sm_35
 
-# MKL switch: set to 1 for MKL
+# MKL switch:
+# 0 for ATLAS BLAS (default)
+# 1 for MKL BLAS
 USE_MKL := 0
 # MKL directory contains include/ and lib/ directions that we need.
 MKL_DIR := /opt/intel/mkl
@@ -23,22 +25,16 @@ MATLAB_DIR := /usr/local
 # NOTE: this is required only if you will compile the python interface.
 # We need to be able to find Python.h and numpy/arrayobject.h.
 PYTHON_INCLUDES := /usr/include/python2.7 \
-    /usr/local/lib/python2.7/dist-packages/numpy/core/include
+               /usr/local/lib/python2.7/dist-packages/numpy/core/include
 # Anaconda Python distribution is quite popular. Include path:
 # PYTHON_INCLUDES := $(HOME)/anaconda/include \
-    # $(HOME)/anaconda/include/python2.7 \
-    # $(HOME)/anaconda/lib/python2.7/site-packages/numpy/core/include
+               # $(HOME)/anaconda/include/python2.7 \
+               # $(HOME)/anaconda/lib/python2.7/site-packages/numpy/core/include
 
 # We need to be able to find libpythonX.X.so or .dylib.
 PYTHON_LIB := /usr/local/lib
 # PYTHON_LIB := $(HOME)/anaconda/lib
 
-CXX := /usr/bin/g++
-# For OS X, use clang++.
-# CXX := /usr/bin/clang++
-# For OS X 10.9, use libstdc++ instead of libc++ for CUDA compatibility.
-# CXXFLAGS := -stdlib=libstdc++
-
 # Whatever else you find you need goes here.
 INCLUDE_DIRS := $(PYTHON_INCLUDES) /usr/local/include
 LIBRARY_DIRS := $(PYTHON_LIB) /usr/lib /usr/local/lib
index b59b9a2..87b913e 100644 (file)
@@ -152,7 +152,6 @@ Here are the relevant parts of the Makefile.config after all this:
     MKL_DIR := /opt/intel/mkl  # only needed for MKL
     PYTHON_INCLUDES := /path/to/anaconda/include /path/to/anaconda/include/python2.7 /path/to/anaconda/lib/python2.7/site-packages/numpy/core/include
     PYTHON_LIB := /path/to/anaconda/lib
-    CXX=/usr/bin/clang++
 
 Don't forget to set `PATH` and `LD_LIBRARY_PATH`: