The best place to start is actually with the documentation. Since you are using GNU tools, you might as well stick with GNU Make -- which is superior to other Make tools in many ways.
Your choice of variable names could be improved.
In particular, your MYLIBRARIES
variable is dangerous -- because at some point you'll want to do something like
(That is, you'll list more than one library, like FLTK and the C math library.) This will produce a command line terminating in:
which is erroneous (obviously). Instead, list the libs directly:
LDFLAGS = -lfltk -lm
The same thing can be said of MYINCLUDES
. When you are done, you should see something like:
$(CC) $(CFLAGS) $(SOURCE) -o octhecdec $(LDFLAGS)
You should avoid trying to use a variable in the name of a pattern target -- like $(MYPROGRAM). Since the purpose of the makefile is to compile a specific program, there is no need to put the program's name in a variable.
The typical form for a make file is something like:
CC = g++
CFLAGS = -I/home/scale/g++Projects/gLib/
LDFLAGS = -lfltk
all: octhecdec clean
$(CC) -o $@ $^ $(LDFLAGS)
octhecdec.o: octhecdec.cpp octhecdec.h
$(CC) -c $(CFLAGS) $<
.PHONY: clean cleanest
Certain things have special meaning:
name of the target
name of all prerequisites with duplicates removed
name of the first prerequisite
Notice that the first rule after 'all' was to link the program from the compiled object files. The other rule (or rules
if more than one object file is involved) simply compile individual object files. And the phony targets 'clean' and 'cleanest' get rid of leftover stuff. Notice how the 'all' target builds the program then gets rid of everything except the final executable? Whether or not this is done is up to you... some hate it, others prefer it. (In general, the point of a makefile is not
to do that... so that only the object files that actually need recompiling are recompiled.)
If you all want to see it, I wrote a simple "Make Anything Makefile" for use at Rutgers (using GNU Make and Grep) a while back... It is pretty interesting in how it works. Let me know if you want to see it.
Hope this helps.