Skip to content

pogmat/small_build_utility

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Small Project Utility

The present bash script help to create makefiles for small C/C++ projects. The syntax is the following

./newproj -compiler name

where -compiler stands for

  • -gcc to build a C project with gnu compiler collection
  • -clang to build a C project with llvm compilers
  • -g++ to build a C++ project with gnu compiler collection
  • -clang++ to build a C++ project wht llvm compilers

The output is a folder named name and with the following files and subfolders:

  • src/: the source files
  • include/: the headers
  • build/: the objects (and the building rules, see below)
  • bin/: the executable
  • makefile: the makefile (see below)
  • .clang-format: the configuration file for clang-format

makefile description

The makefiles generated by the the scripts have the following options

variable description default
TARGET name of executable main
HEADS header files (without extension)
SRC source files (without extension)
LIBS libraries (-l and -L)
TDIR target directory bin/
IDIR header directory include/
BDIR object directory build/
SDIR source directory src/
HEADEXT header file extension C: h, C++: hh
SRCEXT source file extension C: c, C++: cc
OBJEXT object file extension o
TRGEXT target file extension x
RUNOPTIONS options argument to run target executable
C(XX) compiler (resp for C and C++) see above
C(XX)FLAGS compiler flags -Wall -Wextra [-g (debug) or -O2 -s (release)]
CPPFLAGS preprocessor flags -I $(IDIR) -MMD -MP
LDFLAGS linker flags -$(LIBS)

NOTE:

  • the preprocessor flag -I $(DIR) allows to write #include <file> instead of #include "file" even if file is an header
  • the preprocessor flags -MMD -MP make the compiler generate additional dependency rules (as .d files) that specify additional file that makefile has to compile for consistency reason. Suppose that in a certain mysource.c is included myheader.h; thanks to these rules the file mysource.c is compiled even if myheader.h is modified.
  • in the case of a default compilation debugging hooks are included -g, while for a final release optimization -O2 and strip -s is enabled

Compiling the project

Here are the option of makefile:

option explanation
none or all compiles the project
clean removes the target, the objects and the rules
run run the project with RUNOPTIONS
format formats the code using clang-format with the settings of .clang-format
release compiles the project without debug hooks and with optimization (see above)
valgrind execute valgrind --leak-check=full --track-origin=yes $(TDIR)/$(TARGET) $(RUNOPTIONS)

About

Simple shell script to manage simple C/C++ project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages