##*****************************************************************************
##                              INTEL CONFIDENTIAL
## Copyright(C) 2006-2010 Intel Corporation. All Rights Reserved.
## The source code contained  or  described herein and all documents related to
## the source code ("Material") are owned by Intel Corporation or its suppliers
## or licensors.  Title to the  Material remains with  Intel Corporation or its
## suppliers and licensors. The Material contains trade secrets and proprietary
## and  confidential  information of  Intel or its suppliers and licensors. The
## Material  is  protected  by  worldwide  copyright  and trade secret laws and
## treaty  provisions. No part of the Material may be used, copied, reproduced,
## modified, published, uploaded, posted, transmitted, distributed or disclosed
## in any way without Intel's prior express written permission.
## No license  under any  patent, copyright, trade secret or other intellectual
## property right is granted to or conferred upon you by disclosure or delivery
## of the Materials,  either expressly, by implication, inducement, estoppel or
## otherwise.  Any  license  under  such  intellectual property  rights must be
## express and approved by Intel in writing.
##
##*****************************************************************************
## Content:
##      Build standalone library of FFTW3 C wrappers to Intel MKL.
##*****************************************************************************

## Usage example:
##
## make lib64 compiler=gnu
##        Build the library for Intel(R) Itanium(R)-based applications
##        using GNU C compiler.

help:
	@echo "Usage: make {lib32|lib64|libem64t} [option...]"
	@echo "Options:"
	@echo ""
	@echo " compiler=gnu|pgi|intel"
	@echo "        Build the library using GNU gcc, PGI pgcc, or"
	@echo "        Intel(R) C compiler icc. Default value: intel."
	@echo ""
	@echo " MKLROOT=<path>"
	@echo "        Locate MKL header files relative to <path>."
	@echo "        Default value: ../.., unless defined in environment"
	@echo ""
	@echo " install_to=<path>"
	@echo "        Install the library to the specified location,"
	@echo "        which must exist. Default value: ."
	@echo ""
	@echo " install_as=<name>"
	@echo "        Specify the name of the library."
	@echo "        Default value depends on compiler used."
	@echo ""

##-----------------------------------------------------------------------------
## Default values

include fftw3xc.lst
compiler = intel
MKLROOT ?= ../..
install_to = .
install_as = libfftw3xc_$(compiler).a

##-----------------------------------------------------------------------------
## Main targets

lib32:
	$(MAKE) lib _IA=32

libem64t:
	$(MAKE) lib _IA=em64t

lib64:
	$(MAKE) lib _IA=64

ifdef _IA
##-----------------------------------------------------------------------------
## Supporting _macros

_CC_intel = icc
_CC_gnu = gcc
_CC_pgi = pgcc
CC = $(firstword $(_CC_$(compiler)) icc)

_cflags += $(_cflags_$(compiler))
_cflags += $(_cflags_$(compiler)_$(_IA))
_cflags += $(CFLAGS)

_cflags_intel = -vec-report0
## Option -O0 is required by Intel(R) compiler to produce
## Pentium(R) III compatible executables.
_cflags_intel_32 = -O0

_cppflags = -I$(MKLROOT)/include -I$(MKLROOT)/include/fftw $(CPPFLAGS)

_srcdir = wrappers
vpath %.c $(_srcdir)

_tmpdir := $(shell mktemp -d)

##-----------------------------------------------------------------------------
## Rules

lib: clean mkresdir $(install_to)/$(install_as) cleanup

$(install_to)/$(install_as): $(WRAP:%=$(_tmpdir)/%.o)
	ar rs $@ $^

$(_tmpdir)/%.o: %.c
	$(CC) $(_cflags) $(_cppflags) -c $< -o $@

clean:
	-rm -rf $(_tmpdir)

mkresdir:
	mkdir -p $(_tmpdir)

cleanup:
	-rm -rf $(_tmpdir)
##-----------------------------------------------------------------------------
endif
