stffrdhrn / makefile

Single-file makefile include that allows defining C++ makefiles with simple variable assignments.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Makefile.mk

Single-file makefile include that allows defining C++ makefiles with simple variable assignments.
Can be used for building binaries, shared/static libraries, and unit tests (auto-execute when building). See Makefile.mk comments for variable parameters and standard targets.

Feature summary

  • Can define up to 99 binaries, 99 libraries, and 99 unit tests in the same makefile
  • Built object files are placed together in a build directory
  • Dependency files are automatically generated to insure re-compilation for source changes is handled correctly
  • Makefile value changes are automatically detected and will always insure everything is compiled correctly without requiring a 'make clean' to remove old object files
  • Multiple build environments are supported:
    • 'release' - default, build with full optimizations
    • 'debug' - build with minimal optimizations and enable debug flags (output binaries will have '-g' suffix)
    • 'gprof' - optimized build with added profiling options enabled ('-pg' suffix added to output binaries)
  • Single configure option to switch compilers (gcc & clang are both currently supported)
  • Binary/library output defaults to makefile directory but an optional output directory can be configured
  • Simple configure option to allow building with various 3rd party libraries (run 'pkg-config --list-all' to see what packages your system supports)
  • Default options for all compiler flags (warnings, optimizations, etc.) are provided. These default values can either be overridden or extended by config options (See Makefile.mk for all config settings)

Makefile usage example

# Simple binary builds
BIN1 = example1
BIN1.SRC = file1.cc file2.cc file3.cc

BIN99 = example2
BIN99.SRC = file4.cpp

# Shared & static library build (will output both libexample.so,libexample.a)
LIB1 = libexample
LIB1.SRC = libsrc.cc file4.cpp
LIB1.TYPE = shared static

# compile flags applied to all binaries
FLAGS = -pthreads -flto
# add package specified compile/link flags (as defined by pkg-config)
PACKAGES = freetype2
# extra warning flags (in addition to default flags)
WARN_EXTRA = -Werror
# use specific C++ standard instead of compiler default
STANDARD = c++14

# include must be at end
include Makefile.mk

About

Single-file makefile include that allows defining C++ makefiles with simple variable assignments.

License:MIT License


Languages

Language:Makefile 100.0%