CC=gcc
CFLAGS=-Wall -O3 -DNLGLOG -DNLGLSTATS -DNDEBUG -DNLGLPICOSAT $(PROF)
all: targets
targets: liblgl.a lingeling plingeling
liblgl.a: lglib.o lglbnr.o makefile
	ar rc $@ lglib.o lglbnr.o
	ranlib $@
lingeling: lglmain.o liblgl.a makefile 
	$(CC) $(CFLAGS) -o $@ lglmain.o -L. -llgl 
plingeling: plingeling.o liblgl.a makefile
	$(CC) $(CFLAGS) -pthread -o $@ plingeling.o -L. -llgl 
feedback:
	make clean-other
	touch makefile
	PROF=-fprofile-generate make targets
	--./lingeling none
	touch makefile
	PROF=-fprofile-use make targets
lglmain.o: lglmain.c lglib.h makefile
	$(CC) $(CFLAGS) -c lglmain.c
plingeling.o: plingeling.c lglib.h makefile
	$(CC) $(CFLAGS) -c plingeling.c
lglib.o: lglib.c lglib.h makefile 
	$(CC) $(CFLAGS) -c lglib.c
lglib.s: lglib.c lglib.h makefile 
	$(CC) $(CFLAGS) -S lglib.c
lglbnr.o: lglbnr.c lglcfg.h lglcflags.h makefile
	$(CC) $(CFLAGS) -c lglbnr.c
lglcfg.h: VERSION mkconfig lglbnr.c lglib.c lglmain.c lglcflags.h makefile
	rm -f $@
	./mkconfig > $@
lglcflags.h: makefile
	rm -f $@
	echo '#define LGL_CC "$(shell $(CC) --version|head -1)"' >> $@
	echo '#define LGL_CFLAGS "$(CFLAGS)"' >> $@
clean: clean-other clean-config
clean-config:
	rm -f makefile lglcfg.h lglcflags.h
clean-other:
	rm -f lingeling plingeling 
	rm -f *.o *.s *.a log/*.log 
	rm -f *.gcno *.gcda cscope.out gmon.out *.gcov
.PHONY: all targets feedback clean clean-config clean-other
