#
# This is mult/makefile
# It makes fftmult  : demo of the fast fourier transform multiplication
#          karamult : demo of the karatsuba multiplication
#          speedcmp : speed comparison of fft-, karatsuba- and direct multiplication
#


ifeq ($(suffix $(MAKE)),.exe) # switch for MS DOS options
	CXX=gxx                    # MS DOS options
	XSUFFIX=.exe
	RM=-del
	COPY=copy
else                          # LINUX options
	CXX=g++ -static
	XSUFFIX=.elf
	LIBS=-lg++
	COPY=cp
endif

CXXFLAGS=-Wall -O

TARGETS=fftmult$(XSUFFIX) \
        karamult$(XSUFFIX) \
        speedcmp$(XSUFFIX)   

fftmult$(XSUFFIX) : fft*.cc print.cc getdigs.cc *.h
	$(CXX) $(CXXFLAGS) $(LIBS) -o $@ $(filter %.cc, $+)
	strip $@

karamult$(XSUFFIX) : kara*.cc print.cc getdigs.cc *.h
	$(CXX) $(CXXFLAGS) $(LIBS) -o $@ $(filter %.cc, $+)
	strip $@

speedcmp$(XSUFFIX) : speedcmp.cc kara.cc fft.cc print.cc *.h
	$(CXX) $(CXXFLAGS) $(LIBS) -o $@ $(filter %.cc, $+)
	strip $@

.PHONY: all new runall
all:  $(TARGETS) 

$(TARGETS) : 

.PHONY: all new runall
all:  $(TARGETS) 

$(TARGETS) : 

new:
	$(RM) fftmult$(XSUFFIX)
	$(RM) karamult$(XSUFFIX)
	$(RM) speedcmp$(XSUFFIX)
	$(MAKE) all

runall: $(TARGETS) 
	fftmult$(XSUFFIX) < fftmult.in
	karamult$(XSUFFIX)   < karamult.in
	speedcmp$(XSUFFIX)   < speedcmp.in

