Attachment 'makefile.txt'

Download

   1 SHELL:=/bin/sh
   2 
   3 define help_text
   4 # All subdirs will be created under the sudirectory  where this makefile lives, i.e.,
   5 # ./freesurfer ./packages ./install
   6 #
   7 # ----- build from scratch starting with these steps ----
   8 #
   9 # $$ make nuke          <--- remove subdirs ./freesurfer ./packages ./install (the source/build, install trees)
  10 #                            - you will have to re-check out the annex if you run nuke
  11 #
  12 # $$ make fsco          <--- checkout the freesurfer source tree here under ./freesurfer
  13 # $$ make pkg_download  <--- get 3rd party packages and place here under ./packages
  14 # $$ make annexco       <--- annex checkout of data files. While not required to compile freesurfer, the install pass
  15 #                           "make install" will fail w/o some annex files. Beware that annexco takes a while.  
  16 #
  17 # ----- incrementaly update source and build with steps below -----
  18 #
  19 # $$ make fsupdate      <--- tell git to update the ./freesurfer source tree only if no merge is required
  20 #
  21 # $$ make config_print  <--- print the cmake command to see the configured options before generating makefiles
  22 #        config        <--- generate all makefiles with options configured below, CentOS 6,7, Ubuntu 16,18, MacOS
  23 #        config_min    <--- generate makefiles for a minimal build, i.e., freeview and many mri* commands are not built
  24 #
  25 # $$ make clean         <--- run the clean target in the cmake generated Makefiles
  26 #
  27 # $$ make build         <--- run parellel build with -j8 under ./freesurfer (using cmake generated makefiles)
  28 #        build_s       <--- run serial build with -j1 (useful for debugging if errors harder to see in parallel make output)
  29 #        build_k       <--- run parallel build with -j8 and -k to continue if errors encountered (useful for debugging)
  30 #        build_s_k     <--- run serial build with -j1 and -k
  31 #
  32 # $$ make run_freeview  <--- if the freeview binary was built, try to run it and load a volume file
  33 #
  34 # $$ make install       <--- run the install pass creating distribution under ./install
  35 #        install_s     <--- same as _s above for build target
  36 #        install_k     <--- same as _k above for build target
  37 #        install_s_k   <--- same as _k_s above for build target
  38 #
  39 # $$ make test          <--- run some individual command tests - requires a python rev 3 in PATH, e.g., anaconda python
  40 #
  41 #                       *** For more complete testing run a recon-all command, e.g., on subject bert data
  42 endef
  43 
  44 this_makefile:=$(firstword $(MAKEFILE_LIST))
  45 this_makefile_abspath:=$(abspath $(dir $(firstword $(MAKEFILE_LIST))))
  46 TOPDIR:=$(this_makefile_abspath)
  47 PKGS_URL:=http://surfer.nmr.mgh.harvard.edu/pub/data/fspackages/prebuilt
  48 
  49 # darwin or linux
  50 os:=$(shell uname -s | tr -s '[A-Z]' '[a-z]')
  51 os_type:=$(shell uname -v | tr -s '[A-Z]' '[a-z]')
  52 
  53 # LINUX
  54 ifeq ($(os),linux)
  55    # linux: Ubuntu or CentOS
  56    os_rhel:=none
  57    os_rhel_release:= none
  58    os_ubuntu_release:=none
  59    ifneq (,$(wildcard /etc/redhat-release))
  60       # CentOS version
  61       os_rhel:=$(shell cat /etc/redhat-release)
  62       os_rhel_release:=$(shell cat /etc/redhat-release | sed 's;^.*release ;;' | awk '{print $$1}' | sed 's;\..*;;')
  63    else ifneq (,$(wildcard /etc/os-release))
  64       # Ubuntu version
  65       os_ubuntu_release:=$(shell cat /etc/os-release | grep "^VERSION_ID" | sed 's;^.*=;;' | sed 's;\";;g' | sed 's;\..*;;')
  66    endif
  67 
  68    # assume permission to run sudo on linux system
  69    # SUDO_CMD:=
  70    SUDO_CMD:=sudo
  71    ifneq (,$(findstring ubuntu,$(os_type))) 
  72 
  73       # UBUNTU
  74       # *** Not guaranteed to be a comprehensive list
  75       # sudo apt-get install build-essential
  76       # sudo apt-get install libgl1-mesa-dev freeglut3-dev mesa-common-dev
  77       # sudo apt-get install libblas-dev liblapack-dev
  78       # sudo apt-get install ocl-icd-opencl-dev
  79       # sudo apt-get install libxmu-dev libxi-dev
  80       # sudo apt-get install libopencv-dev 
  81       # Ubuntu 16: sudo apt-get install gcc-4.9 g++-4.9 gfortran-4.9
  82       # Ubuntu 18: sudo apt-get install gcc-4.8 g++-4.8 gfortran-4.8
  83       # sudo apt-get install xorg xorg-dev libx11-dev
  84       # sudo apt-get install tcl tcl-dev tk tk-dev
  85       # sudo apt-get install qt5-default qtcreator
  86       # sudo apt-get install libqt5x11extras5-dev
  87       # sudo apt-get install git-annex 
  88 
  89       DEVTOOL_BASE=/usr/bin
  90       BIN_BASE:=$(DEVTOOL_BASE)
  91       LIB_BASE:=/usr/lib
  92       EXTRA_UBUNTU_LINKER_FLAGS:=
  93       ifeq (18,$(os_ubuntu_release))
  94          # gcc-4.8
  95          DEVTOOL_REV:=4.8
  96 	 # tell linker not to ignore RPATH in binaries (needed as of Ubuntu 17+)
  97          EXTRA_UBUNTU_LINKER_FLAGS:=-Wl,--disable-new-dtags
  98       else ifeq (16,$(os_ubuntu_release))
  99          # gcc-4.9
 100          DEVTOOL_REV:=4.9
 101       else
 102          # Will fail for now - FIX ME: need default
 103          DEVTOOL_REV:=
 104       endif
 105 
 106       CMAKE:=/usr/bin/cmake
 107       # CMAKE:=/usr/local/bin/cmake
 108       MAKE:=$(BIN_BASE)/make
 109    
 110       CC:=$(BIN_BASE)/gcc-$(DEVTOOL_REV)
 111       CXX:=$(BIN_BASE)/g++-$(DEVTOOL_REV)
 112       GFORTRAN_LIB_BASE:=$(LIB_BASE)/gcc/x86_64-linux-gnu
 113       GFORTRAN_LIBS:=$(GFORTRAN_LIB_BASE)/$(DEVTOOL_REV)
 114       F77:=$(BIN_BASE)/gfortran-$(DEVTOOL_REV)
 115    
 116       PKGS_ARCH:=centos7-packages.tar.gz
 117       qt_base:=$(LIB_BASE)/x86_64-linux-gnu/qt5
 118 
 119    # else ifneq (,$(findstring CentOS,$(os_rhel))) 
 120    else # end Ubuntu
 121    # Start with CentOS settings as default for all other linux systems
 122 
 123       # CENTOS
 124       # *** Not guaranteed to be a comprehensive list
 125       # sudo yum install qt-create qt-config.x86_64
 126       # sudo yum install qt5-qtx11extras.x86_64 qt5-qtx11extras-devel.x86_64
 127       # sudo yum install boost.x86_64 boost-devel.x86_64
 128       # sudo yum install tk-devel.x86_64 
 129       # sudo yum install opencl-filesystem.noarch opencl-headers.noarch
 130       # sudo yum install opencv.x86_64  opencv-devel.x86_64
 131       # CentOS 6: use scl enable devtoolset-2 bash to get gcc4.8 when running the build target
 132       # centOS 7: sudo yum install cmake3.x86_64 cmake3-data.noarch cmake3-doc.noarch cmake3-gui.x86_64
 133       # yum install git-annex
 134    
 135       DEVTOOL_BASE=/usr/bin
 136       BIN_BASE:=$(DEVTOOL_BASE)
 137       LIB_BASE:=/usr/lib
 138       DEVTOOL_REV:=4.8.2
 139 
 140       ifeq (6,$(os_rhel_release))
 141          CMAKE:=/usr/pubsw/bin/cmake
 142       else
 143          CMAKE:=$(BIN_BASE)/cmake3
 144       endif
 145       MAKE:=$(BIN_BASE)/make
 146    
 147       CC:=$(shell which gcc)
 148       CXX:=$(shell which g++)
 149       F77:=$(shell which gfortran)
 150       ifeq (6,$(os_rhel_release))
 151          GFORTRAN_LIBS:=/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/$(DEVTOOL_REV)
 152       else
 153          GFORTRAN_LIBS:=$(LIB_BASE)/gcc/x86_64-redhat-linux/$(DEVTOOL_REV)
 154       endif
 155       PKGS_ARCH:=centos7-packages.tar.gz
 156       qt_base:=/usr/lib64
 157 
 158    endif # CentOS
 159 
 160 # DARWIN (MAC)
 161 #
 162 # Homebrew requires a full install of Xcode (not just the command line tools).  You can get the
 163 # most recent version fo Xcode from the App Store.  For older versions of MacOS, you can get
 164 # a matching older version of Xcode from the Apple Developers web site (you will need an account
 165 # there), https://developer.apple.com/ 
 166 #
 167 # In addition to installing homebrew (by default under /usr/local), install the gcc-5 compilers
 168 #
 169 # brew update
 170 # brew install gcc@5 
 171 
 172 else ifeq ($(os),darwin)
 173    # assume permission to run sudo on Mac
 174    SUDO_CMD:=sudo
 175    # SUDO_CMD:=
 176 
 177    # use homebrew
 178    HOMEBREW_ROOT:=/usr/local
 179    HOMEBREW_BIN_BASE:=$(HOMEBREW_ROOT)/bin
 180    HOMEBREW_CELLAR_BASE:=$(HOMEBREW_ROOT)/Cellar
 181    HOMEBREW_OPT_BASE:=$(HOMEBREW_ROOT)/opt
 182    CMAKE:=$(HOMEBREW_BIN_BASE)/cmake
 183 
 184    BIN_NO_CCACHE_BASE:=$(HOMEBREW_BIN_BASE)
 185    BIN_CCACHE_BASE:=$(HOMEBREW_OPT_BASE)/ccache/libexec
 186    # no ccache version of F77
 187    F77:=$(BIN_NO_CCACHE_BASE)/gfortran-5
 188    ifneq (,$(USE_CCACHE))
 189       BIN_BASE:=$(BIN_CCACHE_BASE)
 190       $(warning +++ USING CCACHE versions of gcc and g++)
 191    else
 192       BIN_BASE:=$(BIN_NO_CCACHE_BASE)
 193    endif
 194    CC:=$(BIN_BASE)/gcc-5
 195    CXX:=$(BIN_BASE)/g++-5
 196 
 197    # GNU make 4.0 and above preserves correct order of log output with -jN for N>1 
 198    # brew install homebrew/core/make
 199    ifneq (,$(wildcard $(HOMEBREW_BIN_BASE)/gmake))
 200       MAKE:=$(HOMEBREW_BIN_BASE)/gmake
 201    else
 202       # default should be make 3.8x
 203       MAKE:=/usr/bin/make
 204    endif
 205 
 206    PKGS_ARCH:=osx10.11-packages.tar.gz
 207    # qt_base=/Volumes/hd-3/Qt5.10.0/5.10.0/clang_64
 208    qt_base=$(HOMEBREW_CELLAR_BASE)/qt/5.11.2
 209 
 210 endif # darwin
 211 
 212 GIT_BASE:=$(TOPDIR)
 213 EXTRA_PKGS_BASE:=$(GIT_BASE)/packages
 214 BUILD_BASE:=$(GIT_BASE)/freesurfer
 215 INSTALL_BASE:=$(TOPDIR)/install
 216 
 217 # first or default target is help
 218 .PHONY: help nuke fsco pkg_download annexco fsupdate
 219 help:
 220 	$(call help_text)
 221 
 222 # For complete checkout and build from scratch run targets:
 223 # nuke, fsco, pkg_download, annexco, config, build, install
 224 
 225 # Everything will be created underneath the parent subdir where this makefile fragment is located 
 226 
 227 all_src: nuke fsco pkg_download annexco fsupdate
 228 
 229 nuke:
 230 	mkdir -p $(GIT_BASE)
 231 	(cd $(GIT_BASE) && $(SUDO_CMD) rm -rf ./freesurfer)
 232 
 233 fsco:
 234 	mkdir -p $(GIT_BASE)
 235 	(cd $(GIT_BASE) && git clone -b dev https://github.com/freesurfer/freesurfer.git)
 236 
 237 .PHONY: pkg_download
 238 pkg_download:
 239 	(cd $(GIT_BASE) && mkdir -p ./packages && chmod -R 777 ./packages)
 240 	(cd $(GIT_BASE) && rm -rf ./packages)
 241 	(cd $(GIT_BASE) && curl -O $(PKGS_URL)/$(PKGS_ARCH))
 242 	(cd $(GIT_BASE) && tar zxpf $(PKGS_ARCH))
 243 	ls ./packages
 244 
 245 # Try to speed up with number of jobs for git annex get > 1
 246 ifeq ($(os),darwin)
 247 # ANNEX_JOBS:=--jobs=10
 248 ANNEX_JOBS:=
 249 else
 250 # option not available on linux
 251 ANNEX_JOBS:=
 252 endif
 253 annexco:
 254 	(cd $(BUILD_BASE) && git remote add datasrc http://surfer.nmr.mgh.harvard.edu/pub/dist/freesurfer/repo/annex.git)
 255 	(cd $(BUILD_BASE) && git fetch datasrc)
 256 	(cd $(BUILD_BASE) && git annex get $(ANNEX_JOBS) .)
 257 	(cd $(BUILD_BASE) && git status)
 258 	# ignore this error, but check for broken soft links which means annex fetch had a problem
 259 	-(cd $(BUILD_BASE) && find . | xargs file | grep -i "broken")
 260 
 261 # only update source if can fast forward (no merge required)
 262 fsupdate:
 263 	(cd $(BUILD_BASE) && git pull --ff-only)
 264 
 265 ifndef config_cmd
 266 ifeq ($(os),linux)
 267    ifneq (,$(findstring ubuntu,$(os_type))) 
 268       # Ubuntu
 269       config_cmd:=\
 270       CC=$(CC) \
 271       CXX=$(CXX) \
 272       FC=$(F77) \
 273       $(CMAKE) \
 274       -DCMAKE_MAKE_PROGRAM=$(MAKE) \
 275       -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
 276       -DFS_PACKAGES_DIR=$(EXTRA_PKGS_BASE) \
 277       -DCMAKE_CXX_FLAGS:STRING="${CMAKE_CXX_FLAGS} -I/usr/include/tcl -Wno-deprecated -Wno-deprecated-declarations" \
 278       -DX11_INCLUDE_DIR=/usr/include/X11 \
 279       -DOPENGL_glu_LIBRARY=$(LIB_BASE)/x86_64-linux-gnu/libGLU.so.1 \
 280       -DOpenCL_INCLUDE_DIRS=/usr/include \
 281       -DCMAKE_RULE_MESSAGES:BOOL=ON \
 282       -DCMAKE_INSTALL_PREFIX="$(INSTALL_BASE)" \
 283       -DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS} $(EXTRA_UBUNTU_LINKER_FLAGS) -L$(LIB_BASE)/x86_64-linux-gnu -L/usr/local/lib -lz" \
 284       -DGFORTRAN_LIBRARIES=$(GFORTRAN_LIBS)/libgfortran.so
 285    # else ifneq (,$(findstring CentOS,$(os_rhel))) 
 286    else # end Ubuntu
 287    # Start with CentOS settings as default for all other linux systems
 288       config_cmd:=\
 289       $(CMAKE) \
 290       -DCMAKE_MAKE_PROGRAM=$(MAKE) \
 291       -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
 292       -DFS_PACKAGES_DIR=$(EXTRA_PKGS_BASE) \
 293       -DCMAKE_CXX_FLAGS:STRING="${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-deprecated-declarations" \
 294       -DCMAKE_RULE_MESSAGES:BOOL=ON \
 295       -DCMAKE_INSTALL_PREFIX="$(INSTALL_BASE)" \
 296       -DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS} -lz" \
 297       -DGFORTRAN_LIBRARIES=$(GFORTRAN_LIBS)/libgfortran.so
 298    endif # CentOS/default linux
 299 
 300 else ifeq ($(os),darwin)
 301 
 302    config_cmd=\
 303    CC=$(CC) \
 304    CXX=$(CXX) \
 305    FC=$(F77) \
 306    $(CMAKE) \
 307    -DCMAKE_MAKE_PROGRAM=$(MAKE) \
 308    -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
 309    -DFS_PACKAGES_DIR=$(EXTRA_PKGS_BASE) \
 310    -DCMAKE_RULE_MESSAGES:BOOL=ON \
 311    -DCMAKE_INSTALL_PREFIX="$(INSTALL_BASE)"
 312 
 313 endif # darwin
 314 endif # config_cmd
 315 
 316 
 317 # Do minimal build for target config_min
 318 ifeq (config_min,$(findstring config_min,$(MAKECMDGOALS)))
 319    config_cmd+=-DMINIMAL:BOOL=ON
 320 endif
 321 ifneq (,$(wildcard $(qt_base)))
 322    config_cmd+=-DCMAKE_PREFIX_PATH=$(qt_base)
 323 else
 324    $(warning Could not stat path to qt distribution $(qt_base), so skipping adding it via -DCMAKE_PREFIX_PATH)
 325 endif
 326 
 327 export config_cmd
 328 
 329 .PHONY: config_print config config_min config_common clean
 330 config_print:
 331 	@echo "$(config_cmd)"
 332 
 333 # Allow devtoolsets (with different compilers) to be used for CentOS builds
 334 devtoolset_config_cmd=
 335 config config_min:
 336 ifeq (6,$(os_rhel_release))
 337 	scl enable devtoolset-2 '$(MAKE) config_cmd=$(config_cmd) -f $(this_makefile) config_common'
 338 else
 339 	$(MAKE) -f $(this_makefile) config_common
 340 endif
 341 
 342 config_common:
 343 	(cd $(BUILD_BASE) && rm -f CMakeCache.txt && rm -f cmake.log)	
 344 	(cd $(BUILD_BASE) && $(config_cmd) . 2>&1 | tee -a cmake.log)
 345 
 346 
 347 ifndef MAKE_OPTS
 348    MAKE_OPTS:=VERBOSE=1
 349    define make_opt_keepgoing
 350    MAKE_OPTS+=-k
 351    endef
 352    define make_opt_serial
 353    MAKE_OPTS+=-j1
 354    endef
 355    define make_opt_parallel
 356    MAKE_OPTS+=-j8
 357    endef
 358 endif # MAKE_OPTS
 359 export MAKE_OPTS
 360 
 361 clean:
 362 	(cd $(BUILD_BASE) && $(MAKE) $(MAKE_OPT) clean)
 363 
 364 
 365 # target "build" default is to build with VERBOSE and -j8
 366 # target "build_k" or append _k to target for -k keepgoing option past any compilation errors
 367 # target "build_s" or append _s to build serially (-j1) which is useful for debugging builds especially
 368 # target "build_k_s" to combine options -k and -j1
 369 
 370 # default is to build parallel with -j8
 371 .PHONY: build build_k build_s build_k_s build_s_k
 372 build build_k build_s build_k_s build_s_k:
 373 	$(if $(findstring _s,$@),$(eval $(make_opt_serial)),$(eval $(make_opt_parallel)))
 374 	$(if $(findstring _k,$@),$(eval $(make_opt_keepgoing)),)
 375 ifeq (6,$(os_rhel_release))
 376 	scl enable devtoolset-2 '$(MAKE) -f $(this_makefile) build_common'
 377 else
 378 	# assume native compilers should work
 379 	$(MAKE) $(MAKE_OPTS) -f $(this_makefile) build_common
 380 endif
 381 
 382 .PHONY: build_common
 383 # build target above runs common build target
 384 build_common:
 385 	which $(MAKE) && $(MAKE) --version
 386 	(cd $(BUILD_BASE) && rm -f make.log && $(MAKE) $(MAKE_OPTS) 2>&1 | tee -a make.log)
 387 
 388 # default is to build parallel with -j8
 389 .PHONY: install install_k install_s install_k_s install_s_k
 390 # Assume nothing left to be compiled when install target is run, so scl enable does not need to be run
 391 install install_k install_s install_k_s install_s_k:
 392 	$(if $(findstring _s,$@),$(eval $(make_opt_serial)),$(eval $(make_opt_parallel)))
 393 	$(if $(findstring _k,$@),$(eval $(make_opt_keepgoing)),)
 394 	mkdir -p $(INSTALL_BASE)
 395 	(cd $(INSTALL_BASE) && $(SUDO_CMD) rm -rf *)
 396 	(cd $(BUILD_BASE) && rm -f install.log && $(SUDO_CMD) $(MAKE) $(MAKE_OPTS) install 2>&1 | tee -a install.log)
 397 	ls $(INSTALL_BASE)
 398 
 399 
 400 .PHONY: test
 401 python_rev:=$(shell python --version)
 402 
 403 # uncomment and add the path to your license here
 404 # test: export FS_LICENSE=
 405 test: export FREESURFER_HOME=$(INSTALL_BASE)
 406 test: export CTEST_OUTPUT_ON_FAILURE=1
 407 test:
 408 ifeq (,$(findstring Python 3,$(python_rev)))
 409 	@echo "Cannot run $@ target without a python version 3.X in PATH"
 410 else
 411 	(cd $(BUILD_BASE) && rm -f test.log && $(MAKE) $(MAKE_OPT) test 2>&1 | tee -a test.log)
 412 endif
 413 
 414 
 415 # After install target, check if GUI based freeview runs.
 416 # Note that freeview is not built in a "minimal" buid with -DMININAL cmake option
 417 
 418 freeview_volume:=$(INSTALL_BASE)/subjects/cvs_avg35/mri/T1.mgz
 419 ifeq (,$(wildcard $(freeview_volume)))
 420    freeview_volume:=
 421 endif
 422 
 423 ifeq ($(os),linux)
 424    freeview_binary:=freeview
 425    freeview_cmd:=./$(freeview_binary) $(freeview_volume)
 426    freeview_install_dir:=$(INSTALL_BASE)/bin
 427 else ifeq ($(os),darwin)
 428    freeview_binary:=Freeview.app
 429    freeview_cmd:=open -a $(freeview_binary) $(freeview_volume)
 430    freeview_install_dir:=$(INSTALL_BASE)
 431 endif
 432 
 433 .PHONY: run_freeview
 434 run_freeview:
 435 ifneq (,$(wildcard $(BUILD_BASE)/freeview/$(freeview_binary)))
 436 	(cd $(BUILD_BASE)/freeview && $(freeview_cmd))
 437 else ifneq (,$(wildcard $(freeview_install_dir)/$(freeview_binary)))
 438 	(cd $(freeview_install_dir) && $(freeview_cmd))
 439 else
 440 	$(warning No freeview binary to run under $(BUILD_BASE)/freeview or $(INSTALL_BASE))
 441 	$(warning Please check that freeview was built ad/or installed)
 442 endif # test for freeview

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2018-11-19 01:56:29, 15.7 KB) [[attachment:makefile.txt]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.