# Copyright 2002-2004 The Apache Software Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# All these setting come from the configure script
# We use configure to do most of the hard work as it is more
# designed to handle different system complexity than make
#

######################## CONFIGURE DEFINITIONS ##########################


PLATFORM = @platform@

CC  = @cc@
CXX = @cxx@
CXXFLAGS = @cxxflags@
CPPFLAGS = @cppflags@

PREFIX = @prefix@
LDFLAGS = @ldflags@
LIBS=@libs@
OBJSUFFIX = @objsuffix@
SHLIBSUFFIX = @shlibsuffix@

CC1 = @cc1@
CC4 = @cc4@
MAKE_SHARED = @make_shared@
LINK = @link@

LN_S = @ln_s@
INSTALL = @install@
INSTALL_DATA = @install_data@

# Packaging

PACKAGE_NAME = @package_name@
PACKAGE_TARNAME = @package_tarname@
PACKAGE_VERSION = @package_version@
PACKAGE_VERSION_MAJOR = @package_version_major@

# Library Files
LIB_OBJ_FILES = @lib_obj_files@

# MACROS defining commands
MKDIR=mkdir -p

######################## Build Directories ##########################

# SRC Directories

CANON_DIR = canon
TRANSFORMERS_DIR = transformers
UTILS_DIR = utils
UNIXUTILS_DIR = utils/unixutils
ENC_DIR = enc
FRAMEWORK_DIR = framework
DSIG_DIR = dsig
OPENSSL_DIR = enc/OpenSSL
XSCRYPT_DIR = enc/XSCrypt
XENC_DIR = xenc
XENCIMPL_DIR = xenc/impl
XKMS_DIR = xkms
XKMSIMPL_DIR = xkms/impl

# Utility SRC directories

TOOLS_DIR = tools
SAMPLES_DIR = samples

######################## Install Directories ##########################

prefix = @prefix@
exec_prefix = @exec_prefix@
includedir = @includedir@
libdir = @libdir@
bindir = @bindir@
infodir = @infodir@
mandir = @mandir@

######################## Library Definition ##########################


# Define the Library

LIB_DIR = ../lib
LIB_OBJECTS_DIR = $(LIB_DIR)/obj

# Actual names are defined by configure

LIBNAME = @lib_name@
LIBSHORTNAME = @lib_short_name@
LIBMAJORNAME = @lib_major_name@

# Our build target

THISLIB = ${LIB_DIR}/${LIBNAME}

BINTARGETDIR = ../bin

######################## RULES ##########################


# Now the actual compilation

all: lib alltools allsamples

lib: ${THISLIB}

${THISLIB}: $(LIB_OBJ_FILES)
	$(MAKE_SHARED) $(LDFLAGS) $(LIB_OBJ_FILES) $(LIBS) -o $@
	@LINK_COMMAND_1@
	@LINK_COMMAND_2@

$(LIB_OBJ_FILES): compile

compile: prepare
	$(MAKE) -C ${CANON_DIR} compile
	$(MAKE) -C ${TRANSFORMERS_DIR} compile
	$(MAKE) -C ${DSIG_DIR} compile
	$(MAKE) -C ${ENC_DIR} compile
	$(MAKE) -C ${OPENSSL_DIR} compile
	$(MAKE) -C ${XSCRYPT_DIR} compile
	$(MAKE) -C ${FRAMEWORK_DIR} compile
	$(MAKE) -C ${UTILS_DIR} compile
	$(MAKE) -C ${UNIXUTILS_DIR} compile
	$(MAKE) -C ${XENC_DIR} compile
	$(MAKE) -C ${XENCIMPL_DIR} compile
	$(MAKE) -C ${XKMS_DIR} compile
	$(MAKE) -C ${XKMSIMPL_DIR} compile

depends:
	$(MAKE) -C ${CANON_DIR} -s depends
	$(MAKE) -C ${TRANSFORMERS_DIR} -s depends
	$(MAKE) -C ${DSIG_DIR} -s depends
	$(MAKE) -C ${ENC_DIR} -s depends
	$(MAKE) -C ${OPENSSL_DIR} -s depends
	$(MAKE) -C ${XSCRYPT_DIR} -s depends
	$(MAKE) -C ${FRAMEWORK_DIR} -s depends
	$(MAKE) -C ${UTILS_DIR} -s depends
	$(MAKE) -C ${UNIXUTILS_DIR} -s depends
	$(MAKE) -C ${XKMS_DIR} -s depends
	$(MAKE) -C ${XKMSIMPL_DIR} -s depends

prepare:
	$(MKDIR) ../lib
	$(MKDIR) ../lib/obj
	$(MKDIR) ../bin
	$(MKDIR) ../bin/obj
	$(MAKE) -C ${CANON_DIR} includes
	$(MAKE) -C ${TRANSFORMERS_DIR} includes
	$(MAKE) -C ${DSIG_DIR} includes
	$(MAKE) -C ${ENC_DIR} includes
	$(MAKE) -C ${OPENSSL_DIR} includes
	$(MAKE) -C ${XSCRYPT_DIR} includes
	$(MAKE) -C ${FRAMEWORK_DIR} includes
	$(MAKE) -C ${UTILS_DIR} includes
	$(MAKE) -C ${UNIXUTILS_DIR} includes
	$(MAKE) -C ${XENC_DIR} includes
	$(MAKE) -C ${XKMS_DIR} includes

alltools: lib
	$(MAKE) -C ${TOOLS_DIR} alltools

allsamples: lib
	$(MAKE) -C ${SAMPLES_DIR} allsamples


####################### INSTALL ##########################

install: lib
	$(MAKE) -C ${CANON_DIR} install
	$(MAKE) -C ${TRANSFORMERS_DIR} install
	$(MAKE) -C ${DSIG_DIR} install
	$(MAKE) -C ${ENC_DIR} install
	$(MAKE) -C ${OPENSSL_DIR} install
	$(MAKE) -C ${XSCRYPT_DIR} install
	$(MAKE) -C ${FRAMEWORK_DIR} install
	$(MAKE) -C ${UTILS_DIR} install
	$(MAKE) -C ${UNIXUTILS_DIR} install
	$(MAKE) -C ${XENC_DIR} install
	$(MAKE) -C ${XKMS_DIR} install
	@INSTALL_COMMAND_1@
	@INSTALL_COMMAND_2@
	@INSTALL_COMMAND_3@

######################## CLEAN  ##########################


clean:
	rm -rf ../lib/*
	rm -rf ../bin/*
	rm -rf ../include/*

distclean: clean
	$(MAKE) -C ${CANON_DIR} distclean
	$(MAKE) -C ${TRANSFORMERS_DIR} distclean
	$(MAKE) -C ${DSIG_DIR} distclean
	$(MAKE) -C ${ENC_DIR} distclean
	$(MAKE) -C ${OPENSSL_DIR} distclean
	$(MAKE) -C ${XSCRYPT_DIR} distclean
	$(MAKE) -C ${FRAMEWORK_DIR} distclean
	$(MAKE) -C ${UTILS_DIR} distclean
	$(MAKE) -C ${UNIXUTILS_DIR} distclean
	$(MAKE) -C ${TOOLS_DIR} distclean
	$(MAKE) -C ${XENC_DIR} distclean
	$(MAKE) -C ${XENCIMPL_DIR} distclean
	$(MAKE) -C ${XKMS_DIR} distclean
	$(MAKE) -C ${XKMSIMPL_DIR} distclean
	rm -f config.cache
	rm -f config.status
	rm -f config.log
	rm -rf autom4te.cache
	rm -f framework/XSECConfig.hpp
	rm -f Makefile
	rm -f Makefile.bak

