1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
# Copyright (c) 2019 Maxim Egorushkin. MIT License. See the full licence in file LICENSE.
# Usage examples (assuming this directory is ~/src/atomic_queue):
# time make -rC ~/src/atomic_queue -j8 run_benchmarks
# time make -rC ~/src/atomic_queue -j8 TOOLSET=clang run_benchmarks
# time make -rC ~/src/atomic_queue -j8 BUILD=debug run_tests
SHELL := /bin/bash
BUILD := release
TOOLSET := gcc
build_dir := ${CURDIR}/build/${BUILD}/${TOOLSET}
build_dir_shared := ${CURDIR}/build_shared/${BUILD}/${TOOLSET}
cxx.gcc := g++
cc.gcc := gcc
ld.gcc := g++
ar.gcc := gcc-ar
cxx.clang := clang++
cc.clang := clang
ld.clang := clang++
ar.clang := ar
CXX := ${cxx.${TOOLSET}}
CC := ${cc.${TOOLSET}}
LD := ${ld.${TOOLSET}}
AR := ${ar.${TOOLSET}}
cxxflags.gcc.debug := -Og -fstack-protector-all -fno-omit-frame-pointer # -D_GLIBCXX_DEBUG
cxxflags.gcc.release := -O3 -ffast-math -falign-{functions,loops}=64 -DNDEBUG
cxxflags.gcc := -pthread -std=gnu++14 -W{all,extra,error,no-{maybe-uninitialized,unused-function,unused-local-typedefs}} -g -fmessage-length=0 ${cxxflags.gcc.${BUILD}}
cflags.gcc := -pthread -W{all,extra} -g -fmessage-length=0 ${cxxflags.gcc.${BUILD}}
cxxflags.clang.debug := -O0 -fstack-protector-all
cxxflags.clang.release := -O3 -ffast-math -falign-functions=64 -DNDEBUG
cxxflags.clang := -stdlib=libstdc++ -pthread -std=gnu++14 -W{all,extra,error,no-{unused-variable,unused-function,unused-local-typedefs}} -g -fmessage-length=0 ${cxxflags.clang.${BUILD}}
ldflags.clang := -stdlib=libstdc++ ${ldflags.clang.${BUILD}}
# Additional CPPFLAGS, CXXFLAGS, CFLAGS, LDLIBS, LDFLAGS can come from the command line, e.g. make CPPFLAGS='-I<my-include-dir>', or from environment variables.
# However, a clean build is required when changing the flags in the command line or in environment variables, this makefile doesn't detect such changes.
cxxflags := ${cxxflags.${TOOLSET}} ${CXXFLAGS}
cflags := ${cflags.${TOOLSET}} ${CFLAGS}
cppflags := ${CPPFLAGS} -Iinclude
ldflags := -fuse-ld=gold -pthread -g ${ldflags.${TOOLSET}} ${LDFLAGS}
ldlibs := -lrt ${LDLIBS}
ifdef BOOST_ROOT_1_72_0 # E.g./opt/hostedtoolcache/boost/1.72.0/x64
boost_unit_test_framework_inc := -I${BOOST_ROOT_1_72_0}
boost_unit_test_framework_lib := -{L,'Wl,-rpath='}${BOOST_ROOT_1_72_0}/lib -lboost_unit_test_framework-mt-x64
else
boost_unit_test_framework_lib := -lboost_unit_test_framework
endif
cppflags.tbb :=
ldlibs.tbb := {-L,'-Wl,-rpath='}/usr/local/lib -ltbb
cppflags.moodycamel := -I$(abspath ..)
ldlibs.moodycamel :=
cppflags.xenium := -I${abspath ../xenium}
ldlibs.xenium :=
SOVERSION := 0
COMPILE.CXX = ${CXX} -o $@ -c ${cppflags} ${cxxflags} -MD -MP $(abspath $<)
COMPILE.S = ${CXX} -o- -S -masm=intel ${cppflags} ${cxxflags} $(abspath $<) | c++filt | egrep -v '^[[:space:]]*\.(loc|cfi|L[A-Z])' > $@
PREPROCESS.CXX = ${CXX} -o $@ -E ${cppflags} ${cxxflags} $(abspath $<)
COMPILE.C = ${CC} -o $@ -c ${cppflags} ${cflags} -MD -MP $(abspath $<)
LINK.EXE = ${LD} -o $@ $(ldflags) $(filter-out Makefile,$^) $(ldlibs)
LINK.SO = ${LD} -o $@.$(SOVERSION) -shared -Wl,-soname,`basename $@`.$(SOVERSION) $(ldflags) $(filter-out Makefile,$^) $(ldlibs)
LINK.A = ${AR} rscT $@ $(filter-out Makefile,$^)
exes := benchmarks tests example
all : ${exes}
${exes} : % : ${build_dir}/% ${build_dir}/libatomic_queue.a ${build_dir_shared}/libatomic_queue.so
ln -sf ${<:${CURDIR}/%=%}
${build_dir}/libatomic_queue.a : $(addprefix ${build_dir}/,cpu_base_frequency.o huge_pages.o)
-include ${build_dir}/cpu_base_frequency.d
-include ${build_dir}/huge_pages.d
${build_dir_shared}/libatomic_queue.so : $(addprefix ${build_dir_shared}/,cpu_base_frequency.o huge_pages.o)
-include ${build_dir_shared}/cpu_base_frequency.d
-include ${build_dir_shared}/huge_pages.d
benchmarks_src := benchmarks.cc cpu_base_frequency.cc huge_pages.cc
${build_dir}/benchmarks : cppflags += ${cppflags.tbb} ${cppflags.moodycamel} ${cppflags.xenium}
${build_dir}/benchmarks : ldlibs += ${ldlibs.tbb} ${ldlibs.moodycamel} ${ldlibs.xenium} -ldl
${build_dir}/benchmarks : ${benchmarks_src:%.cc=${build_dir}/%.o} Makefile | ${build_dir}
$(strip ${LINK.EXE})
-include ${benchmarks_src:%.cc=${build_dir}/%.d}
tests_src := tests.cc
${build_dir}/tests : cppflags += ${boost_unit_test_framework_inc} -DBOOST_TEST_DYN_LINK=1
${build_dir}/tests : ldlibs += ${boost_unit_test_framework_lib}
${build_dir}/tests : ${tests_src:%.cc=${build_dir}/%.o} Makefile | ${build_dir}
$(strip ${LINK.EXE})
-include ${tests_src:%.cc=${build_dir}/%.d}
example_src := example.cc
${build_dir}/example : ${example_src:%.cc=${build_dir}/%.o} Makefile | ${build_dir}
$(strip ${LINK.EXE})
-include ${example_src:%.cc=${build_dir}/%.d}
${build_dir_shared}/%.so : cxxflags += -fPIC
${build_dir_shared}/%.so : Makefile | ${build_dir_shared}
${LINK.SO}
ln -s `basename $@`.$(SOVERSION) $@
${build_dir}/%.a : Makefile | ${build_dir}
$(strip ${LINK.A})
run_benchmarks : ${build_dir}/benchmarks
@echo "---- running $< ----"
scripts/benchmark-prologue.sh
-sudo chrt -f 50 $<
scripts/benchmark-epilogue.sh
run_tests : ${build_dir}/tests
@echo "---- running $< ----"
$<
run_% : ${build_dir}/%
@echo "---- running $< ----"
$<
${build_dir}/%.o : src/%.cc Makefile | ${build_dir}
$(strip ${COMPILE.CXX})
${build_dir}/%.o : src/%.c Makefile | ${build_dir}
$(strip ${COMPILE.C})
${build_dir_shared}/%.o : src/%.cc Makefile | ${build_dir_shared}
$(strip ${COMPILE.CXX})
${build_dir_shared}/%.o : src/%.c Makefile | ${build_dir_shared}
$(strip ${COMPILE.C})
%.S : cppflags += ${cppflags.tbb} ${cppflags.moodycamel} ${cppflags.xenium}
%.S : src/%.cc Makefile | ${build_dir}
$(strip ${COMPILE.S})
%.I : src/%.cc
$(strip ${PREPROCESS.CXX})
${build_dir} :
mkdir -p $@
${build_dir_shared} :
mkdir -p $@
rtags : clean
${MAKE} -nk | rc -c -; true
clean :
rm -rf ${build_dir} ${exes} ${build_dir_shared}
env :
env | sort
versions:
${MAKE} --version | head -n1
${CXX} --version | head -n1
.PHONY : env versions rtags run_benchmarks clean all run_%
|