Giter VIP home page Giter VIP logo

genericmakefile's Introduction

Auto Versioning Makefile

This repository contains a generic makefile for use with small/medium C and C++ projects. This makefile project is forked from https://github.com/mbcrawfo/GenericMakefile but majorly addapted in the meantime. It allows for easy project setup without the need to create tedious build rules or dependency lists. In the test directory is a makefile configured to create an example executable which references the static library generated by the makefile in the root directory.

Features:

  • Automatically finds and compiles all source files within the source directory.
  • Compiles most recently modified files first, to hopefully find problems earlier.
  • Automatically generates dependecies as files are compiled, ensuring that files are correctly recompiled when dependecies have updated.
  • Includes configurations for normal (release) build and debug build suitable for GDB debugging (the debug is the standard build that is called with a 'make' command.)
  • Times the compilation of each file and the entire build.
  • Generates version numbers based on git or subversion tags (see below), which are passed the compiler as preprocessor macros.
  • Implements and includes a header file with a static PrintVersion function (see example in sources).
  • By default, builds in a "verbose" mode which allows you to see the full compiler commands being issued. By passing V=false to make, you can compile with only an output for the actions being performed.
  • Automatically added Build Date and Build Number Symbols which can be extracted from the generated lib or executable with the 'getVersion.sh' script included in this repository. Examples follow below.
  • Added stacked compilation support to enable a simple project build on multiple cores by make -f all [option]. There are multiple options available like clean, newd (= new debug) and newr (= new release).
  • Makefile now supports out of the box executables, static (.a) and shared (.so) libraries. All you need to change is the TYPE flag to one of the specified NAMES (TARGET_EXECUTABLE, TARGET_STATIC_LIB or TARGET_SHARED_LIB).
  • Added IGNORE_SOURCE flag. With IGNORE_SOURCE="old" each file, that contains old will be ignored.
  • SYMBOLIC_LINK_DIR is now optional. Just specify a directory for a symlink to be build in. If nothing is specified, no symlink will be created. Make sure to also specify the LIB_SYMLINK_DELTA flag, which has to contain the path from the SYMBOLIC_LINK_DIR to the project root (otherwise the created links won't work).
  • The DIST_INFO Variable can now be used e.g. for the SYMBOLIC_LINK_DIR. It contains information about the distribution and the current OS-Type (32 or 64 bit).
  • Supported make flags are:
    • clean - removes all compiled or generated data
    • release - builds an optimized release build of the project
    • debug - builds an gdb debuggable build of this project
    • all - builds both, debug and release
    • reset - resets build number
    • help - shows this overview

Versioning:

Tags should be made in the format "vMAJOR.MINOR.PATCH[-description]", where MAJOR, MINOR and PATCH are numeric. The following macros will be generated and passed to the preprocessor:

  • VERSION_MAJOR (int) - The major version number from the most recent tag.
  • VERSION_MINOR (int) - The minor version number from the most recent tag.
  • VERSION_PATCH (int) - The patch version number from the most recent tag.
  • VERSION_REVISION (int) - The number of commits since the most recent tag.
  • BUILD_NUMBER (int) - The build number, which is automatically increasing every time the project is linked.
  • BUILD_YEAR (int) - The year of the build date.
  • BUILD_MONTH (int) - The month of the build date.
  • BUILD_DAY (int) - The day of the build date.
  • BUILD_HOUR (int) - The hour of the build date.
  • BUILD_MIN (int) - The minute of the build date.
  • BUILD_SEC (int) - The second of the build date.

Examples:

How to add a versioned tag:

git tag -a v1.0.1 -m "Your tag message"

How to use the getVersion.sh

# to list all version information of all linked libraries included in libtest.a.
./getVersion.sh libtest.a
# lists only the version information of libtest.a itself.
./getVersion.sh libtest.a libtest.a

How to use the linked references in code

# Find all references:
# The file extention .a of static libraries is removed in the reference symbols.
objdump -t libtest.a | grep REF

# For usage of the additional linked REF symboles see test/src/main.cpp
extern char libtest_BUILD_NUMBER_REF;
std::cout << "Version: v" << (unsigned long) &libtest_BUILD_NUMBER_REF;

How to use the generated jversion.hpp header

# first of all you need to activate the option PRINTVERSION_HEADER := true in makefile.
____________
// Source code
#include "jversion.hpp"

void yourFunction()
{
    // Use the $(NAME) flag you defined in the makefile.
    JVersion::Name::PrintVersion();
}

How to use the different make flags

make clean
make clean debug
make clean reset debug
make clean reset release
make clean reset all
make install
make uninstall
...

If the makefile is not used in a git repository, or is in a repository with no tags, the version macros are not created.

Limitations:

  • Assumes GNU make.
  • Doesn't really support multiple types of source files in the same project.
  • Currently no full support for svn.
  • Only tested and adapted for Linux system and g++ and ar toolchain.

Thanks to mbcrawfo and his contributors:

  • My friend Jay and people on Stack Overflow for help with regex to parse the version info.
  • The residents of /r/programming for suggesting numerous tweaks and improvements.
  • For the support and help from Sebastian with this project and a lot of good improvement ideas.

genericmakefile's People

Contributors

jacknjo avatar mbcrawfo avatar alekratz avatar ctcchan avatar dbeecham avatar

Watchers

James Cloos avatar  avatar

Forkers

phord

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.