OS=linux

GCC=gcc


#if you want to use config file
#CC=./cc -configfile cspot.config

#if you prefer to set everything manualy
CC=g++

#CC=./cc -compiler /usr/bin/g++ -directory cspot.directory  -filelist cspot.file_list

#if enabled file list won't be generated
#CC=gcc

#MY-RELEASE
# CFLAGS = -O2 -ffast-math -march=pentium-m
# LDFLAGS= -O2 -march=pentium-m

#RELEASE
 CFLAGS = -O2 -ffast-math 
 LDFLAGS= -O2 

#DEBUG 
 CFLAGS = -g
 LDFLAGS= -g

#povinne
CFLAGS += -fpic 

LDFLAGS += -lreadline
LDFLAGS += -lgmp



PROGRAMS=div
LIB_OBJS=\
		base/div.o  \
		base/z_p.o  \
		base/io.o   \
		base/test.o \
		base/deleno.o \
		base/deleno_helper.o \
		base/helper.o \
		base/alloc.o \
		base/polynom.o \
		base/nasob.o 
		
#		base/fft_m.o \

auto: clean div zaloha

#auto: clean div divdb zaloha
-include Makefile.dep


all:  div zaloha

DB=div.db


divdb:
#if you are using configfile then this is the way to set filelist
	./cspot -db $(DB) -conf cspot.config -p -v -so sparse_output

#or you can specify your filelist manually
#	./cspot -db spot.db -fl cspot.directory/cspot.file_list -p -v -so sparse_output


clean:
	rm -f cspot_cc *.[oasi] */*.[oasi]  $(SPARSE_FOLDER)/*/*.[oasi] $(SPARSE_FOLDER)/*.[oasi] core core.[0-9]* $(PROGRAMS) $(SPARSE_FOLDER)/$(PROGRAMS) Makefile.dep
	rm -rf cspot.directory $(DB)

Makefile.dep dep: $(SPARSE_FOLDER)/pre-process.h
	rm -f Makefile.dep
	touch Makefile.dep
#	ls */*.c | sed 's/\(.*\).c/gcc -I. -MM -DSPOT -DPAGE_SIZE \1.c \| sed "s\/^.*.o: \/`echo \1| sed s\/\\\\\\\/\/\\\\\\\\\\\\\\\\\\\\\\\\\/\/g`.o: \/" >> Makefile.dep /' | bash 
	g++ -I. -MM -DSPOT -DPAGE_SIZE `find . -name "*.c"` > Makefile.dep
#	gcc -I. -MM -DSPOT -DPAGE_SIZE $(wildcard */*.c) > Makefile.dep


div: $(LIB_OBJS) $(LIBS) 
	$(CC) $(LDFLAGS) -o $@ $(LIB_OBJS) $(LIBS) 

zaloha:
	rm -rf snapshot
	if [ -d backup ]; then tar -czf backup/latest.tgz Makefile */*.[ch] cspot.config ; cp backup/latest.tgz backup/source-`date +%F_%X`.tgz; fi


.PHONY: clean all run


