Automated Makefile Template 1.0
Make is a powerful tool that traditionally requires too much work from the programmer for even the most simple projects. It can, with a sufficiently complex make file, be made to do the most common tasks totally automatically. This is my work to create such a make file:
Download: project makefile template
makefile core
Features:
- Automatic backup of the most recent successful build
- Finds source files in the source directory, compiles and links them into a target
- Recursively searches the source directory for source files nested in sub directories, builds to a parallel hierarchy in object directory
- Creates a link named
run
to your executable for easy execution
- Will make backups of source on request
- Clears the terminal before performing a build (since the build may produce many error messages)
Setup:
When first using the makefile template you should put the "core" someplace where it can be referenced from all your projects. Also place a copy of the makefile project template in this location for reference. If you use an extension to your code files other then .c++
then you will need to change the variable EXT in the makefile core to reflect this. Finally, change your makefile template to have any defaults you would like and to refer to where your placed the makefile core.
When you begin using the makefile template on a new project you should set up the variables at the top of the file for your project. When specifying paths don't end them with a slash. Variables which may be set in the makefile are:
- SRC - the source directory
- OUT - the output directory for temporary files generated during making
- OBJS - destination of object files (the default is inside the OUT directory, which should normally be fine)
- BASE flags - the flags for the compiler and for the linker (LFLAGS) to use no matter what build is being done
- DEBUG flags - additional flags to use when making a debug compile
- FINAL flags - additional flags to use when making a final compile
- TARGET - the location and name of the executable to generate
Usage:
- make or make world - builds a debug version of your project
- make clean - removes any object files and the target executable, clears and re-lists directory
- make restore - restores the last build backup (moves current source directory to source.old)
- make run - same as make world, then it runs the program
- make final - makes a final build from scratch and wipes out objects files after (so they aren't used in a later debug build
- make backup - saves a backup of the current source directory with a time-stamp
Proposed Features:
- multiple source directories
- backup manipulation features (restore one, remove some)
- different target for final builds