
# ==============================================================================
#                          Unix Makefile for libmpdec
# ==============================================================================


LIBSTATIC = @LIBSTATIC@
LIBSONAME = @LIBSONAME@
LIBSHARED = @LIBSHARED@

CC = @CC@
LD = @LD@
AR = @AR@
RANLIB = @RANLIB@
MPD_PGEN = @MPD_PGEN@
MPD_PUSE = @MPD_PUSE@
MPD_PREC = @MPD_PREC@
MPD_DPREC = @MPD_DPREC@

CONFIGURE_CFLAGS = @CONFIGURE_CFLAGS@
MPD_CFLAGS = $(CONFIGURE_CFLAGS) $(CFLAGS)

CONFIGURE_LDFLAGS = @CONFIGURE_LDFLAGS@
MPD_LDFLAGS = $(CONFIGURE_LDFLAGS) $(LDFLAGS)

ifeq ($(MAKECMDGOALS), profile_gen)
  MPD_CFLAGS += $(MPD_PGEN)
  MPD_LDFLAGS += $(MPD_PGEN)
endif
ifeq ($(MAKECMDGOALS), profile_use)
  MPD_CFLAGS += $(MPD_PUSE)
  MPD_LDFLAGS += $(MPD_PUSE)
endif


default: $(LIBSTATIC) $(LIBSHARED)


OBJS := basearith.o context.o constants.o convolute.o crt.o mpdecimal.o \
        mpsignal.o difradix2.o fnt.o fourstep.o io.o memory.o numbertheory.o \
        sixstep.o transpose.o

$(LIBSTATIC): Makefile $(OBJS)
	$(AR) rc $(LIBSTATIC) $(OBJS)
	$(RANLIB) $(LIBSTATIC)

$(LIBSHARED): Makefile $(OBJS)
	$(LD) $(MPD_LDFLAGS) -shared -Wl,-soname,$(LIBSONAME) -o $(LIBSHARED) $(OBJS) -lm


basearith.o:\
Makefile basearith.c mpdecimal.h constants.h memory.h \
typearith.h basearith.h
	$(CC) $(MPD_CFLAGS) -c basearith.c

constants.o:\
Makefile constants.c mpdecimal.h constants.h
	$(CC) $(MPD_CFLAGS) -c constants.c

context.o:\
Makefile context.c mpdecimal.h
	$(CC) $(MPD_CFLAGS) -c context.c

convolute.o:\
Makefile convolute.c mpdecimal.h bits.h constants.h fnt.h fourstep.h \
numbertheory.h sixstep.h umodarith.h typearith.h convolute.h
	$(CC) $(MPD_CFLAGS) -c convolute.c

crt.o:\
Makefile crt.c mpdecimal.h numbertheory.h constants.h umodarith.h \
typearith.h crt.h
	$(CC) $(MPD_CFLAGS) -c crt.c

difradix2.o:\
Makefile difradix2.c mpdecimal.h bits.h numbertheory.h constants.h \
umodarith.h typearith.h difradix2.h
	$(CC) $(MPD_CFLAGS) -c difradix2.c

fnt.o:\
Makefile fnt.c mpdecimal.h bits.h difradix2.h numbertheory.h \
constants.h fnt.h
	$(CC) $(MPD_CFLAGS) -c fnt.c

fourstep.o:\
Makefile fourstep.c mpdecimal.h numbertheory.h constants.h sixstep.h \
transpose.h umodarith.h typearith.h fourstep.h
	$(CC) $(MPD_CFLAGS) -c fourstep.c

io.o:\
Makefile io.c mpdecimal.h bits.h constants.h memory.h typearith.h io.h
	$(CC) $(MPD_CFLAGS) -c io.c

memory.o:\
Makefile memory.c mpdecimal.h typearith.h memory.h
	$(CC) $(MPD_CFLAGS) -c memory.c

mpdecimal.o:\
Makefile mpdecimal.c mpdecimal.h basearith.h typearith.h bits.h \
convolute.h crt.h memory.h umodarith.h constants.h
	$(CC) $(MPD_CFLAGS) -c mpdecimal.c

mpsignal.o:\
Makefile mpdecimal.c mpdecimal.h
	$(CC) $(MPD_CFLAGS) -c mpsignal.c

numbertheory.o:\
Makefile numbertheory.c mpdecimal.h bits.h umodarith.h constants.h \
typearith.h numbertheory.h
	$(CC) $(MPD_CFLAGS) -c numbertheory.c

sixstep.o:\
Makefile sixstep.c mpdecimal.h bits.h difradix2.h numbertheory.h \
constants.h transpose.h umodarith.h typearith.h sixstep.h
	$(CC) $(MPD_CFLAGS) -c sixstep.c

transpose.o:\
Makefile transpose.c mpdecimal.h bits.h constants.h typearith.h \
transpose.h
	$(CC) $(MPD_CFLAGS) -c transpose.c


FORCE:

bench: FORCE $(LIBSTATIC)
	$(CC) -Wno-unused-but-set-variable $(MPD_CFLAGS) -o bench bench.c $(LIBSTATIC) -lm


profile_gen: clean bench
	./bench $(MPD_PREC) 1000
	./bench $(MPD_DPREC) 1000
	rm -f *.o *.gch $(LIBSTATIC) $(LIBSHARED) bench runtest

profile_use: bench
	./bench $(MPD_PREC) 1000
	./bench $(MPD_DPREC) 1000

profile:
	$(MAKE) profile_gen
	$(MAKE) profile_use

clean: FORCE
	rm -f *.o *.so *.gch *.gcda *.gcno *.gcov *.dyn *.dpi *.lock \
        $(LIBSTATIC) $(LIBSHARED) bench

distclean: clean
	rm -f config.h config.log config.status Makefile mpdecimal.h



