Austin Schuh | ab802d5 | 2020-07-03 18:11:11 -0700 | [diff] [blame] | 1 | # Use C++11, dont warn on long-to-float conversion |
| 2 | CXXFLAGS += -std=c++11 -Wno-conversion |
Austin Schuh | 6c8ec4c | 2018-01-23 11:18:57 -0800 | [diff] [blame] | 3 | |
Austin Schuh | ab802d5 | 2020-07-03 18:11:11 -0700 | [diff] [blame] | 4 | # Default to using system's default version of python |
| 5 | PYTHON_BIN ?= python3 |
| 6 | PYTHON_CONFIG := $(PYTHON_BIN)-config |
| 7 | PYTHON_INCLUDE ?= $(shell $(PYTHON_CONFIG) --includes) |
| 8 | EXTRA_FLAGS := $(PYTHON_INCLUDE) |
| 9 | # NOTE: Since python3.8, the correct invocation is `python3-config --libs --embed`. |
| 10 | # So of course the proper way to get python libs for embedding now is to |
| 11 | # invoke that, check if it crashes, and fall back to just `--libs` if it does. |
| 12 | LDFLAGS += $(shell if $(PYTHON_CONFIG) --ldflags --embed >/dev/null; then $(PYTHON_CONFIG) --ldflags --embed; else $(PYTHON_CONFIG) --ldflags; fi) |
Austin Schuh | 6c8ec4c | 2018-01-23 11:18:57 -0800 | [diff] [blame] | 13 | |
Austin Schuh | ab802d5 | 2020-07-03 18:11:11 -0700 | [diff] [blame] | 14 | # Either finds numpy or set -DWITHOUT_NUMPY |
| 15 | EXTRA_FLAGS += $(shell $(PYTHON_BIN) $(CURDIR)/numpy_flags.py) |
| 16 | WITHOUT_NUMPY := $(findstring $(EXTRA_FLAGS), WITHOUT_NUMPY) |
Austin Schuh | 6c8ec4c | 2018-01-23 11:18:57 -0800 | [diff] [blame] | 17 | |
Austin Schuh | ab802d5 | 2020-07-03 18:11:11 -0700 | [diff] [blame] | 18 | # Examples requiring numpy support to compile |
| 19 | EXAMPLES_NUMPY := surface colorbar |
| 20 | EXAMPLES := minimal basic modern animation nonblock xkcd quiver bar \ |
| 21 | fill_inbetween fill update subplot2grid lines3d \ |
| 22 | $(if $(WITHOUT_NUMPY),,$(EXAMPLES_NUMPY)) |
Austin Schuh | 6c8ec4c | 2018-01-23 11:18:57 -0800 | [diff] [blame] | 23 | |
Austin Schuh | ab802d5 | 2020-07-03 18:11:11 -0700 | [diff] [blame] | 24 | # Prefix every example with 'examples/build/' |
| 25 | EXAMPLE_TARGETS := $(patsubst %,examples/build/%,$(EXAMPLES)) |
Austin Schuh | 6c8ec4c | 2018-01-23 11:18:57 -0800 | [diff] [blame] | 26 | |
Austin Schuh | ab802d5 | 2020-07-03 18:11:11 -0700 | [diff] [blame] | 27 | .PHONY: examples |
Austin Schuh | 6c8ec4c | 2018-01-23 11:18:57 -0800 | [diff] [blame] | 28 | |
Austin Schuh | ab802d5 | 2020-07-03 18:11:11 -0700 | [diff] [blame] | 29 | examples: $(EXAMPLE_TARGETS) |
| 30 | |
| 31 | docs: |
| 32 | doxygen |
| 33 | moxygen doc/xml --noindex -o doc/api.md |
| 34 | |
| 35 | # Assume every *.cpp file is a separate example |
| 36 | $(EXAMPLE_TARGETS): examples/build/%: examples/%.cpp matplotlibcpp.h |
| 37 | mkdir -p examples/build |
| 38 | $(CXX) -o $@ $< $(EXTRA_FLAGS) $(CXXFLAGS) $(LDFLAGS) |
Austin Schuh | 6c8ec4c | 2018-01-23 11:18:57 -0800 | [diff] [blame] | 39 | |
| 40 | clean: |
Austin Schuh | ab802d5 | 2020-07-03 18:11:11 -0700 | [diff] [blame] | 41 | rm -f ${EXAMPLE_TARGETS} |