#-----------------------------------------------------------------------------
# Makefile
#
# For building land-surface-temperature.
#-----------------------------------------------------------------------------
.PHONY: all install clean

# Inherit from upper-level make.config
TOP = ../..
include $(TOP)/make.config

# Set up compile options
CC = gcc
RM = rm
EXTRA = -Wall $(EXTRA_OPTIONS)

# Define the include files
INC1 = utilities.h grid_points.h modtran_utils.h integrate.h interpolate.h calculate_atmospheric_parameters.h input.h output.h intermediate_data.h
INC2 = utilities.h input.h interpolate.h
INCDIR  = -I. -I$(PROJX_INC) -I$(XML2INC) -I$(ESPAINC)
NCFLAGS = $(EXTRA) $(INCDIR)

# Define the source code and object files
SRC1 = \
      utilities.o                              \
      grid_points.c                            \
      modtran_utils.c                          \
      integrate.c                              \
      interpolate.c                            \
      input.c                                  \
      output.c                                 \
      intermediate_data.c                      \
      calculate_atmospheric_parameters.c
OBJ1 = $(SRC1:.c=.o)

SRC2 = \
      utilities.o                              \
      input.c                                  \
      calculate_qa.c
OBJ2 = $(SRC2:.c=.o)


# Define the object libraries
EXLIB = -L$(ESPALIB) -l_espa_raw_binary -l_espa_common -l_espa_format_conversion \
        -L$(XML2LIB) -lxml2 \
        -L$(LZMALIB) -llzma \
        -L$(PROJX_LIB) -lproj \
        -L$(ZLIBLIB) -lz
MATHLIB = -lm
LOADLIB = $(EXLIB) $(MATHLIB)

# Define the executables
EXE1 = st_atmospheric_parameters
EXE2 = calculate_surface_temp_unc

# Target for the executables
all: $(EXE1) $(EXE2)

$(EXE1): $(OBJ1) $(INC1)
	$(CC) $(EXTRA) -o $(EXE1) $(OBJ1) $(LOADLIB)
$(EXE2): $(OBJ2) $(INC2)
	$(CC) $(EXTRA) -o $(EXE2) $(OBJ2) $(LOADLIB)

install:
	install -d $(link_path)
	install -d $(st_install_path)
	install -m 755 $(EXE1) $(st_install_path) || exit 1
	install -m 755 $(EXE2) $(st_install_path) || exit 1
	ln -sf $(st_link_source_path)/$(EXE1) $(link_path)/$(EXE1)
	ln -sf $(st_link_source_path)/$(EXE2) $(link_path)/$(EXE2)

clean:
	$(RM) -f *.o $(EXE1)
	$(RM) -f *.o $(EXE2)

$(OBJ1): $(INC1)
$(OBJ2): $(INC2)

.c.o:
	$(CC) $(NCFLAGS) -c $<

