.IGNORE:
#---------------------------------------------------------------------------------------------------
# Makefile for mixed mode example 'c-f77-mixed' using Intel compilers.
#
# In this example, a C main program (main.c) calls a Fortran subroutine (a.k.a. void 
# function in C) called 'sub' (sub.f).  The key to linking the resulting object code files,
# each of which can be separately compiled using 'icc' (C) and 'ifort' (f77) is to *LOAD* 
# using CC, and to supply the libraries needed for a Fortran application.  These libraries 
# vary WIDELY from O/S to O/S, from vendor to vendor, and, as can be seen below, even from version
# to version of the same vendor's compiler on the same O/S!  This is why we tend to collect this sort 
# arcania in a file called 'aclocal.m4' that is used with configure.in to build 
# configure scripts.
#
# In short though, when linking fortran code into c code to produce a c executable, with the 
# recent versions of the intel compilers, one needs to include the libraries
#
#     -lsvml -lifcore -lm
# 
# at load time
#---------------------------------------------------------------------------------------------------
FC       = ifort
FFLAGS   = -O3 -tpp6 -axK -w -w90 -w95 -cm -Vaxlib

CC       = icc
CFLAGS   = -O3 -axK -tpp6
CPPFLAGS = -wd177,266 -DINTEL_8_OR_LATER -DLINUX -DPORT_GROUP -DWant_c_files \
           -I/usr/local/include -I/usr/local/intel/include -I/usr/X11R6/include

LDFLAGS  = -L/usr/local/intel/lib -L/usr/X11R6/lib

# For ifc, versions 5,6,7
# CCF77LIBS="-lCEPCF90 -lF90 -lm"
#
# For ifc, versions 8,?
CCF77LIBS = -lsvml -lifcore -lm

# Add libs here as needed, or in link command ('main' target) per se
LIBS = $(CCF77LIBS) 

.f.o:
	$(FC) $(FFLAGS) -c $*.f

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

EXECUTABLES = main

all: $(EXECUTABLES) run

main: main.o sub.o
	$(CC) $(CFLAGS) $(LDFLAGS) main.o sub.o $(LIBS) -o main

run: main
	echo "Running main in 2 seconds ..."; sleep 2
	./main

clean:
	rm *.o
	test -f work.pc && rm work.pc
	test -f work.pc && rm work.pcl
	rm $(EXECUTABLES)
