The above task can be accomplished with Make. In the same directory as my source create a file called "Makefile" with the contents:
main.o:main.C String.h
g++ -g -c -o main.o main.C
String.o: String.C String.h Stack.h
g++ -g -c -o String.o String.C
Stack.o: Stack.C Stack.h
g++ -g -c -o Stack.o Stack.C
revHW: main.o String.o Stack.o
g++ -o revHW main.o String.o Stack.o
All you need to do to build revHW when you make a change to the source is
type:
and Make will do the right thing.% make revHW
# 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
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.
You should do this anytime you add new source, or add/remove include dependencies in your source code.% make depend