CC = @cc@
CXX = @cc@

ROOTDIR = @rootdir@
PREFIX = @prefix@
BINDIR = $(PREFIX)/bin

INCDIR = $(ROOTDIR)/include
LIBDIR = $(ROOTDIR)/lib

CPPFLAGS =	-I. -I$(INCDIR)
#CXXFLAGS =	-g
CXXFLAGS =	-O2

LIBCMDLINE =	$(LIBDIR)/libcmdline.a
LIBCXXUTIL =	$(LIBDIR)/libcxxutil.a
LIBGTL =	$(LIBDIR)/libGTL.a

CXXLIBS =	-lstdc++
LOADLIBES =	$(LIBCMDLINE) $(LIBCXXUTIL) $(LIBGTL) $(CXXLIBS) -lm

MARKER_OBJS =		marker.o
HAPLOTYPE_OBJS =	haplotype.o
DICTIONARY_OBJS =	dictionary.o \
			segment_factory.o longest_segment.o \
			independent_segment.o
DISTRIBUTION_OBJS =	geometric.o
PROBABILITY_OBJS =	probability.o
PATH_OBJS =		path.o
PATH_STRATEGY_OBJS =	no_latents.o no_latent_recomb_strategy.o \
			latent_recomb_strategy.o path_strategy_factory.o
PATH_CRITERION_OBJS =	path_criterion_factory.o
COMMANDLINE_OBJS =	commandline.o

LIBOBJS =	$(MARKER_OBJS) $(HAPLOTYPE_OBJS) $(DICTIONARY_OBJS) \
		$(PATH_OBJS) $(PATH_STRATEGY_OBJS) $(DISTRIBUTION_OBJS) \
		$(PROBABILITY_OBJS) $(PATH_CRITERION_OBJS) \
		$(COMMANDLINE_OBJS)

PROGOBJS =	marker.t.o haplotype.t.o colortex.o dictionary.t.o \
		path.t.o commandline.t.o colortable.o \
		recombinant.o prob.o path_gen.o profile.o \
		profile_helpers.o

OBJS =		$(LIBOBJS) $(PROGOBJS)
SRCS =		$(OBJS:.o=.cc)

TEST_DRIVERS =	marker.t haplotype.t dictionary.t \
		path.t commandline.t

PROGRAMS =	colortex recombinant prob path_gen profile

CAT = @cat@
CP = @cp@
ECHO = @echo@
MKDEP = @mkdep@
MKDIR = @mkdir@
RM = @rm@
STRIP = @strip@
TAR = @tar@
TOUCH = @touch@

all:	$(PROGRAMS)
lib:	$(LIBOBJS)

install-debug:	$(PROGRAMS)
	$(MKDIR) $(BINDIR)
	for f in $(PROGRAMS); do \
		$(ECHO) "Installing $$f..."; \
		$(RM) -f $(BINDIR)/$$f; \
		$(CP) $$f $(BINDIR)/$$f; \
	done

install:	$(PROGRAMS)
	$(MKDIR) $(BINDIR)
	for f in $(PROGRAMS); do \
		$(ECHO) "Installing $$f..."; \
		$(RM) -f $(BINDIR)/$$f; \
		$(CP) $$f $(BINDIR)/$$f; \
		$(STRIP) $(BINDIR)/$$f; \
	done

depend:
	@$(ECHO) "Depending source files."
	@$(MKDEP) -- $(CPPFLAGS) -- $(SRCS) 2> /dev/null
	@$(RM) Makefile.bak

test:	$(TEST_DRIVERS)

marker.t:	marker.t.o $(MARKER_OBJS)

haplotype.t:	haplotype.t.o $(HAPLOTYPE_OBJS) $(MARKER_OBJS)

colortex:	colortex.o $(LIBOBJS)

dictionary.t:	dictionary.t.o $(DICTIONARY_OBJS) \
		$(HAPLOTYPE_OBJS) $(MARKER_OBJS)

path.t:		path.t.o $(PATH_OBJS) $(HAPLOTYPE_OBJS) $(MARKER_OBJS)

no_latents.t:	no_latents.t.o $(PATH_STRATEGY_OBJS) \
		$(DICTIONARY_OBJS) $(PATH_OBJS) $(PROBABILITY_OBJS) \
		$(HAPLOTYPE_OBJS) $(MARKER_OBJS)

recombinant:	recombinant.o $(LIBOBJS)

prob:	prob.o $(LIBOBJS)

path_gen:	path_gen.o $(LIBOBJS)

profile:	profile.o profile_helpers.o $(LIBOBJS)

profile-test:	profile
	date && \
	./profile \
		$(GENETICS_FLAGS) \
		--components-fname profile.components.out \
		5 test/disease.dat test/normal.dat > profile.out 2>&1 && \
	date

clean:
	$(RM) core *.core *~ *.bak *.out $(OBJS) $(TEST_DRIVERS) $(PROGRAMS)

distclean:	clean
	$(RM) Makefile
