Code Monkey home page Code Monkey logo

mymakefile's Introduction

MyMakefile

MyMakefile is a central build system based on GNU Makefile for compiling my GitHub C++ projects for Linux, Mac OS X, Emscripten and ExaequOS (and certainly for Windows) architectures. To be used for upset people against CMake like me. The aim of MyMakefile is to reduce the number of lines to type for my Makefiles by avoiding duplicating the same boring code over all my projects and therefore to make all my Makefiles consistent.

Write in few lines of Makefile by including in your project two files containing all the complex cookery rules for compiling files, generating shared/static lib, generating pkg config, creating MacOX bundle application, generating documentation, runing code coverage, compilation flags, installing on your system ... is already made for you. You can still extend rules!

Here, the list of my personal projects using the branch version-2 as git submodule:

Here, the list of my personal projects using the branch version-1 as git submodule:

Why do I care using this project?

Or maybe: "why not simply using CMake instead of this project?" CMake is, after all, a Makefile generator and architecture agnostic! The answer would be "maybe yes for big projects", but I personally never liked CMake for its syntax, obscure function names and specially for generating Makefiles containing more lines than an hand-made equivalent, especially for small projects such as mines.

In the case, for your personal projects, you are not bored by CMake syntax or not interested with deadling with Makefile rules, you may be interested in this project. Two choices:

  • simply copy/paste this repo inside your project.
  • or better, use it as a git submodule to track my evolutions.

MyMakefile API

WIP: See this document.

MyMakefile Features

MyMakefile allows you to:

  • Each Makefile allows you to define a binary target and/or a static/shared library target for Linux, OS X, Windows.
  • In the case of your target is a library, a pkg-config file is automatically created.
  • Define macros for installing your program, its resources, docs, libraries, include files, pkg-config inside your OS in the case you want a make install rule. By default a minimal installation rules is offered installing applications, libraries, pkg files, header files, doc and data.
  • Define by default plenty of compilation flags for GCC and clang compilers to have plenty of warnings. Some are made for hardening your binary or striping your release binaries.
  • Enable/disable the good optimization flags (-Ox) as well as enabling/disabling asserts (NDEBUG) depending on if your project is in debug or release mode. If you do not like my default compilation/link flags, you can replace them by yours. If you do not like the default compiler, you can tell your own.
  • In debug mode, add automatically a stack trace for helping you fixing segfaults.
  • In debug mode, offer debug printf macros.
  • Offer rules such as gcov (code coverage report), Coverity Scan (static analyzer of code), doxgen (documentation generator), asan (AddressSanitizer), check for a hardened target.
  • Generate a C++ header file with your project information (version, SHA1 ...) that can be used in a logger.
  • Generate a Doxygen file with project parameters (such as project name, version ...). The generated HTML follows the theme used by the library SFML which is more proper than the default Doxygen theme.
  • Have a rule for compressing your project (without .git or generated documentation) in a tar.gz tarball with the date and the version. Names collision of tarballs is managed.
  • Auto-generate the Makefile help by parsing your comments placed before rules.
  • Work with parallel builds (-jX option, where X is the number of your CPU cores).
  • Hide by default all these awful lines made of GCC compilation flags. Colorful information messages are displayed instead with the percentage of compiled files (in the way of the CMake progress bar).
  • Create a build directory where compiled files are placed, instead of being created within source files.
  • Generate .d files inside a build directory holding dependencies files (when one header file is modified, dependent source files are also compiled).
  • For MacOS, you have option for obtaining bundle applications.

Current constraint:

  • Currently, you have to define a single target by Makefile file (for example a library and its demo application). This can be easily bypassed as shown in examples given in this document by adding a makefile in a separate folder (source, lib, demo, tests, ...). A WIP solution which both fix and reduce the code is in gestation in the git branch dev-multitargets.

Prerequisites:

You have to install:

  • a bash interpretor since some Makefile code cannot be directly called.
  • the basic calculator bc tool: apt-get install bc needed for the progress bar (if not present the compilation does not fail but the percent of progress is crapped).
  • if needed, install tools that can be called by MyMakefile: gcov, doxygen, hardening-check: apt-get install gcovr doxygen devscripts.

How to compile for ExaequOS ?

ExaequOS is a new project: a fork of Emscripten for managing posix features such as forks, signals, tty, Wayland and more ...

  • Install the ExaequOS Docker image. Follow instructions https://github.com/Lecrapouille/docker-exa
  • Go to your project using MyMakefile.
  • Run the ExaequOS Docker image against the folder holding your project.
  • Simply call make! Your project will compile like if you were compiling a Linux application. Do not worry about Emscripten compiler. All is hidden for you!
  • Once compiled, call make install.
  • Open you favorite browser to the URL https://www.exaequos.com/
  • Run Havoc, the ExaequOS console and type /media/localhost/<my-application> where <my-application> has to be changed for your application name.

mymakefile's People

Contributors

lecrapouille avatar

Stargazers

 avatar

Watchers

 avatar  avatar

mymakefile's Issues

