X-Git-Url: https://mattmccutchen.net/bigint/bigint.git/blobdiff_plain/e67d60496ce8582666f1fb77503acfe5d05c70d4..0afe80d551aa9b66b574b956cf681692399fc728:/Makefile diff --git a/Makefile b/Makefile index 8231720..68e7a00 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,75 @@ -# -# Matt McCutchen's Big Integer Library -# -# Please see the project Web site at -# http://mysite.verizon.net/mccutchen/bigint/ -# for more information and the latest version. -# -# December 16, 2004 version -# +# Mention default target. +all: -library : BigUnsigned.o BigInteger.o BigIntegerIO.o +# Implicit rule to compile C++ files. Modify to your taste. +%.o: %.cc + g++ -c -O2 -Wall -Wextra -pedantic $< -BigUnsigned.o : BigUnsigned.h BigUnsigned.cpp - g++ -c BigUnsigned.cpp +# Components of the library. +library-objects = \ + BigUnsigned.o \ + BigInteger.o \ + BigIntegerAlgorithms.o \ + BigUnsignedInABase.o \ + BigIntegerUtils.o \ -BigInteger.o : BigUnsigned.h BigInteger.h BigInteger.cpp - g++ -c BigInteger.cpp +library-headers = \ + NumberlikeArray.hh \ + BigUnsigned.hh \ + BigInteger.hh \ + BigIntegerAlgorithms.hh \ + BigUnsignedInABase.hh \ + BigIntegerLibrary.hh \ -BigIntegerIO.o : BigUnsigned.h BigInteger.h BigIntegerIO.cpp - g++ -c BigIntegerIO.cpp +# To ``make the library'', make all its objects using the implicit rule. +library: $(library-objects) -po3demo : library PowersOfThreeDemo.cpp - g++ -opo3demo BigUnsigned.o BigInteger.o BigIntegerIO.o PowersOfThreeDemo.cpp +# Conservatively assume that all the objects depend on all the headers. +$(library-objects): $(library-headers) -clean : - rm -f *.o po3demo +# TESTSUITE +# Compiling the testsuite. +testsuite.o: $(library-headers) +testsuite: testsuite.o $(library-objects) + g++ $^ -o $@ +# Extract the expected output from the testsuite source. +testsuite.expected: testsuite.cc + sed -nre 's,^.*//,,p' $< >$@ +# Run the testsuite. +.PHONY: test +test: testsuite testsuite.expected + ./testsuite >testsuite.out + @if diff -u testsuite.expected testsuite.out; then\ + echo 'All tests passed.';\ + else\ + echo >&2 'At least one test failed!'; exit 1;\ + fi + +# The rules below build a program that uses the library. They are preset to +# build ``sample'' from ``sample.cc''. You can change the name(s) of the +# source file(s) and program file to build your own program, or you can write +# your own Makefile. + +# Components of the program. +program = sample +program-objects = sample.o + +# Conservatively assume all the program source files depend on all the library +# headers. You can change this if it is not the case. +$(program-objects) : $(library-headers) + +# How to link the program. The implicit rule covers individual objects. +$(program) : $(program-objects) $(library-objects) + g++ $^ -o $@ + +# Delete all generated files we know about. +clean : + rm -f $(library-objects) $(program-objects) $(program) + +# I removed the *.tag dependency tracking system because it had few advantages +# over manually entering all the dependencies. If there were a portable, +# reliable dependency tracking system, I'd use it, but I know of no such; +# cons and depcomp are almost good enough. + +# Come back and define default target. +all : library $(program)