Skip to content

a makefile template that is ready to be used with least amount of configuration

Notifications You must be signed in to change notification settings

demon36/cpp-makefile-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

cpp-makefile-template

this is a makefile that aims towards letting you build a linux c++ project with the least amount of configuration

usage examples:

make init creates the basic directory structure shown below

make shared BUILD=release builds source files in ./src with -O3 into a stripped shared object file in ./lib directory with separate debug symbols in a .dbg file

make static builds source files in ./src into a static archive in ./lib directory with debug symbols included

make exec BUILD=debug builds source files in ./src into an executable in ./bin directory with debug symbols included

make test builds source files in ./test into an executable that is linked against the first shared/static lib file it finds in lib directory

make run runs the output test executable

make run BUILD=coverage builds test sources with --coverage flag, run tests, generates web report in ./doc and opens it using system default web browser

features

  • automatic header dependency generation
  • source directories nesting support for ./src and ./test
  • Linux library versioning, usage: edit MAJOR_VERSION & MINOR_VERSION
  • 32/64bit builds support, usage: make ARCH=32, make ARCH=64 -default is system arch-
  • 3 types of builds:
    • debug: default build
    • release: has -O3 optimization level and separate debug symbols with debug link in elf file
    • coverage: output binaries generate coverage reports in html directory (lcov package required for that)
  • rpath set to $ORIGIN by default
  • library/executable file names are determined from project directory name

example directory structure

libtest
|
├── makefile
|
├── src
│   └── TestModule.cpp
|
├── include
│   └── TestModule.h
|
|── test
|    └── major_tests.cpp
|
├── dep --generated--
│   ├── src
│   │   └── TestModule.cpp.dep
│   └── test
│       └── major_tests.cpp.dep
|
├── obj --generated--
│   └── 64
│       └── debug
│           ├── src
│           │   └── TestModule.o
│           └── test
│               └── major_tests.o
|
├── lib --generated--
│   └── 64
│       └── debug
│           ├── libtest.so.0 -> ./libtest.so.0.1.9
│           └── libtest.so.0.1.9
|
├── bin --generated--
│   └── test
│       └── 64
│           └── main_test
|
├── cov --generated by coverage target--
|
└── docs
    └── mydoc.md

todo

  • make use of pkg-config
  • support nested local deps
  • add install target
  • support more architectures
  • support packaging via fpm

About

a makefile template that is ready to be used with least amount of configuration

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published