#
# Makefile for Forecaster

# include common variables
include Makedefs

# extra files to be put into the distribution
DIST_FILES      =       Makedefs.in \
			Makefile \
			config.guess \
			config.sub \
			install-sh \
			configure

# include files to install
HEADERS =       $(buildincdir)/nws_forecast_api.h \
		$(buildincdir)/fbuff.h \
		$(buildincdir)/config_forecast.h
# dependency include files
MY_INCLUDES = 	mse_forc.h \
		forc.h \
		fbuff.h \
		config_forecast.h

# these are the targets
LIBRARY = $(buildlibdir)/libNwsForecast.a

# objects we are creating here
OBJS	= 	$(buildobjdir)/exp_smooth.o \
		$(buildobjdir)/fbuff.o \
		$(buildobjdir)/forc.o \
		$(buildobjdir)/nws_forecast_api.o \
		$(buildobjdir)/last_value.o \
		$(buildobjdir)/median.o \
		$(buildobjdir)/mse_forc.o \
		$(buildobjdir)/run_mean.o

.PHONY: all clean distclean precondition dist install headers

all: precondition $(LIBRARY) 

clean:
	@$(RM) -f $(OBJS) 
	@$(RM) -f $(LIBRARY) 
	@$(RM) -rf $(DIST_ROOT)

distclean: clean
	@echo "Removing build directories ..."
	@$(RM) -rf $(builddir) $(DIST_NAME)
	@echo "Removing configurations files ..."
	@$(RM) -f Makedefs Include/config_forecast.h config.status config.log config.cache

dist:
	@$(INSTALL) -d $(DIST_ROOT)
	@$(CP) *.h *.h.in *.c $(DIST_ROOT)
	@$(CP) $(DIST_FILES) $(DIST_ROOT)
	@cd $(TOP) && $(TAR) cf $(TOP)/$(DIST_NAME) $(DIST_DIR)
	@$(RM) -rf $(DIST_ROOT)

$(LIBRARY): $(OBJS)
	$(AR) $(ARFLAGS) $@ $(OBJS)
	$(RANLIB) $@

install: all
	@test -w $(bindir) || $(INSTALL) -d $(bindir)
	@test -w $(libdir) || $(INSTALL) -d $(libdir)
	@test -w $(incdir) || $(INSTALL) -d $(incdir)
	#@$(CP) $(buildbindir)/* $(bindir)
	@$(CP) $(buildlibdir)/* $(libdir)
	@$(CP) $(buildincdir)/* $(incdir)

tags:
	$(CTAGS) -R 

precondition: $(HEADERS)
	@if test `./config.guess` != "$(configured)"; then \
		echo "Forecast was configured for $(configured)!!"; \
		echo "you may want to run make clean and reconfigure for `./config.guess`!";\
		sleep 5 1; fi
	@$(INSTALL) -d $(buildobjdir)
	@$(INSTALL) -d $(buildlibdir)
	@$(INSTALL) -d $(buildincdir)
	@$(INSTALL) -d $(buildbindir)


Makedefs: Makedefs.in config.status
	./config.status

config.status: configure 
	@echo "You need to run ./configure!"; exit 1

# Compilation rules for C.
$(buildobjdir)/%.o : %.c %.h $(MY_INCLUDES)
	$(CC) $(INCLUDES) $(CFLAGS) -c $< -o $@

# copying rules for the header files
$(buildincdir)/%.h : %.h 
	$(CP) $< $(buildincdir)
