# This sample Makefile allows you to make a OpenGL application # whose source is exactly one .c file. # # # To use this Makefile, you must type: # # make xxxx # # where xxxx.c or xxxx.cc is the name of the file you wish to compile # This Makefile works because the default makefile rules include several # magic variables that are used during processing, like this: # $(CC) $(CFLAGS) $(CPPFLAGS) # Therefore, all we really need to do is define some variables. This is # really cool! # Makefile written by Scott D. Anderson 8/30/2000 # Fall 2004, Modified to use libnetpbm, Fall 2004 # Fall 2005, Modified to substitute libppm for libnetpbm # Summer 2006, Modified to add Nate Robbins's glm library # Fall 2006, many modifications to add phony targets, such as targets to build # demos, tutors and so forth # Here's where the TW stuff lives. For installation, using PWD is fine, # since we assume you're in the directory containing this file. (That's # the assumption in the INSTALL directions.) If you want to use this # Makefile from other directories, say via the alias, you'll have to have # the correct environment variable defined. You can define TWHOMEDIR in # your ~/.bash_profile or wherever you like. SHELL = /bin/bash #TWHOME = /home/cs307/public_html/tw TWHOME = $(shell if [ "x${TWHOMEDIR}x" != "xx" ]; then echo "${TWHOMEDIR}"; else echo "${PWD}"; fi) NETPBMINSTALLED = $(shell if [ `uname -s` = 'Linux' -o -e '/opt/local/lib/libnetpbm.dylib' ]; then echo "yes" ; else echo 'no'; fi) # ================================================================ # Some of the following Makefile coding is borrowed from the Lejos software. # OSTYPE is not set by default on Mac OS X. Should end up being "darwin" ifndef OSTYPE OSTYPE = $(shell uname -s|awk '{print tolower($$0)}') #export OSTYPE endif # These magic variables (LOADLIBES and LDLIBS) are used during linking; I # don't know the distinction, but I'm using the first for my object files # and the second for libraries. If you want to omit the glm or # /f05/objects.o, just define this environment variable outside the # Makefile (say in your own ~/.bash_profile). ifndef LOADLIBES LOADLIBES = $(TWHOME)/lib/tw.o $(TWHOME)/lib/glm.o $(TWHOME)/f05/objects.o $(TWHOME)/f06/objects.o $(TWHOME)/f07/objects.o #LOADLIBES = $(TWHOME)/lib/tw.o $(TWHOME)/lib/glm.o #LOADLIBES = $(TWHOME)/lib/tw.o endif # Redhat is using the libppm package, but Fedora has changed to netpbm, so # if you want the Redhat behavior, you have to define an environment # variable called PPM with the value ppm. There seems to be an # implementation of netpbm for Darwin. PPM can't be used, because the # function ppm_allocrow doesn't exist. There is a pm_allocrow, which might # be an acceptable substitute, but I just don't care that much. # This CFLAGS variable is used during compiling C programs, and CXXFLAGS # for compiling C++ programs. The -DMAC compiler flag is for the # conditional compilation of which include files to use. The -DNETPBM # comments out code that relies on netpbm for platforms that don't have # it. On the Mac, the ppm.h file lives in /opt/local/include ifeq ($(OSTYPE),linux) CFLAGS = -g -I/usr/X11R6/include/ -I$(TWHOME)/ -DNETPBM CXXFLAGS = $(CFLAGS) LDLIBS = -L/usr/X11R6/lib -lglut -lGL -lGLU -lXmu -lXi -lX11 -lm -lnetpbm endif ifeq ($(OSTYPE),darwin) ifeq ($(NETPBMINSTALLED),yes) CFLAGS = -g -I/usr/X11R6/include/ -I$(TWHOME)/ -DNETPBM -I/opt/local/include -DMAC CXXFLAGS = $(CFLAGS) LDLIBS = -lm -framework OpenGL -framework cocoa -framework glut -L/opt/local/lib/ -lnetpbm else CFLAGS = -g -I/usr/X11R6/include/ -I$(TWHOME)/ -DMAC CXXFLAGS = $(CFLAGS) LDLIBS = -lm -framework OpenGL -framework cocoa -framework glut endif endif # ================================================================================ # Special stuff for the TW stuff .PHONY: all tw demos tutors demosall demosinfo info demodistrib cleandemos alias all: tw demos tutors f05_demos f06_demos f07_demos # ================================================================ # making the libraries TWLIB = lib/tw.o $(TWLIB): src/tw.cc src/tw-bounding-box.cc src/tw-camera.cc src/tw-color.cc \ src/tw-fonts.cc src/tw-geometry.cc src/tw-keyboard.cc src/tw-lighting.cc \ src/tw-menu.cc src/tw-messages.cc src/tw-mouse.cc src/tw-objects.cc \ src/tw-textures.cc src/tw-window.cc src/tw-wrappers.cc g++ $(CFLAGS) $(CPPFLAGS) -c src/tw.cc -o $(TWLIB) chmod a+r $(TWLIB) GLMLIB = lib/glm.o $(GLMLIB): glm/glm.cc g++ $(CFLAGS) $(CPPFLAGS) -c glm/glm.cc -o $(GLMLIB) chmod a+r $(GLMLIB) F05_LIB = f05/objects.o $(F05_LIB): f05/objects.h f05/objects.cpp g++ $(CFLAGS) $(CPPFLAGS) -c f05/objects.cpp -o f05/objects.o chmod a+r f05/objects.o F06_LIB = f06/objects.o $(F06_LIB): f06/objects.h f06/objects.cpp g++ $(CFLAGS) $(CPPFLAGS) -c f06/objects.cpp -o f06/objects.o chmod a+r f06/objects.o F07_LIB = f07/objects.o $(F07_LIB): f07/objects.h f07/objects.cpp g++ $(CFLAGS) $(CPPFLAGS) -c f07/objects.cpp -o f07/objects.o chmod a+r f07/objects.o TWBINS = bin/show-object-natural bin/show-object-unitized bin/show-texture bin/tw-which tw: $(TWLIB) $(GLMLIB) $(F05_LIB) $(F06_LIB) $(F07_LIB) $(TWBINS) @echo Done making $(TWLIB), $(GLMLIB) $(F05_LIB) $(F06_LIB) $(F07_LIB) and $(TWBINS) cleantw: -rm $(TWLIB) $(GLMLIB) $(F05_LIB) $(F06_LIB) $(F07_LIB) $(TWBINS) # ================================================================ # making Nate Robbins's tutors TUTOR_BINS := tutors/shapes tutors/transformation tutors/projection tutors/lightmaterial tutors/lightposition tutors/fog tutors/texture tutors: $(TUTOR_BINS) cleantutors: -rm $(TUTOR_BINS) # ================================================================ # making the demos # The following variable lists all the directories under "demos" DEMO_DIRS := $(wildcard demos/*) # If you just want a few demos directories made, list them like this: #DEMO_DIRS := demos/early demos/color demos/modeling demos/camera # The following variables holds the filenames of all the demo source # files and the binaries. DEMO_SRCS := $(foreach dir,$(DEMO_DIRS),$(wildcard $(dir)/*.cc)) DEMO_BINS := $(basename $(DEMO_SRCS)) # I don't know how to cause the demo bins to be remade if one of the # library files changes, such as tw.o. You'll have to do that by hand, by # saying "make cleandemos" and then "make demos" demos: $(DEMO_BINS) # Use the following target if you want to keep going even if one of the # compilations fails. Use the preceding if they should all work. demosall: @echo "Making demo programs" #for f in $(DEMO_BINS); do $(MAKE) $$f; done demoinfo: @echo "Demo All Dirs:" @echo $(DEMO_ALL_DIRS) @echo "Demo Dirs:" @echo $(DEMO_DIRS) @echo -n "Number of Sources: " @echo $(words $(DEMO_SRCS)) @echo -n "Number of Binaries: " @echo $(words $(DEMO_BINS)) @echo "Counting actual binaries" @ls $(DEMO_BINS) 2>/dev/null | wc cleandemos: @-rm -f $(DEMO_BINS) # ================================================================ # semester object demos F05_SRCS := $(wildcard f05/*.cc) F05_BINS := $(basename $(F05_SRCS)) f05_demos: $(F05_BINS) clean_f05: @-rm -f $(F05_BINS) # ================================================================ # semester object demos F06_SRCS := $(wildcard f06/*.cc) F06_BINS := $(basename $(F06_SRCS)) f06_demos: $(F06_BINS) clean_f06: @-rm -f $(F06_BINS) # ================================================================ # semester object demos F07_SRCS := $(wildcard f07/*.cc) F07_BINS := $(basename $(F07_SRCS)) f07_demos: $(F07_BINS) clean_f07: @-rm -f $(F07_BINS) # ================================================================ # getting ready for a release # Delete all emacs backup files expunge: find $(TWHOME) -name "*~" -exec rm {} \; # This target is used on the clean: cleantw cleandemos cleantutors clean_f05 clean_f06 clean_f07 # the release script copies the master directory tree, then does a "make # clean" on the copy, and finally tars the whole thing up. release: expunge bin/release $(TWHOME) # ================================================================ # installation alias: @echo "" @echo " To define an alias, please copy/paste the following lines into your shell." @echo " On Linux and Mac OS X, you can highlight the lines and middle-click" @echo " (probably option+click for a one-button Mac mouse)." @echo "" @echo export TWHOMEDIR=${PWD} @echo export TWLOADPATH=.:${PWD}/textures:${PWD}/objects:${PWD}/f05:${PWD}/f06:${PWD}/f06:${PWD}/f07 @echo alias 'make-tw="make -f ${PWD}/Makefile"' @echo "" # The "install" target is obsolete. All I wanted was to define an alias # automatically, but I don't see how to do it. install: #source bin/install-tw $(TWHOME) # ================================================================ # debugging info: @echo "TWHOME is $(TWHOME)" @echo "OSTYPE is $(OSTYPE)" @echo "NETPBMINSTALLED is $(NETPBMINSTALLED)" @echo "CFLAGS is $(CFLAGS)" @echo "LDLIBS is $(LDLIBS)" @echo "LOADLLIBES is $(LOADLIBES)" @echo "PPM is $(PPM)" @echo "LDLIBS is $(LDLIBS)" @echo "DEMO_ALL_DIRS is $(DEMO_ALL_DIRS)" @echo "DEMO_DIRS is $(DEMO_DIRS)" @echo "F05_BINS is $(F05_BINS)" @echo "F06_BINS is $(F06_BINS)" @echo "F07_BINS is $(F07_BINS)"