Coder Social home page Coder Social logo

makefilec's Introduction

The Makefile I wish I had for C Development Main

This is the summary of my experience applied to programming in C. My ambition is to put together all good practices and necessary features of a well-driven C project. I would like to include good compilation, sub-projects, static analyzers, and testing processes.

I want this makefile to be easy to use, easy to get started with and well-documented.

I have worked on this project on and off multiple times. Today, I don't code in C anymore, so I want to share the current state of this project. The initial goal of this project was very ambitious, and I let anyone use this Makefile if he/she finds it useful.

Ambition

The ultimate makefile must be intuitive, simple, configurable, easy to understand and finally and most importantlty practical.

Documentation

Getting Started

Basically you can copy/paste the whole content of the makefile into your project. You can then use make init in order to have a minimal viable project. This will create the minimal file you need in order to start your project.

curl -fsSL https://raw.githubusercontent.com/FauconFan/makefileC/master/Makefile -o Makefile
make init

Features

  • Support basic rules:
    • make or make all: build the binary
    • make clean: remove all binaries and generated files except the binary
    • make fclean: remove all binaries and generated files
    • make re: shortcut for make fclean && make all
  • Debug mode make debug and make redebug
  • Help command make help
  • Init command make init (when starting a new project only)
  • Verbose mode with VERBOSE=1 make VERBOSE=1 [target] (prints out meaningful commands)
  • Compile or recompile only if necessary (source files as well as header files)
  • If no file needs to be recompiled, nothing is done (no relink)
  • Progress status during (re)compiling (per file)
  • Multithread support (native makefile feature)
  • Out-of-source builds (the source and header directory is not altered in any way)
  • Configuration through a config file config.mk
    • Specify names of final binaries (release and debug)
    • Change compiler and flags (warnings, optimization, debug, standard, etc...)
    • Specify source, build, and include directories names
    • List all source files
  • Error handling
    • The config.mk file is missing
    • Missing variables
    • Unauthorized variables are defined
    • Specified files are missing
    • Presence of unspecified files

Things that I don't want:

  • Automatic tracking of source files
  • Automatic tracking of header files

This is the current state of this project management project.
A more precise list of feature and incoming features is done in a file called .todo.

Documentation of config.mk

In the config.mk file, some variables can be defined. We have two types of variables: necessary variables in order to make the makefile work properly, and optional variables with default values. Here is the exhaustive list:

Necessary Variables

Name Description
NAME Name of the release binary
NAME_DEBUG Name of the debug binary
BUILD_FOLDER Folder name for generated files
INC_FOLDER Folder name for header files
SRC_FOLDER Folder name for source files
SRC Exhaustive list of source files stored in SRC_FOLDER

Optional Variables

Name Description Default value
CC Compiler used clang
CFLAGS_COMMON Flags shared both for release and debug builds -Wall -Wextra -Werror -Weverything -pedantic -std=c17
CFLAGS_RELEASE Flags used for relase build -O2 -DNDEBUG
CFLAGS_DEBUG Flags used for debug build -O0 -DDEBUG -ggdb
LDFLAGS Library flags given to compiler such as '-L'
LDLIBS Library flags given to compiler such as '-l'

Available commands of make

Once all the necessary variables are available, a few commands are available:

$> make help
Usage: make [target]

Here is the list of targets:
  - make all                       Builds the release binary
  - make clean                     Removes generated files except binaries
  - make fclean                    Removes all generated files
  - make re                        Alias for "make fclean && make all"
  - make debug                     Same as "make all" except it uses debug flags
  - make redebug                   Alias for "make fclean && make debug"
  - make install                   Installs the binary/library on the system
  - make uninstall                 Uninstalls the binary/library from the system
  - make init                      Initialize the project (at start only)
  - make help                      Prints this message

  You can also provide two extra variables:
  - VERBOSE (default: 0):
      If enabled, meaningful commands are printed.
      A non-meaningful command is a print command, create directories, etc.
        ex: `make re VERBOSE=1`
  - NO_COLORS (default: 0):
      If enabled, no colors will be printed
        ex: `make help NO_COLORS=1`

makefilec's People

Contributors

fauconfan avatar

Watchers

 avatar

makefilec's Issues

Todo

When I started this project, I wanted this to be very useful with a lot of features. Then life happens, and I don't do any code in C anymore.
At the time, I kept all the dev process in a .todo file.
Feel free to read it. Of course, it would be nice to convert this file into a proper backlog. Since I'm not developing this project, this will stay like this.

If you happen to read this, leave me any feedback, it's always have to have some!

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.