Makedefault - don't bother writing makefiles

Tired of writing makefiles? Makedefault is a ruby script which compiles a set files given in the current directory and creates either a single object file containing all code, or a single executable. The script automatically creates a makefile based on the sources in the current directory. It uses the compiler to search for dependencies in your sources and includes them into your makefile.

Managing several projects depending on different and possibly overlapping sub projects can be done with makeexecutable.

Manual

Usage of the program is simple: just call makedefault in the directory containing the sources and give the name of the target object file, or the target executable name. The -e option must be given if an executable shall be created. Further arguments make it possible to provide compiler flags and/or linker flags. Compiler flags and linker flags are separated by a comma.

Usage:

makedefault [-e] target_name c-option1 c-option2 ... , l-option1 l-option2

Examples:

makedefault imagemodule.o -Wall -O3 
compiles all source files in the current directory into a single object file called 'imagemodule.o' and applies the compiler flags "-Wall -O3" on each file, and
makedefault -e imagetool -Wall -O3 , -lm -lstdc++ -ljpeg

compiles all source files in the current directory into a single executable called 'imagetool' and applies the compiler flags "-Wall -O3" on each file, as well as the linker linker options "-lm -lstdc++ -ljpeg" during the linking phase.

Graphical user interfaces using the QT library are supported in that the meta object compiler 'moc' is automatically called on every C++ file containing QT objects.

Makeexecutable

Let's suppose you have a large collection of C++ source files which compile into several executables. Each executable depends on a couple of sub projects, and executables may share sub projects. And now suppose that you want to give the sources of one of the executables to somebody, but you want to minimize the sources deployed to the absolute minimum. How do you know which sub project is used by which executable, and how do you avoid, while developing, to accidently include a file of sub project which you did not consider being a part of the executable?

Makeexecutable is a ruby script which easily manages the dependencies between sub projects using a small text file. When compiling, it configures the compiler path such that for each executable the compiler only 'sees' the sub projects which it is supposed see.

Example:
Let's suppose that you have two executables: 'mrftool' which depends on sub projects 'Image', 'Math', 'ImageProc' and 'MRF', and 'mctool' which depends on 'Image', 'Math', 'ImageProc' and 'MC'. The sub project 'ImageProc' itself depends on 'Image' and 'Math'. In this case, create sub directories for each module and for executable, and put the respective sources in the respective sub directory. The dependencies can be captured in a dependencies file as follows:

[DEPENDENCIES_ON_MACROS]

[DEPENDENCIES_ON_MODULES]
Image
Math
ImageProc	Image Math
MRF
MC
mrftool		ImageProc MRF
mctool		ImageProc MC

Assumining the dependency file is called 'DEPENDENCIES', compilation of the executables can be done with a single call the makeexectuable script:

makeexecutable mrftool $HOME/bin/mrftool -Wall -O3 , -lm -lstdc++ -ljpeg

and

makeexecutable mctool $HOME/bin/mctool -Wall -O3 , -lm -lstdc++ -ljpeg

The first argument specifies the name of the sub project containing the executable, the second argument the target installation path, and the rest of the arguments contain the compiler flags and linker flags (see the manual for makedefault). The script will automatically build all depending sub projects (Image, Math, ImageProc, MRF) and link them to the mrftool sources.

When a header file is included from a sub project, giving the full path should be avoided. For instance, instead of writing #include "../Image/Image.h", write #include <Image.h>. Makeexecutable will automatically add compiler flags which will allow the compiler to find all files on which depends the executable. This way, you will never additentally add and include statement for a file without being aware that your executable depends on this file.

Download

No setup is necessary. Just download the package, extract all files and put them into a directory which is in the PATH of your shell. Just be sure that the ruby shell is available as /usr/bin/ruby, else create a link or change the first line of each script (see requirements).
tool version date downloadremark
makedefault.tgz 2.01 12.03.2008 httpCurrent stable version

Requirements

Ruby

makedefault and makeexecutable are completely written in the ruby programming language, so you need to have the ruby runtime package installed. Ruby comes with most Linux distributions. To install it on Fedora or Red Hat distributions type "yum install ruby". Ruby can be downloaded for a wide range of systems here.

Compiler

The compiler needs to support the -M option which determines the dependencies of a source file.

Credits

Makedefault and makeexecutable was written by Christian Wolf. Send comments, suggestions and bug reports to the follwing address:

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.