#------- Sample Makefile ------------------ # Author: Ryan M. Graham <ryan_graham@nvmarine.com> # Updated by: Gavin Mogan <halkeye@halkeye.net> # - Included auto-dependancies # # comments: # This is a decent template for simple # Makefiles you may wish to use for your # C++ or other assignments # usage: # `make' - compiles the project # `make clean' - removes object (.o) files # `make neat' - runs all source files # through indent (reasonable flags) # `make touch' - updates timestamps and/or # creates empty files if none exist # `make tarball' - creates a tarball backup # of all the project files # `make depend` - creates a dependancy file # `make realclean` - deletes files and dependancy file #---- Variables --------------------------- # set the following variables to match your # project # # PROJECT: project name, used for naming the # tarball backup # EXECUTABLE: name of the executable to make # VERSION: executable version. used in the # tarball name. can be any string # you might find useful # OTHER: any other non-header, non-source files # that you want to archive # LIBS: if this project uses pthreads, put # -pthread here. Also include any other # libraries you know you need. # CXX: g++ if you are using C++ # gcc if you are using C # CXXFLAGS: compiler flags to use (-O2, -Wall, # etc..) # INDENT: the name of the code beautifier you # wish to use (indent is good) # INDENT_FLAGS: the flags you want to pass to # the program specified by INDENT PROJECT = unknown EXECUTABLE = $(PROJECT) VERSION = 0.0.2 CXX = g++ INCLUDEDIR = CFLAGS = -O2 -DVERSION=$(VERSION) -pedantic -Wall -W LIBS = -lcrypt -lm TAR_DIR = $(PROJECT)-$(VERSION) INDENT = indent INDENT_FLAGS = -ts3 -nut -bap -bli0 -di10 -l78\ -lp -nbc -i3 -sc -cdb -c1 -cd1 # you should probably leave these alone # unless you know what you are doing # NOTE: I don't understand these completely #---- Suffix Rules ------------------------ # All the .cc files SOURCES = $(wildcard *.c) # All the .cc files HEADERS = $(wildcard *.h) # And the corresponding .o files OBJECTS = $(SOURCES:.c=.o) # The good stuff #---- File Dependencies ------------------- all : $(EXECUTABLE) depend $(EXECUTABLE) : $(OBJECTS) $(CXX) $(INCLUDEDIR) $(LIBS) -o $@ $(OBJECTS) # removes .o files # updates when Makefile is updated clean : rm -f $(OBJECTS) # "realclean" removes everything that's been built. realclean: clean rm -f $(OBJECTS) .depend $(EXECUTABLE) # runs the source files through INDENT neat : $(INDENT) $(INDENT_FLAGS) $(SOURCES) $(SOURCES) # create empty files/update timestamps of project # listed in the HDR, SRC, and OTHER variables. touch : touch $(HEADERS) $(SOURCES) $(OTHER) # create a tarball (.tar.bz2) of the important files tarball : mkdir $(TAR_DIR) cp $(SOURCES) $(HEADERS) $(OTHER) $(TAR_DIR) tar czf $(PROJECT)-$(VERSION).tgz $(TAR_DIR) rm -rf $(TAR_DIR) # create a tarball (.tar.bz2) of the important files bzip : mkdir $(TAR_DIR) cp $(SOURCES) $(HEADERS) $(OTHER) $(TAR_DIR) tar cjf $(PROJECT)-$(VERSION).tar.bz2 $(TAR_DIR) rm -rf $(TAR_DIR) # This is the actual dependency calculation. .depend: $(SOURCES) $(HEADERS) rm -f .depend # For each source, let the compiler run the preprocessor with the -M and -MM # options, which causes it to output a dependency suitable for make. for source in $(SOURCES) ; do \ $(CC) $(INCLUDEDIR) $(CPPFLAGS) -M -MM $$source >> .depend ; \ done # Include the generated dependencies. # somehow this uses CXXFLAGS.. i donno how ifneq ($(wildcard .depend),'') include .depend endif # Tell make that "all" etc. are phony targets, i.e. they should not be confused # with files of the same names. .PHONY: all clean depend realclean touch neat tarball bzip