-
Jan Trávníček authoredJan Trávníček authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
makefile 6.18 KiB
SHELL:=/bin/bash
USE_RAMDISK ?= 0
-include makefile.conf
define NEW_LINE
endef
export NEW_LINE
LDFLAGS_DEBUG:=-Wl,-no-as-needed $(addprefix -L, $(addsuffix lib-debug, $(LINK_PATHS))) -rdynamic $(addprefix -l, $(LINK_LIBRARIES)) -Wl,-rpath,.
LDFLAGS_RELEASE:=-Wl,-no-as-needed $(addprefix -L, $(addsuffix lib-release, $(LINK_PATHS))) -rdynamic $(addprefix -l, $(LINK_LIBRARIES)) -Wl,-rpath,.
OBJECTS_DEBUG:=$(patsubst src/%.cpp, obj-debug/%.o, $(shell find src/ -name *cpp))
OBJECTS_RELEASE:=$(patsubst src/%.cpp, obj-release/%.o, $(shell find src/ -name *cpp))
.PHONY: all build-debug clean-debug doc
all:
@echo "What to do master?"
FORCE:
# -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# make subdir makefile
%/makefile: makefile makefile.conf
if [ ! -w $(dir $@) ] && [ $(USE_RAMDISK) -eq 1 ]; then\
ln -s /tmp/`date +'%s%N'`-$(dir $@) $(subst /, , $(dir $@)) 2>/dev/null;\
fi;\
if [ -L $(subst /, , $(dir $@)) ]; then\
mkdir -p `readlink $(subst /, , $(dir $@))`;\
else\
mkdir -p $(dir $@);\
fi
echo "\
SHELL:=/bin/bash$${NEW_LINE}\
SRCDIR:=$${NEW_LINE}\
$${NEW_LINE}\
define NEW_LINE$${NEW_LINE}\
$${NEW_LINE}\
$${NEW_LINE}\
endef$${NEW_LINE}\
$${NEW_LINE}\
export NEW_LINE$${NEW_LINE}\
$${NEW_LINE}\
CXXFLAGS:= -pipe -std=c++11 \$$(CXX_OTHER_FLAGS) -c -Wall -pedantic -Wextra -Werror -fPIC \$$(addprefix -I, \$$(realpath $(INCLUDE_PATHS)))$${NEW_LINE}\
$${NEW_LINE}\
SOURCES:= \$$(shell find \$$(SOURCES_BASE_DIR)/\$$(SRCDIR) -maxdepth 1 -type f -name \"*.cpp\")$${NEW_LINE}\
DEPENDENCIES:= \$$(patsubst \$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, \$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d, \$$(SOURCES))$${NEW_LINE}\
OBJECTS:= \$$(patsubst %.d, %.o, \$$(DEPENDENCIES))$${NEW_LINE}\
SOURCES_DIRS:= \$$(shell find \$$(SOURCES_BASE_DIR)/\$$(SRCDIR) -maxdepth 1 -mindepth 1 -type d)$${NEW_LINE}\
OBJECTS_DIRS:= \$$(patsubst \$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%, %/, \$$(SOURCES_DIRS))$${NEW_LINE}\
OBJECTS_DIRS_MAKEFILES:= \$$(patsubst %, %makefile, \$$(OBJECTS_DIRS))$${NEW_LINE}\
$${NEW_LINE}\
.PHONY: all$${NEW_LINE}\
.PRECIOUS: \$$(DEPENDECIES) \$$(OBJECTS_DIRS_MAKEFILES)$${NEW_LINE}\
$${NEW_LINE}\
all: \$$(OBJECTS_DIRS) \$$(OBJECTS)$${NEW_LINE}\
$${NEW_LINE}\
%.d: makefile$${NEW_LINE}\
@echo \"\\$${NEW_LINE}\
\$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\") = \\$$\$$(shell (\\$$\$$(CXX) -M \\$$\$$(CXXFLAGS) \$$(patsubst \$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d,\$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, \$$@) 2>/dev/null || echo \\\"\$$(patsubst \$$(OBJECTS_BASE_DIR)/\$$(SRCDIR)%.d,\$$(SOURCES_BASE_DIR)/\$$(SRCDIR)%.cpp, \$$@) FORCE\\\") | sed \\\"s/.*://g;s/\\\\\\\\\\\\\\\\//g\\\")\$$\$${NEW_LINE}\\$${NEW_LINE}\
\$$(patsubst %.d,%.o, \$$@): \\$$\$$(\$$(shell sha1sum <<< \"\$$@\" | sed \"s/ -//g\")) makefile\$$\$${NEW_LINE}\\$${NEW_LINE}\
\\$$\$$(CXX) \\$$\$$(CXXFLAGS) \\$$\$$< -o \$$(patsubst %.d,%.o, \$$@)\$$\$${NEW_LINE}\\$${NEW_LINE}\
\" > \$$@$${NEW_LINE}\
$${NEW_LINE}\
%/makefile: makefile$${NEW_LINE}\
mkdir -p \$$(dir \$$@)$${NEW_LINE}\
cp makefile \$$@$${NEW_LINE}\
$${NEW_LINE}\
%/: FORCE | %/makefile$${NEW_LINE}\
@accesstime=\`stat -c %Y \$$@\` && \\$${NEW_LINE}\
\$$(MAKE) -C \$$@ SRCDIR=\$$(SRCDIR)\$$(notdir \$$(patsubst %/, %, \$$@))/ OBJECTS_BASE_DIR=\$$(OBJECTS_BASE_DIR) SOURCES_BASE_DIR=\$$(SOURCES_BASE_DIR) CXX_OTHER_FLAGS=\"\$$(CXX_OTHER_FLAGS)\" && \\$${NEW_LINE}\
accesstime2=\`stat -c %Y \$$@\` && \\$${NEW_LINE}\
if [ "\$$\$$accesstime" -ne "\$$\$$accesstime2" ]; then \\$${NEW_LINE}\
touch .; \\$${NEW_LINE}\
fi$${NEW_LINE}\
$${NEW_LINE}\
FORCE:$${NEW_LINE}\
$${NEW_LINE}\
-include \$$(DEPENDENCIES)" > $@
# -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# final lib/bin construction
bin-debug/$(EXECUTABLE): obj-debug/ $(OBJECTS_DEBUG)
if [ ! -w $(dir $@) ] && [ $(USE_RAMDISK) -eq 1 ]; then\
ln -s /tmp/`date +'%s%N'`-$(dir $@) $(subst /, , $(dir $@)) 2>/dev/null;\
fi;\
if [ -L $(subst /, , $(dir $@)) ]; then\
mkdir -p `readlink $(subst /, , $(dir $@))`;\
else\
mkdir -p $(dir $@);\
fi
$(CXX) $(OBJECTS_DEBUG) -o $@ $(LDFLAGS_DEBUG)
bin-release/$(EXECUTABLE): obj-release/ $(OBJECTS_RELEASE)
if [ ! -w $(dir $@) ] && [ $(USE_RAMDISK) -eq 1 ]; then\
ln -s /tmp/`date +'%s%N'`-$(dir $@) $(subst /, , $(dir $@)) 2>/dev/null;\
fi;\
if [ -L $(subst /, , $(dir $@)) ]; then\
mkdir -p `readlink $(subst /, , $(dir $@))`;\
else\
mkdir -p $(dir $@);\
fi
$(CXX) $(OBJECTS_RELEASE) -o $@ $(LDFLAGS_RELEASE)
# -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# subdir make calls
obj-debug/: FORCE | obj-debug/makefile
$(MAKE) -C $@ OBJECTS_BASE_DIR=$(realpath obj-debug) SOURCES_BASE_DIR=$(realpath src) CXX_OTHER_FLAGS="-g -O0 -DDEBUG"
obj-release/: FORCE | obj-release/makefile
$(MAKE) -C $@ OBJECTS_BASE_DIR=$(realpath obj-release) SOURCES_BASE_DIR=$(realpath src) CXX_OTHER_FLAGS="-O3 -DNDEBUG -DRELEASE"
# -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# objects dependencies
$(OBJECTS_DEBUG): obj-debug/
$(OBJECTS_RELEASE): obj-release/
# -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# main targets
debug: bin-debug/$(EXECUTABLE)
release: bin-release/$(EXECUTABLE)
clean: clean-debug clean-release
$(RM) -r doc
clean-debug:
if [ -L obj-debug ]; then\
$(RM) -r `readlink obj-debug`;\
fi
if [ -L bin-debug ]; then\
$(RM) -r `readlink bin-debug`;\
fi
$(RM) -r *.o *.d bin-debug obj-debug
clean-release:
if [ -L obj-release ]; then\
$(RM) -r `readlink obj-release`;\
fi
if [ -L lib-release ]; then\
$(RM) -r `readlink lib-release`;\
fi
$(RM) -r *.o *.d bin-release obj-release
doc:
doxygen