Today I started on my PDF assembly engine project, and I found myself needing to build a make file to compile a bunch of C++ code that include the libHaru library. I was using build scripts but decided a bit more smarts was wise to speed up compile time of the affected code only and decided a makefile would do the trick… so some revisiting of the makefile man page and a google search netterd this gem.
My platform is Centos 6.4 with the libHaru code installed in /opt
Notes: t1.cpp is my test application and the rest of the files are logs, config and the PDF document files that I am starting with.
CC=g++ CFLAGS=-I/opt/libharu-libharu-22e741e/include -Wall LDIR=/opt/libharu-libharu-22e741e/include LIBS=-lhpdf -lm -lz DEPS=Logger.h Config.h ConfigReader.h ConfigWriter.h Configuration.h Document.h Page.h DocType.h PDFDocument.h Transport.h Customer.h InvoicePDF.h OBJ = Logger.o Config.o ConfigReader.o ConfigWriter.o Configuration.o Document.o Page.o DocType.o PDFDocument.o Transport.o Customer.o InvoicePDF.o t1.o %.o: %.cpp $(DEPS) @echo "Build Support Code -> $@" $(CC) -c -o $@ $< $(CFLAGS) $(LIBS) t1: $(OBJ) @echo "------------------> Building Main" g++ -o $@ $^ $(CFLAGS) $(LIBS) clean: rm -f *.o
At the command line, simply type “make” to build and “make clean” to wipe the .o files prior to a complete rebuild.