
srcdir = @srcdir@
top_builddir =  @top_builddir@
abs_top_builddir = @abs_top_builddir@
top_srcdir = @top_srcdir@
abs_top_srcdir = @abs_top_srcdir@
subdir = rational
builddir = @builddir@

CFLAGS = @CFLAGS@
DEPFLAGS = @DEPFLAGS@
LDFLAGS = @LDFLAGS@
DEFS = @DEFS@
OPTARGS = @OPTARGS@
SOPTARGS = @SOPTARGS@

AR = @AR@
RANLIB = @RANLIB@
CC = @CC@
CCDEP = @CCDEP@
CCLD = ${CC}
LINK = ${CCLD} ${CFLAGS} ${LDFLAGS} ${OPTARGS} -o $@
LEX = @LEX@
AUTOCONF = @AUTOCONF@
DEFS = @DEFS@

INCLUDES = @INCLUDES@
LDADD =
#COMPILE = ${CC} ${DEFS} ${INCLUDES} ${CFLAGS}
COMPILE = ${CC} $(DEFS) ${INCLUDES} ${CFLAGS}

LIBRARIES = librational
librational_TARGETS = zolotarev elliptic rational

librational_STARGETS =

librational_OBJECTS = $(addsuffix .o, ${librational_TARGETS})
librational_SOBJECTS = $(addsuffix .o, ${librational_STARGETS})

# default rule

all: Makefile dep librational.a

# rules for debugging
debug all-debug: CFLAGS := $(CFLAGS) @DEBUG_FLAG@
debug all-debug: all

# rules for profiling information
profile all-profile: CFLAGS := $(filter-out -fomit-frame-pointer,${CFLAGS}) @PROFILE_FLAG@
profile all-profile: all


#include dep rules

-include $(addsuffix .d,${librational_TARGETS})

include ${top_srcdir}/Makefile.global

# rule to compile objects

${librational_OBJECTS}: %.o: ${srcdir}/%.c %.d Makefile ${abs_top_builddir}/config.h
	$(COMPILE) ${OPTARGS} -c $<

${librational_SOBJECTS}: %.o: ${srcdir}/%.c %.d Makefile ${abs_top_builddir}/config.h
	$(COMPILE) ${SOPTARGS} -c $<

# rule to make librational

librational.a: ${librational_OBJECTS} ${librational_SOBJECTS} Makefile
	@rm -f librational.a
	@${AR} cru librational.a ${librational_OBJECTS} ${librational_SOBJECTS}
	@$(RANLIB) librational.a
	@cp librational.a ../lib/librational.a

# rule to generate .d files

$(addsuffix .d, $(librational_TARGETS) ${librational_STARGETS}): %.d: ${srcdir}/%.c Makefile
	@${CCDEP} ${DEFS} ${DEPFLAGS} ${INCLUDES} $< > $@

# rule to make dependencies

dep: ${addsuffix .d, ${librational_TARGETS} ${librational_STARGETS}}

# rules to clean

compile-clean: Makefile
	rm -f ${$(addsuffix _OBJECTS, ${LIBRARIES})} ${$(addsuffix _SOBJECTS, ${LIBRARIES})} *.d

clean: compile-clean 
	rm -f $(addsuffix .a, ${LIBRARIES})
	rm -f ../lib/librational.a

distclean: clean
	rm -f Makefile

.PHONY: all dep clean compile-clean distclean profile all-profile debug all-debug
