# These variables should be provided by the includer Makefile:
# P should be the project name, mostly used to handle include directories
# T should be the path to the top-level directory.
-# C should be the path to the current directory.
+# S should be sub-directory where the current makefile is, relative to $T.
# Verbosity flag (empty show nice messages, non-empty use make messages)
# When used internal, $V expand to @ is nice messages should be printed, this
# Includes directory
INCLUDE_DIR ?= $G/include
+# Directory of the current makefile (this might not be the same as $(CURDIR)
+# This variable is "lazy" because $S changes all the time, so it should be
+# evaluated in the context where $C is used, not here.
+C = $T/$S
+
# Functions
############
# Find sources files and get the corresponding object names
# The first argument should be the sources extension ("c" or "cpp" typically)
# It expects the variable $T and $O to be defined as commented previously in
-# this file. $C should be defined to the path to the current directory relative
-# to the top-level.
-find_objects = $(patsubst $T/%.$1,$O/%.o,$(shell find $T/$C -name '*.$1'))
+# this file.
+find_objects = $(patsubst $T/%.$1,$O/%.o,$(shell find $C -name '*.$1'))
# Find sources files and get the corresponding object names
# The first argument should be the sources extension ("c" or "cpp" typically)
# It expects the variable $T and $O to be defined as commented previously in
-# this file. $C should be defined to the path to the current directory relative
-# to the top-level.
-find_headers = $(patsubst $T/$C/%.$1,$2/%.$1,$(shell find $T/$C -name '*.$1'))
+# this file.
+find_headers = $(patsubst $C/%.$1,$2/%.$1,$(shell find $C -name '*.$1'))
# Abbreviate a file name. Cut the leading part of a file if it match to the $T
# directory, so it can be displayed as if it were a relative directory. Take
# doesn't already exist.
symlink_include_dir = $(shell \
test -L $(INCLUDE_DIR)/$1 \
- || ln -s $T/$C $(INCLUDE_DIR)/$1 )
+ || ln -s $C $(INCLUDE_DIR)/$1 )
# Overrided flags
# Default rules
################
+# Compile C objects
$O/%.o: $T/%.c $G/compile-c-flags
$(call compile,c)
+# Compile C++ objects
$O/%.o: $T/%.cpp $G/compile-cpp-flags
$(call compile,cpp)
+# Link binary programs
$B/%: $G/link-o-flags
$(call link)
+# Link shared libraries
$L/%.so: override CFLAGS += -fPIC
$L/%.so: override CXXFLAGS += -fPIC
$L/%.so: $G/link-o-flags
$(call link,-shared)
+# Install binary programs
$I/bin/%:
$(call install_file,0755)
+# Install system binary programs
$I/sbin/%:
$(call install_file,0755)
+# Install libraries
$I/lib/%:
$(call install_file)