Helper Makefiles
All builds rely on a single set of helper Makefiles - they define common variables, directory paths, functions and rules.
These Makefiles reside under a single directory, whose location must be defined in a shell using the environment variable MAKEFILES_DIR. E.g., if you use tcsh, and place those Makefiles in /home/code/makefiles, then do: setenv MAKEFILES_DIR /home/code/makefiles The helper Makefiles are: build_type.mk This Makefile defines the build type and build directory name. 3 options are encoded: debug, release and profile. It assumes all builds are under a single directory named "build", with the type of build as a sub-directory. E.g., building a debug type, will be in directory named "build/debug". target.mk This Makefile is included during the first execution of the top-level Makefile (which is in the source directory). target.mk ensures the build directory exists (otherwise it is created), and then calls the top-level Makefile again, with the current directory being the build directory. Thus, the build occurs in the build directory and not in the source directory. common.mk This Makefile defines common variables, and includes 3 other common Makefiles: compile_options.mk This Makefile defines compilation options. file_extensions.mk This Makefile defines expected file extensions for source, header and executable files. macros_and_functions.mk This Makefile defines macros and functions used by other Makefiles. build_lib.mk and lib_target_rule.mk Together, these 2 Makefiles go through a list of source files, compile each into an object file, then pack them into a static library. build_obj.mk and obj_target_rule.mk Together, these 2 Makefiles go through a list of source files, and compile each into an object file. build_prog.mk and prog_target_rule.mk Together, these 2 Makefiles build a single executable from a source file, that contains the main() function. |
|