makemake
Stimulus:
Whenever I start coding a new program, one of the most important things is the
Makefile. I always have to copy an existing makefile to the current directory
and then modify it to my new settings. Then, as I create new .h and .c files,
I always have to go in and edit the Makefile to reflect those changes. I
decided to automate this process with a single command, makemake, that you can
call at anytime that will create or update a Makefile in the current directory
with up-to-the-second results of the files contained in your directory. Thus,
I can create a new project directory and a new file.c, and then simply run
makemake and I will have a Makefile. I then create file2.h and file2.c and
then run makemake again and add those files to the Makefile. Programs like
this exist elsewhere, but I wanted the updating functionality, and also the
ability to control what the initial Makefile that is created looks like.
Description:
makemake is a utility that automatically generates a Makefile based on the
files residing in the current directory. Initially, it creates the Makefile
from the default Makefile here:
Makefile.template
You can modify the default file that makemake
will use to initially form the Makefile to any Makefile that you're comfortable
with. makemake will update the Makefile to reflect whatever .c, .C, .cpp, and
.h are in the current directory (or additional directories given on the command
line). Whenever new files are created, simply run makemake and it will update
the Makefile to reflect the new files.
Here is the basic usage of the program:
Usage: makemake [OPTION]...
Create a Makefile based on files in current directory.
-n name The name of the executable created by the Makefile.
-x file1 [file2] [...] Exclude file(s) from being included in the Makefile.
-m makefile The Makefile to use, overriding both the default and
the Makefile in current directory.
-h, --help Print help (this screen).
-d dir1 [dir2] [...] Add files in these directories to the Makefile as
well.
When the following update commands are issued, only those filetypes listed
will be updated. The default is all types.
-uc Update c files.
-uC, -Ucpp Update C or cpp files.
-uh Update h files.
For example, in a directory for a Hearts card game I created, the following
files exist:
Card.h Deck.h Player.h Game.h
Card.C Deck.C Player.C Game.C
and in that directory another directory, containers, containing:
list.C
By running the program (initially giving it the n argument for the program name
as it defaults to a.out), it creates a new Makefile:
[tommut@scoobs hearts]$ makemake -n hearts -d containers
[tommut@scoobs hearts]$ cat Makefile
PROG= hearts
CC= gcc
GCCFLAGS = -g
CFLAGS = -g
WARNFLAGS = -Wall -ansi
WARN_ADDITIONAL = -Wshadow
HFILES= Card.h Deck.h Player.h Game.h
CFILES=
CPPFILES= Card.C Deck.C Player.C Game.C containers/list.C
SOURCEFILES= $(CPPFILES) $(HFILES)
OFILES=$(CPPFILES:.C=.o) $(CFILES:.c=.o)
all: $(PROG)
SUFFIXES: .C .o
.C.o:
$(CC) -o $*.o -c $(GCCFLAGS) $(WARNFLAGS) $*.C
.cpp.o:
$(CC) -o $*.o -c $(GCCFLAGS) $(WARNFLAGS) $*.cpp
.c.o:
$(CC) -o $*.o -c $(GCCFLAGS) $(WARNFLAGS) $*.c
$(PROG): $(OFILES)
$(CC) -o $(PROG) $(OFILES)
clean:
rm -f $(OFILES) $(PROG)
View the source :
makemake.c