2019-08-19 00:28:54 +03:00
|
|
|
DESTDIR ?=
|
|
|
|
prefix ?= /usr
|
|
|
|
bindir := $(prefix)/bin
|
|
|
|
pkglibdir := $(prefix)/lib/coz-profiler
|
|
|
|
incdir := $(prefix)/include
|
|
|
|
mandir := $(prefix)/share/man
|
|
|
|
man1dir := $(mandir)/man1
|
2016-07-10 23:13:37 +03:00
|
|
|
|
|
|
|
INSTALL = install
|
2017-08-14 19:32:08 +03:00
|
|
|
RST2MAN = rst2man
|
2016-07-10 23:13:37 +03:00
|
|
|
|
2019-08-18 20:49:32 +03:00
|
|
|
# Build with clang by default
|
|
|
|
CC ?= clang
|
|
|
|
CXX ?= clang++
|
2014-09-30 18:56:52 +04:00
|
|
|
|
2015-10-10 06:01:14 +03:00
|
|
|
# Set coz and include path for coz
|
|
|
|
ifeq ($(USE_SYSTEM_COZ),1)
|
2019-08-19 00:28:54 +03:00
|
|
|
COZ := $(shell which coz)
|
2015-10-10 06:01:14 +03:00
|
|
|
else
|
2019-08-19 00:28:54 +03:00
|
|
|
COZ := $(ROOT)/coz
|
2015-10-10 06:01:14 +03:00
|
|
|
endif
|
2015-10-07 09:30:18 +03:00
|
|
|
|
2014-09-30 18:56:52 +04:00
|
|
|
# Default flags
|
|
|
|
CFLAGS ?= -g -O2
|
|
|
|
CXXFLAGS ?= $(CFLAGS)
|
2017-02-02 11:03:15 +03:00
|
|
|
LDLIBS += $(addprefix -l,$(LIBS))
|
2014-09-30 18:56:52 +04:00
|
|
|
|
|
|
|
# Default source and object files
|
2019-08-19 00:28:54 +03:00
|
|
|
SRCS ?= $(wildcard *.cpp) $(wildcard *.c)
|
|
|
|
OBJS ?= $(addprefix obj/,$(patsubst %.cpp,%.o,$(patsubst %.c,%.o,$(SRCS))))
|
|
|
|
|
|
|
|
# Prevent errors if files named all, clean, distclean, bench, or test exist
|
|
|
|
.PHONY: all clean distclean bench test
|
2014-09-30 18:56:52 +04:00
|
|
|
|
|
|
|
# Targets to build recirsively into $(DIRS)
|
2019-08-19 01:32:02 +03:00
|
|
|
RECURSIVE_TARGETS ?= all clean bench bench_large bench_small test install check
|
2014-09-30 18:56:52 +04:00
|
|
|
|
|
|
|
# Targets separated by type
|
|
|
|
SHARED_LIB_TARGETS := $(filter %.so, $(TARGETS))
|
|
|
|
STATIC_LIB_TARGETS := $(filter %.a, $(TARGETS))
|
|
|
|
OTHER_TARGETS := $(filter-out %.so, $(filter-out %.a, $(TARGETS)))
|
|
|
|
|
|
|
|
# If not set, the build path is just the current directory name
|
2019-08-19 00:28:54 +03:00
|
|
|
MAKEPATH ?= $(shell basename $(shell pwd))
|
2014-09-30 18:56:52 +04:00
|
|
|
|
|
|
|
# Log the build path in gray, following by a log message in bold green
|
2015-10-06 20:30:32 +03:00
|
|
|
LOG_PREFIX := "$(shell tput setaf 7)[$(MAKEPATH)]$(shell tput sgr0)$(shell tput setaf 2)"
|
|
|
|
LOG_SUFFIX := "$(shell tput sgr0)"
|
2014-09-30 18:56:52 +04:00
|
|
|
|
2019-08-19 00:28:54 +03:00
|
|
|
# Build in parallel
|
|
|
|
MAKEFLAGS += -j
|
|
|
|
|
2019-08-19 00:33:54 +03:00
|
|
|
# Build all targets by default, unless this is a benchmark
|
2014-09-30 18:56:52 +04:00
|
|
|
all:: $(TARGETS)
|
|
|
|
|
2019-08-19 01:32:02 +03:00
|
|
|
# Clean up after a build
|
2014-09-30 18:56:52 +04:00
|
|
|
clean::
|
|
|
|
@for t in $(TARGETS); do \
|
|
|
|
echo $(LOG_PREFIX) Cleaning $$t $(LOG_SUFFIX); \
|
|
|
|
done
|
|
|
|
@rm -rf $(TARGETS) obj
|
|
|
|
|
2016-08-10 12:28:14 +03:00
|
|
|
# Bring source back to pristine state
|
|
|
|
distclean:: clean
|
2019-08-19 00:28:54 +03:00
|
|
|
@$(MAKE) -C benchmarks clean
|
2014-09-30 18:56:52 +04:00
|
|
|
|
|
|
|
# Compile a C++ source file (and generate its dependency rules)
|
2014-10-03 18:27:57 +04:00
|
|
|
obj/%.o: %.cpp $(PREREQS)
|
2014-09-30 18:56:52 +04:00
|
|
|
@echo $(LOG_PREFIX) Compiling $< $(LOG_SUFFIX)
|
|
|
|
@mkdir -p obj
|
|
|
|
@$(CXX) $(CXXFLAGS) -MMD -MP -o $@ -c $<
|
|
|
|
|
|
|
|
# Compile a C source file (and generate its dependency rules)
|
2014-10-03 18:27:57 +04:00
|
|
|
obj/%.o: %.c $(PREREQS)
|
2014-09-30 18:56:52 +04:00
|
|
|
@echo $(LOG_PREFIX) Compiling $< $(LOG_SUFFIX)
|
|
|
|
@mkdir -p obj
|
|
|
|
@$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
|
|
|
|
|
2015-04-09 00:31:18 +03:00
|
|
|
# Link a shared library
|
2014-09-30 18:56:52 +04:00
|
|
|
$(SHARED_LIB_TARGETS): $(OBJS)
|
|
|
|
@echo $(LOG_PREFIX) Linking $@ $(LOG_SUFFIX)
|
2017-02-02 11:03:15 +03:00
|
|
|
@$(CXX) -shared $(LDFLAGS) -o $@ $^ $(LDLIBS)
|
2014-09-30 18:56:52 +04:00
|
|
|
|
2015-01-28 03:07:11 +03:00
|
|
|
$(STATIC_LIB_TARGETS): $(OBJS)
|
|
|
|
@echo $(LOG_PREFIX) Linking $@ $(LOG_SUFFIX)
|
|
|
|
@ar rs $@ $^
|
|
|
|
|
2014-09-30 18:56:52 +04:00
|
|
|
# Link binary targets
|
|
|
|
$(OTHER_TARGETS): $(OBJS)
|
|
|
|
@echo $(LOG_PREFIX) Linking $@ $(LOG_SUFFIX)
|
2017-02-02 11:03:15 +03:00
|
|
|
@$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
|
2014-09-30 18:56:52 +04:00
|
|
|
|
|
|
|
# Include dependency rules for all objects
|
|
|
|
-include $(OBJS:.o=.d)
|
|
|
|
|
|
|
|
# Build any recursive targets in subdirectories
|
|
|
|
$(RECURSIVE_TARGETS)::
|
|
|
|
@for dir in $(DIRS); do \
|
2016-08-10 11:45:12 +03:00
|
|
|
$(MAKE) -C $$dir --no-print-directory $@ MAKEPATH="$(MAKEPATH)/$$dir" || exit 1; \
|
2015-04-09 00:31:18 +03:00
|
|
|
done
|