WARNING: If you have a CMakeLists.txt associate with your project, you
shouldn't be mucking with the Makefile yourself.
Use cmake
to produce it instead!
The above task can be accomplished with make. In the same directory as my source create a file called "Makefile" with the contents (where "<TAB>" is a single TAB indentation; This is essential -- using spaces won't work):
All you need to do to build revHW when you make a change to the source is type:main.o:main.C String.h <TAB>g++ -g -c -o main.o main.C String.o: String.C String.h Stack.h <TAB>g++ -g -c -o String.o String.C Stack.o: Stack.C Stack.h <TAB>g++ -g -c -o Stack.o Stack.C revHW: main.o String.o Stack.o <TAB>g++ -o revHW main.o String.o Stack.o
and make will do the right thing.% make revHW
As before, you build revHW with "make revHW". In addition, "make clean" will remove the object files, executable, and auto-save files so you, so you can start with a fresh project directory.# some variables describing your program source # in most cases, you'll only need to edit these four variables PROGRAM = revHW HEADERS = String.h Stack.h SOURCES = String.C Stack.C main.C OBJECTS = main.o String.o Stack.o # some useful others that you may need to edit CC = g++ CFLAGS = -g LIBS = # name of this file MF = makefile .SUFFIXES: .o .h .C # ------------- Stuff you shouldn't have to change ------------------ .C.o: $(CC) $(CFLAGS) -c -o $*.o $< $(PROGRAM): $(OBJECTS) $(CC) -o $(PROGRAM) $(CFLAGS) $(OBJECTS) $(LIBS) clean: @rm -f *~ "#*" *.o $(PROJECT) depend: @echo 'updating the dependencies for:' @echo ' ' $(SOURCES) @{ \ < $(MF) sed -n '1,/^###.*SUDDEN DEATH/p'; \ echo '#' ; \ echo '# dependencies generated on: ' `date` ; \ echo '#' ; \ for i in $(SOURCES); do \ $(CC) -MM $(CFLAGS) $(DEFINES) $$i ; \ echo; \ done \ } > $(MF).new @mv $(MF) $(MF).last @mv $(MF).new $(MF) ##################### EVERYTHING BELOW THIS LINE IS SUBJECT TO SUDDEN DEATH... # # dependencies generated on: Wed Apr 2 23:23:09 PST 1997 # String.o: String.C String.h Stack.h Stack.o: Stack.C Stack.h main.o: main.C String.h
You should do this anytime you add new source, or add/remove include dependencies in your source code.% make depend
C-q
<TAB>
to insert a real tab. (C-q
means "literally give me whatever I type next; don't do any
fancy-pants interpreting of my intention.) Second, use M-x
tabify
. This converts any sequence of consecutive spaces
in the region long enough to be a tab into a tab. To do this to your
whole document, try typing M-x <
then M-x >
then M-x
tabify
. (That should select your whole document and then
tabify it.)