Below is a general Makefile which is easily adapted to most Vrui projects. This page will describe some aspects of the file, but assumes the developer is already familiar with using make and the format of Makefiles. This is provided merely as a starting point and may not be suited to every project.
VRUIDIR = $(HOME)/Vrui-1.0 #include $(VRUIDIR)/etc/Vrui.debug.makeinclude include $(VRUIDIR)/etc/Vrui.makeinclude CC = /opt/local/bin/g++ CFLAGS += -Wall -O2 -g # Pattern rule to compile C++ sources: o/%.o: %.cpp %.hpp @mkdir -p o/$(*D) @echo Compiling $<... @$(CC) -c -o $@ $(VRUI_CFLAGS) $(CFLAGS) $< # Pattern rule to link executables: %: o/%.o @echo Linking $@... @$(CC) -o $@ $^ $(VRUI_LINKFLAGS) all: myprojectbinary myprojectbinary: o/myclass1.o \ o/myclass2.o \ o/myclass3.o clean: rm o/*.o
The top of the file sets the path of your Vrui installation to the Vrui-1.0 subdirectory in your home directory. Vrui will typically be installed somewhere like $(HOME)/Vrui-1.0.55, where 1.0.55 is the version number. Many developers will keep several versions of Vrui installed and create a symbolic link from the version they wish to compile against to Vrui-1.0. This way, the Makefiles for your projects do not have to change when using a different Vrui version.
VRUIDIR = $(HOME)/Vrui-1.0
The next line includes the contents of a Makefile from the Vrui directory. This will set up the compiling and linking flags automatically so the Vrui includes and libraries will be found. To build with the debug version of Vrui, comment out the first of these include lines, and uncomment the second.
include $(VRUIDIR)/etc/Vrui.makeinclude #include $(VRUIDIR)/etc/Vrui.debug.makeinclude
The next two lines let you set the path to your C++ compiler and change compiler flags. Common flags include -Wall to show all warnings, -g to enable debugging symbols in the binary, and -O2 to enable compiler optimizations.
CC = /opt/local/bin/g++ CFLAGS += -Wall -O2 -g
The next several lines use pattern matching to create rules to compile each of your .cpp files into object files (.o) in a subdirectory named o/. The given pattern assumes each .cpp file has an accompanying .hpp file – if there is no accompanying .hpp file, the compiler will produce an error.
The last lines specify the make targets, in the standard way. The final executable here will be called myprojectbinary and will link together the object files generated by compiling myclass1.cpp, myclass2.cpp, and myclass3.cpp.