WIP version 2

  • Comment simplifier les TU qui en general reprend celui du Makefile principal => utiliser INTERNAL_LIB ?
  • Finir API.md + README
  • Ajouter rpath
  • pkg config générés les noms des libs ne sont pas mises en minuscules quand l'option est demandé
  • INTERNAL_LIBS vs. THIRDPART_LIBS
  • make install + INSTALL_PROJECT_HEADERS => appellé plusieurs fois.
  • INTERNAL_LIBS on entre inutellement plusieurs fois dans les memes dossiers/Makefiles: messages rendondants, installation inutiles ... Idee: avoir une liste de Makzfiles visités.
  • make check KO
  • Gerer/distinguer/chercher automatiquement DIRS_WITH_MAKEFILE dont on depend (libs) de DIRS_WITH_MAKEFILE de tests et dont on veut faire un seul make clean
  • Ajouter une regle pour downloader et compiler 3parts
  • Repenser cloning 3parts avec un SHA1
  • rwildcard avec la regexp * ne permet pas de distinguer les fichiers des dossiers.
  • ar cr pas propre: virer les "../../build-release/objs" r - ../../build-release/objs/TimedPetriNetCore/src/Net/Algorithms.o
  • Progress bar doit compter les fichiers à recompiler plutot que l'ensemble "[89%] Compiling C++ TimedPetriNetCore <= /home/qq/MyGitHub/TimedPetriNetEditor/src/Utils/Path.cpp"
  • make install avec Emscripten/ExaequOS recompile le project => vient du soucis des dependances (dossiers ?)
  • emscripten en debug => du sens ? Oui d'apres Benoit
  • rwildcard ne marche quand on donne plusieurs dossiers
  • - Bug make install avec des ../.. => ajouter abspath + wildcard
  • pkg config: faut il ahouter le noms des libs internes ? INTERNAL_LIBS

Create static libs from other thirdpart static libs not working

https://github.com/sebastiandev/zipper/tree/v2.x.y

THIRDPART_LIBS += \
    $(abspath $(THIRDPART)/zlib-ng/build/libz.a) \
    $(abspath $(THIRDPART)/minizip/build/libaes.a) \
    $(abspath $(THIRDPART)/minizip/build/libminizip.a)

does not work.

nm '/home/qq/MyGitHub/zipper/build/libzipper.a.2.0.0' | grep crc32
                 U crc32

I have to do:

cd build
ar -x /home/qq/MyGitHub/zipper/external/zlib-ng/build/libz.a
...

This extract all .o files and then have to link back all files.

Add INTERNAL_LIBS

Same than THIRDPART_LIBS (list of static/shard files) but used as dependencies therefore the list shall be added inside pkgconfig files

WIP version 1

TODO:

  • download thirdpart since we usually follow their HEAD: log SHA1 of their HEAD since thirdpart can evolve and breaking API. Keep a trace.
  • !!! IMPORTANT: manage multiple targets by project !!!
  • !!! make CXX=clang++-7 or emmake make always redo compilation from scratch ! Why ? !!!
  • SimForth: how to compile shared libs and target at the same time. idea replace OBJS by LIBS.
  • !!! IMPORTANT: disable debug and/or backward when compiling library or add -ldw !!! else backward segfault"
  • !!! compile library + in debug mode: add -debug libfoo-debug.so
  • Take into account CWEB
  • Take into account emscripten
  • Add bash script checking PKG_LIBS and SYSTEM_LIBS in thirdpart libs
  • Add bash script checking compilation flags: gcc $ALL_FLAGS foo.c => parse compilation flag not detected. Not not use them
  • The Makefile for unit tests cannot know TARGET of the main project. In the same idea: Makefile for compiling examples cannot know the name of the lib or the target of the main project.
  • Where to install .pc files ? /usr/share/pkgconfig/ or /usr/lib/pkgconfig ?
  • Cannot multiple inclusion of config.hpp** (first attempt failed)
  • Generate a config.hpp file (instead/in addition of a version.h file)
  • Rename RULE_INSTALL_DOC to RULE_INSTALL_PROJECT and change Installing: doc => /usr/share/xxx/0.1 to Installing: project => /usr/share/SimForth/0.1
  • Make shared VPATH and INCLUDES between all Makefiles. Won't do: Use Makefile.common.
  • http://make.mad-scientist.net/papers/how-not-to-use-vpath/ (ok: my VPATH if including BUILD is ok because of generated files stored here. ie version.h)
  • add rules for compiling libraries and pkg-config
  • LDFLAGS vs EXTERNAL_LIBS: when linking order of static lib is important (ie GL vs GLFW)
  • Make the file VERSION be optional (won't do)
  • Add an option for verbosing Makefile
  • Todo INCLUDES += pkg-config --cflags XXX EXTERNAL_LIBS += pkg-config --libs XXX vs. CXXFLAGS += pkg-config XXX LDFLAGS += pkg-config --libs XXX
  • Rethink g++/clang flags
  • misplacement of Makefile.header Makefile.common (not the same for all projects + variables can be hidden like STANDARD = --std=c++14) (WIP)
  • version.sh: Generate BUILD_TYPE in version.h (needed for example by loggers)
  • Missing flags: -Wsign-conversion -Wformat -Wpessimizzing-move

Bugs:

  • !!! Bored of external/backward not always installed ar the root of the project.
  • MYMAKEFILES := depends on Makefile.common but this should be an optional file
  • Fix typo "not" in "You are not replacing recommended CXXFLAGS by your flags"
  • Remove $(P) of THIRDPART ?= $(P)/external => THIRDPART ?= external this fuck up VPATH. !!! IMPORTANT:Ask why on stackoverflow !!!**
  • Auto install backward when building in debug mode:
    $(THIRDPART)/backward-cpp/.git/config:
    mkdir -p $(THIRDPART) &amp;&amp; cd $(THIRDPART) && git clone https://github.com/Lecrapouille/backward-cpp.git --depth=1 > /dev/null 2> /dev/null

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.