#======================================================================== # # NAME # # makefile # # DESCRIPTION # # Makefile for UNIX systems and Windows + Cygwin for compiling # and testing Primpoly. # # Build the executables by calling # # make # # To compile and test the program, type # # make test # # LEGAL # # Primpoly Version 9.1 - A Program for Computing Primitive Polynomials. # Copyright (C) 1999-2008 by Sean Erik O'Connor. All Rights Reserved. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; version 2 # of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, # USA. # # The author's address is artifex@seanerikoconnor.freeservers.com. # #============================================================================= # Put this pseudo-target first so make without command line options executes it. all: makeAllExes configure #============================== Configuration ================================ # Get the name of the host and figure out if we are on a Windows/PC/Cygwin # platform. configure: HOSTNAME=`python -c "import platform; print platform.node()"` echo Hostname = $(HOSTNAME) ifeq ($(HOSTNAME), seanwinimac) PLATFORM = cygwin endif # Default platform is Mac OS X ifndef PLATFORM PLATFORM = mac endif # Mac OS X Leopard SDK. ifeq ($(PLATFORM), mac) SDK = /Developer/SDKs/MacOSX10.5.sdk MAC_SDK = -isysroot ${SDK} endif # Cygwin include files and libraries. ifeq ($(PLATFORM), cygwin) CYGWIN_CPP_INC = -I "C:/cygwin/lib/gcc/i686-pc-mingw32/3.4.4/include/c++" CYGWIN_C_INC = -I "C:/cygwin/lib/gcc/i686-pc-mingw32/3.4.4/include" CPP_LIBS = -L"C:/cygwin/lib" C_LIBS = -L"C:/cygwin/lib" endif # GNU standard C and C++ compilers. ifeq ($(PLATFORM), mac) CPP= /Developer/usr/bin/g++-4.0 CC= /Developer/usr/bin/gcc-4.0 else CPP = g++ CC = gcc endif #============================== Compile and Link Flags ======================= # On the Mac, create a universal binary architectures for both ppc7400 and i386. ifeq ($(PLATFORM), mac) ARCH = -arch ppc -arch i386 endif # On the Mac, we can optimize more. ifeq ($(PLATFORM), mac) CPP_DEBUG_FLAGS = -O3 # -g3 \ # -D DEBUG_PP_PARSER \ # -D DEBUG_PP_BIGINT \ # -D DEBUG_PP_ARITH \ # -D DEBUG_PP_FACTOR \ # -D DEBUG_PP_POLYNOMIAL C_DEBUG_FLAGS = -O3 # -D DEBUG_PP_PRIMPOLY endif # On Windows/PC/Cygwin, we crash if we optimize. ifeq ($(PLATFORM), cygwin) CPP_DEBUG_FLAGS = # -g3 \ # -D DEBUG_PP_FACTOR \ # -D DEBUG_PP_PARSER \ # -D DEBUG_PP_BIGINT \ # -D DEBUG_PP_ARITH \ # -D DEBUG_PP_POLYNOMIAL C_DEBUG_FLAGS = # -D DEBUG_PP_PRIMPOLY endif # Turn on C++ exceptions and collect the other flags. CPP_FLAGS = -fexceptions $(ARCH) $(CPP_DEBUG_FLAGS) $(MAC_SDK) C_FLAGS = $(ARCH) $(C_DEBUG_FLAGS) $(MAC_SDK) # Location of C++ and C Libraries. ifeq ($(PLATFORM), cygwin) endif # C++ and C include files. CPP_INC = -I /usr/include ${CYGWIN_CPP_INC} C_INC = -I /usr/include ${CYGWIN_C_INC} # Link flags. ifeq ($(PLATFORM), mac) LFLAGS = $(ARCH) -isysroot ${SDK} endif #============================== Root directories ============================= # Source file root directories. CPP_SRC_DIR = ../SourceCode/Primpoly C_SRC_DIR = ../SourceCode/PrimpolyC # Object file root directories. CPP_OBJ_DIR = Bin C_OBJ_DIR = BinC # Executable file root directories. CPP_BIN_DIR = Bin C_BIN_DIR = BinC #============================== List of Files ================================ # Object files. CPP_OBJ = $(CPP_OBJ_DIR)/ppArith.o \ $(CPP_OBJ_DIR)/ppBigInt.o \ $(CPP_OBJ_DIR)/ppStatistics.o \ $(CPP_OBJ_DIR)/ppFactor.o \ $(CPP_OBJ_DIR)/ppParser.o \ $(CPP_OBJ_DIR)/ppPolynomial.o \ $(CPP_OBJ_DIR)/ppUnitTest.o C_OBJ = $(C_OBJ_DIR)/ppArith.o \ $(C_OBJ_DIR)/ppFactor.o \ $(C_OBJ_DIR)/ppHelperFunc.o \ $(C_OBJ_DIR)/ppIO.o \ $(C_OBJ_DIR)/ppOrder.o \ $(C_OBJ_DIR)/ppPolyArith.o # Main program object files. CPP_OBJ_MAIN = $(CPP_OBJ_DIR)/Primpoly.o C_OBJ_MAIN = $(C_OBJ_DIR)/Primpoly.o # Main program executables. CPP_BIN_MAIN = $(CPP_BIN_DIR)/Primpoly.exe C_BIN_MAIN = $(C_BIN_DIR)/PrimpolyC.exe #============================== Implicit Rules =============================== # Link all object files to executables. $(CPP_BIN_MAIN): $(CPP_OBJ_MAIN) $(CPP_OBJ) $(CPP) $(LFLAGS) $(CPP_OBJ_MAIN) $(CPP_OBJ) -o $(CPP_BIN_MAIN) $(CPP_LIBS) $(C_BIN_MAIN): $(C_OBJ_MAIN) $(C_OBJ) $(CC) $(LFLAGS) $(C_OBJ_MAIN) $(C_OBJ) -o $(C_BIN_MAIN) $(C_LIBS) # C++ and C source file compilation to object files. $(CPP_BIN_DIR)/%.o : $(CPP_SRC_DIR)/%.cpp $(CPP) -c $(CPP_FLAGS) $(CPP_INC) $< -o $@ $(C_BIN_DIR)/%.o : $(C_SRC_DIR)/%.c $(CC) -c $(C_FLAGS) $(C_INC) $< -o $@ # List of all file.o : file.h dependencies. Primpoly.o: Primpoly.h ppArith.h ppStatistics.h ppBigInt.h ppFactor.h ppParser.h ppPolynomial.h ppUnitTest.h ppArith.o: Primpoly.h ppArith.h ppStatistics.h ppBigInt.h ppFactor.h ppParser.h ppPolynomial.h ppUnitTest.h ppBigInt.o: Primpoly.h ppStatistics.h ppBigInt.h ppArith.h ppFactor.h ppParser.h ppPolynomial.h ppUnitTest.h ppStatistics.o: Primpoly.h ppStatistics.h ppBigInt.h ppArith.h ppFactor.h ppParser.h ppPolynomial.h ppUnitTest.h ppFactor.o: Primpoly.h ppFactor.h ppArith.h ppStatistics.h ppBigInt.h ppParser.h ppPolynomial.h ppUnitTest.h ppParser.o: Primpoly.h ppParser.h ppArith.h ppStatistics.h ppBigInt.h ppFactor.h ppPolynomial.h ppUnitTest.h ppPolynomial.o: Primpoly.h ppPolynomial.h ppArith.h ppStatistics.h ppBigInt.h ppFactor.h ppParser.h ppUnitTest.h ppUnitTest.o: Primpoly.h ppUnitTest.h ppArith.h ppStatistics.h ppBigInt.h ppFactor.h ppParser.h ppPolynomial.h #============================== Targets ====================================== # Make all the executables. makeAllExes: $(C_BIN_MAIN) $(CPP_BIN_MAIN) # Test C++ vs C programs, comparing polynomials to see if they are the same. test: $(CPP_BIN_MAIN) 2 2 | grep "x ^" | sed -e "s/,.*//g" > j.txt $(C_BIN_MAIN) -s 2 2 | grep "x ^" | sed -e "s/,.*//g" > jc.txt $(CPP_BIN_MAIN) 2 17 | grep "x ^" | sed -e "s/,.*//g" > j.txt $(C_BIN_MAIN) -s 2 17 | grep "x ^" | sed -e "s/,.*//g" > jc.txt $(CPP_BIN_MAIN) 2 43 | grep "x ^" | sed -e "s/,.*//g" > j.txt $(C_BIN_MAIN) -s 2 43 | grep "x ^" | sed -e "s/,.*//g" > jc.txt $(CPP_BIN_MAIN) 2 62 | grep "x ^" | sed -e "s/,.*//g" > j.txt $(C_BIN_MAIN) -s 2 62 | grep "x ^" | sed -e "s/,.*//g" > jc.txt $(CPP_BIN_MAIN) 3 30 | grep "x ^" | sed -e "s/,.*//g" > j.txt $(C_BIN_MAIN) -s 3 30 | grep "x ^" | sed -e "s/,.*//g" > jc.txt $(CPP_BIN_MAIN) 5 22 | grep "x ^" | sed -e "s/,.*//g" > j.txt $(C_BIN_MAIN) -s 5 22 | grep "x ^" | sed -e "s/,.*//g" > jc.txt $(CPP_BIN_MAIN) 7 16 | grep "x ^" | sed -e "s/,.*//g" > j.txt $(C_BIN_MAIN) -s 7 16 | grep "x ^" | sed -e "s/,.*//g" > jc.txt $(CPP_BIN_MAIN) 17 14 | grep "x ^" | sed -e "s/,.*//g" > j.txt $(C_BIN_MAIN) -s 17 14 | grep "x ^" | sed -e "s/,.*//g" > jc.txt $(CPP_BIN_MAIN) 137 7 | grep "x ^" | sed -e "s/,.*//g" > j.txt $(C_BIN_MAIN) -s 137 7 | grep "x ^" | sed -e "s/,.*//g" > jc.txt $(CPP_BIN_MAIN) 223 8 | grep "x ^" | sed -e "s/,.*//g" > j.txt $(C_BIN_MAIN) -s 223 8 | grep "x ^" | sed -e "s/,.*//g" > jc.txt $(CPP_BIN_MAIN) 557 6 | grep "x ^" | sed -e "s/,.*//g" > j.txt $(C_BIN_MAIN) -s 557 6 | grep "x ^" | sed -e "s/,.*//g" > jc.txt diff -w j.txt jc.txt rm j.txt jc.txt $(C_BIN_MAIN) -sc 2 4 $(C_BIN_MAIN) -sc 3 5 $(C_BIN_MAIN) -a 2 5 $(C_BIN_MAIN) 2 62 -$(C_BIN_MAIN) -sc 4 4 -$(CPP_BIN_MAIN) -t "x 1" $(CPP_BIN_MAIN) -t "x^4 + x + 1" $(CPP_BIN_MAIN) -t "x^3 + x + 2, 3" # Remove all C and C++ object files and binaries. clean: rm $(CPP_OBJ) $(CPP_OBJ_MAIN) $(CPP_BIN_MAIN) $(CPP_OBJ_TEST) rm $(C_OBJ) $(C_OBJ_MAIN) $(C_BIN_MAIN)