# Paper size for Sphinx LaTeX output (a4, letter, etc.)
SPHINX_PAPERSIZE ?= a4
+# Name of the build directory (to use when excluding some paths)
+BUILD_DIR_NAME ?= build
+
+# Directories to exclude from the build directory tree replication
+BUILD_DIR_EXCLUDE ?= $(BUILD_DIR_NAME) .git .hg .bzr _darcs .svn CVS
+
# Directories
##############
R := $(subst $T,,$(patsubst $T/%,%,$(CURDIR)))
# Base directory where to put variants (Variants Directory)
-VD ?= $T/build
+VD ?= $T/$(BUILD_DIR_NAME)
# Generated files top directory
G ?= $(VD)/$F
# Same as vexec but it silence the echo command (prepending a @ if $V).
exec = $V$(call vexec,$1,$2,$3)
-# Compile a source file to an object, generating pre-compiled headers and
-# dependencies. The pre-compiled headers are generated only if the system
-# includes change. This function is designed to be used as a command in a rule.
-# The first argument is the type of file to compile (typically "c" or "cpp").
-# What to compile and the output files are built using the automatic variables
-# from a rule. The second argument is the base output directory (typically
-# $O). You can add non-propagated object-specific flags defining a variable
-# with the name of the target followed with ".EXTRA_FLAGS".
+# Compile a source file to an object, generating pre-compiled headers (if
+# $(GCH) is non-empty) and dependencies. The pre-compiled headers are generated
+# only if the system includes change. This function is designed to be used as
+# a command in a rule. The first argument is the type of file to compile
+# (typically "c" or "cpp"). What to compile and the output files are built
+# using the automatic variables from a rule. The second argument is the base
+# output directory (typically $O). You can add non-propagated object-specific
+# flags defining a variable with the name of the target followed with
+# ".EXTRA_FLAGS".
+#
+# XXX: The pre-compiled headers generation is not very useful if you include
+# local files using #include <...>, because the system headers detection
+# is a little simplistic now, it just parse the source file and all its
+# dependencies searching for lines starting with "#include <" and
+# extracting the included files from them.
define compile
$(if $(GCH),\
$Vif test -f $2/$*.d; then \
$(call replace,$(PC_VARS),$*-PC-)
# Run doxygen to build the documentation. It expects the first prerequisite to
-# be the Doxyfile to use and the next prerequisites the input files. This rule
-# is a little restrictive, but you can always make your own if it doesn't fit
-# your needs ;)
+# be the Doxyfile to use and the next prerequisites the input files. You
+# can override Doxyfile configuration variables by defining a DOXYGEN_VARS
+# Make variable for this rule. For example, defining:
+# PROJECT_NAME := myproj
+# DOXYGEN_VARS := PROJECT_NAME
+# You can override Doxygen's PROJECT_NAME configuration option. Optionally, you
+# can define DOXYGEN_VARS_PREFIX too, to avoid polluting your Makefile with
+# Doxygen variables. For example:
+# DOXY.PROJECT_NAME := myproj
+# DOXYGEN_VARS_PREFIX := DOXY.
+# DOXYGEN_VARS := PROJECT_NAME
+# This rule might be still a little restrictive, but you can always make your
+# own if it doesn't fit your needs ;)
$D/%/doxygen-stamp:
$V mkdir -p $(@D)
$(call exec,(cat $<; \
echo "FULL_PATH_NAMES=YES"; \
- echo "INPUT=$(patsubst $(<D)/%,$(INCLUDE_DIR)/$*/%, \
- $(wordlist 2,$(words $^),$^))"; \
+ $(if $(filter INPUT,$(DOXYGEN_VARS)),,\
+ echo "INPUT=$(patsubst $(<D)/%,$(INCLUDE_DIR)/$*/%, \
+ $(wordlist 2,$(words $^),$^))";) \
echo "OUTPUT_DIRECTORY=$(@D)"; \
- echo "INCLUDE_PATH=$(INCLUDE_DIR)"; \
echo "STRIP_FROM_PATH=$(INCLUDE_DIR)"; \
echo "STRIP_FROM_INC_PATH=$(INCLUDE_DIR)"; \
- echo "QUIET=$(if $V,YES,NO)") | doxygen -,$(@D),doxygen)
+ echo "QUIET=$(if $V,YES,NO)"; \
+ $(foreach v,$(DOXYGEN_VARS),\
+ echo '$v=$($(DOXYGEN_VARS_PREFIX)$v)';) \
+ ) | doxygen -,$(@D),doxygen)
$V touch $@
# Run Sphinx to build the documentation. It expects the variable SPHINX_DIR
# subdirectories, that's why the current directory "." is included, so it
# won't show an error message in case of no subdirectories.
setup_build_dir__ := $(shell \
- mkdir -p $O $B $L $D $(INCLUDE_DIR); \
- mkdir -p . $(addprefix $O,$(patsubst $T%,%,\
- $(shell find $T -type d -not -path '$(VD)*'))); \
+ mkdir -p $O $B $L $D $(INCLUDE_DIR) $(addprefix $O,$(patsubst $T%,%,\
+ $(shell find $T -type d $(foreach d,$(BUILD_DIR_EXCLUDE), \
+ -not -path '*/$d' -not -path '*/$d/*')))); \
test -L $(VD)/last || ln -s $F $(VD)/last )