Skip to content

Instantly share code, notes, and snippets.

@IvanYashchuk
Created April 16, 2020 10:10
Show Gist options
  • Save IvanYashchuk/d2e878cd5a7402ecaaf2b7e6b5f59bcd to your computer and use it in GitHub Desktop.
Save IvanYashchuk/d2e878cd5a7402ecaaf2b7e6b5f59bcd to your computer and use it in GitHub Desktop.
Makefile for Stan Math standalone shared library
# makefile to be used for standalone compliation of
# C++ programs. Note that the dependend libraries
# must be compiled first by the math-libs target
#
# Example for hello-math.cpp C++ program:
#
# make -f path/to/math/make/standalone math-libs
# make -f path/to/math/make/standalone hello-math
#
# in case this makefile is used within another makefile
# via an include statement then the user is advised to
# define the MATH variable to point to the stan-math root
# directory (with a trailing "/").
MATH_MAKE ?=$(dir $(abspath $(firstword $(MAKEFILE_LIST))))
MATH ?= $(realpath $(MATH_MAKE)..)/
-include $(HOME)/.config/stan/make.local
-include $(MATH)make/local
-include $(MATH)make/compiler_flags
-include $(MATH)make/libraries
# Stan math programs must include the TBB.
# The sundials libraries are only needed for
# programs using the stiff ode solver or the
# algebra solver
MATH_LIBS ?= $(LIBSUNDIALS) $(MPI_TARGETS) $(TBB_TARGETS)
LDLIBS += $(MATH_LIBS)
math-libs : $(MATH_LIBS)
.PHONY: math-clean
math-clean : clean-libraries
##
# Debug target that allows you to print a variable
##
print-% : ; @echo $* = $($*)
##
# Shared library target
##
CXXFLAGS += -fPIC
%.so: %.o
$(CXX) -shared $< -o $@
@IvanYashchuk
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment