# Make sure to set the CODA_DEFINITION environment variable to point to your
# directory with the CODA .codadef files before running the example program


CC = gcc
F77 = 
LD =  -g -O2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -fcf-protection

# The possible wrapping flags are:
#   -DWRAPFORTRAN_USE_UPPERCASE_IDENTIFIERS=1
#   -DWRAPFORTRAN_USE_ADDITIONAL_UNDERSCORE=1
WRAPFORTRAN_FLAGS = 

prefix = /usr
exec_prefix = ${prefix}
includedir = ${prefix}/include
# libdir = 

CPPFLAGS = -I. -I$(includedir) $(WRAPFORTRAN_FLAGS)
CFLAGS = -W -Wall -g -O2 -Werror=implicit-function-declaration -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection
FFLAGS = -g -O2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -fcf-protection
LDFLAGS =  $(shell pkg-config hdf5 --libs) -Wl,-z,relro

LIBS = -lm 
HDF4LIBS = -lmfhdf -ldf -lz -ljpeg -lsz
HDF5LIBS = $(shell pkg-config hdf5 --libs)

all: example

coda_fortran.o: coda_fortran.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c coda_fortran.c

example.o: example.f /usr/include/coda.inc
	$(F77) $(FFLAGS) -c example.f

example: example.o coda_fortran.o
	$(LD) $(LDFLAGS) -o example example.o coda_fortran.o -lcoda $(HDF4LIBS) $(HDF5LIBS) $(LIBS)

clean:
	-rm -f *.o $(DEMOS)
