/*
 * SVR4 shared library rules
 */

XCOMM $XFree86: xc/config/cf/sv4Lib.rules,v 3.16 2006/03/29 01:35:42 dawes Exp $
/*
 * Copyright (c) 1994-2004 by The XFree86 Project, Inc.
 * All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject
 * to the following conditions:
 *
 *   1.  Redistributions of source code must retain the above copyright
 *       notice, this list of conditions, and the following disclaimer.
 *
 *   2.  Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer
 *       in the documentation and/or other materials provided with the
 *       distribution, and in the same place and form as other copyright,
 *       license and disclaimer information.
 *
 *   3.  The end-user documentation included with the redistribution,
 *       if any, must include the following acknowledgment: "This product
 *       includes software developed by The XFree86 Project, Inc
 *       (http://www.xfree86.org/) and its contributors", in the same
 *       place and form as other third-party acknowledgments.  Alternately,
 *       this acknowledgment may appear in the software itself, in the
 *       same form and location as other such third-party acknowledgments.
 *
 *   4.  Except as contained in this notice, the name of The XFree86
 *       Project, Inc shall not be used in advertising or otherwise to
 *       promote the sale, use or other dealings in this Software without
 *       prior written authorization from The XFree86 Project, Inc.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE XFREE86 PROJECT, INC OR ITS CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef HasSharedLibraries
# define HasSharedLibraries YES
#endif
#ifndef SharedDataSeparation
# define SharedDataSeparation NO
#endif
#ifndef HasGcc2ForCplusplus
# define HasGcc2ForCplusplus HasGcc2
#endif
#ifndef SharedCodeDef
# define SharedCodeDef /**/
#endif
#ifndef SharedLibraryDef
# define SharedLibraryDef /**/
#endif
#ifndef ShLibIncludeFile
# define ShLibIncludeFile <sv4Lib.tmpl>
#endif
#ifndef SharedLibraryLoadFlags
# define SharedLibraryLoadFlags -G -z text
#endif
#ifndef PositionIndependentCFlags
# if HasGcc2
#  define PositionIndependentCFlags -fPIC
# else
#  define PositionIndependentCFlags -K PIC
# endif
#endif
#ifndef PositionIndependentCplusplusFlags
# if HasGcc2ForCplusplus
#  define PositionIndependentCplusplusFlags -fPIC
# else
#  define PositionIndependentCplusplusFlags -K PIC
# endif
#endif
#ifndef UseExportLists
# define UseExportLists NO
#endif
#ifndef StripInstalledPrograms
# define StripInstalledPrograms NO
#endif

/*
 * InstallSharedLibrary - generate rules to install the shared library.
 */
#ifndef InstallSharedLibrary
#if StripInstalledPrograms
# define InstallSharedLibrary(libname,rev,dest)				@@\
install::								@@\
	MakeDir($(DESTDIR)dest)						@@\
	$(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) Concat($(LIBPREFIX),libname.so.rev) $(DESTDIR)dest @@\
	mcs -d Concat($(DESTDIR)dest/$(LIBPREFIX),libname.so.rev)	@@\
	@if $(SOSYMLINK); then (set -x; \				@@\
	  $(RM) Concat($(DESTDIR)dest/$(LIBPREFIX),libname.so); \	@@\
	  cd $(DESTDIR)dest; \						@@\
	  $(LN) Concat($(LIBPREFIX),libname.so.rev) Concat($(LIBPREFIX),libname.so)); fi
#else
# define InstallSharedLibrary(libname,rev,dest)				@@\
install::								@@\
	MakeDir($(DESTDIR)dest)						@@\
	$(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) Concat($(LIBPREFIX),libname.so.rev) $(DESTDIR)dest @@\
	@if $(SOSYMLINK); then (set -x; \				@@\
	  $(RM) Concat($(DESTDIR)dest/$(LIBPREFIX),libname.so); \	@@\
	  cd $(DESTDIR)dest; \						@@\
	  $(LN) Concat($(LIBPREFIX),libname.so.rev) Concat($(LIBPREFIX),libname.so)); fi
#endif

#endif /* InstallSharedLibrary */

/*
 * InstallSharedLibraryData - generate rules to install the shared library data
 */
#ifndef InstallSharedLibraryData
# define InstallSharedLibraryData(libname,rev,dest)
#endif /* InstallSharedLibraryData */

#ifndef LinkWithExports
# if UseExportLists
#  define LinkWithExports(libname,rev,solist,down,up) \
	(cd down; $(CCENVSETUP) $(LD) -o up/$@~ $(SHLIBLDFLAGS) -h $@ solist $(REQUIREDLIBS))	@@\
	if [ -f Concat(lib,libname.elist) ]; then \			@@\
	    $(RM) down/$@.exports $@.list; \				@@\
	    $(CPP) $(ALLINCLUDES) $(EXTRA_DEFINES) $(PROTO_DEFINES) $(THREADS_DEFINES) $(DEFINES) Concat(lib,libname.elist) | CppSedMagic >$@.list; \	@@\
	    $(EXPORTLISTGEN) $@~ $@.list > down/$@.exports; \		@@\
	    (cd down; $(CCENVSETUP) $(LD) -o up/$@~ $(SHLIBLDFLAGS) -h $@ ShlibExportListOpt($@.exports) solist $(REQUIREDLIBS)); \	@@\
	    $(RM) down/$@.exports $@.list; \				@@\
	fi;
# else
#  define LinkWithExports(libname,rev,solist,down,up) \
	(cd down; $(CCENVSETUP) $(LD) -o up/$@~ $(SHLIBLDFLAGS) -h $@ solist $(REQUIREDLIBS))
# endif
#endif

/*
 * SharedLibraryTarget - generate rules to create a shared library;
 * build it into a different name so that we do not hose people by having
 * the library gone for long periods.
 */
#ifndef SharedLibraryTarget
# define SharedLibraryTarget(libname,rev,solist,down,up)		@@\
AllTarget(Concat($(LIBPREFIX),libname.so.rev))				@@\
									@@\
Concat($(LIBPREFIX),libname.so.rev):  solist $(EXTRALIBRARYDEPS)	@@\
	$(RM) $@~							@@\
	LinkWithExports(libname,rev,solist,down,up)			@@\
	$(RM) $@ 							@@\
	$(MV) $@~ $@							@@\
	@if $(SOSYMLINK); then (set -x; \				@@\
	  $(RM) Concat($(LIBPREFIX),libname.so); \			@@\
	  $(LN) $@ Concat($(LIBPREFIX),libname.so)); fi			@@\
	LinkBuildLibrary($@)						@@\
	LinkBuildLibraryMaybe(Concat($(LIBPREFIX),libname.so),$(SOSYMLINK)) @@\
									@@\
clean::									@@\
	$(RM) Concat($(LIBPREFIX),libname.so.rev) Concat($(LIBPREFIX),libname.so)

#endif /* SharedLibraryTarget */

/*
 * SharedDepLibraryTarget - generate rules to create a shared library.
 */
#ifndef SharedDepLibraryTarget
# define SharedDepLibraryTarget(libname,rev,deplist,solist,down,up)	@@\
AllTarget(Concat($(LIBPREFIX),libname.so.rev))				@@\
									@@\
Concat($(LIBPREFIX),libname.so.rev):  deplist $(EXTRALIBRARYDEPS)	@@\
	$(RM) $@~							@@\
	LinkWithExports(libname,rev,solist,down,up)			@@\
	$(RM) $@ 							@@\
	$(MV) $@~ $@							@@\
	@if $(SOSYMLINK); then (set -x; \				@@\
	  $(RM) Concat($(LIBPREFIX),libname.so); \			@@\
	  $(LN) $@ Concat($(LIBPREFIX),libname.so)); fi			@@\
	LinkBuildLibrary($@)						@@\
	LinkBuildLibraryMaybe(Concat($(LIBPREFIX),libname.so),$(SOSYMLINK)) @@\
									@@\
clean::									@@\
	$(RM) Concat($(LIBPREFIX),libname.so.rev) Concat($(LIBPREFIX),libname.so)

#endif /* SharedDepLibraryTarget */


#ifndef SharedDepModuleTarget
#define SharedDepModuleTarget(name,deps,solist)				@@\
AllTarget(name)								@@\
									@@\
name: deps								@@\
	$(RM) $@~							@@\
	$(LD) -o $@~ $(SHLIBLDFLAGS) solist $(REQUIREDLIBS)		@@\
	$(RM) $@							@@\
	$(MV) $@~ $@							@@\
									@@\
clean::									@@\
	$(RM) name

#endif /* SharedDepModuleTarget */


/*
 * SharedLibraryDataTarget - generate rules to create shlib data file;
 */
#ifndef SharedLibraryDataTarget
# define SharedLibraryDataTarget(libname,rev,salist)
#endif /* SharedLibraryTarget */

/*
 * The 64-bit library build support is covered by the XFree86 1.1 license.
 * Author: Mark Kandianis.
 */
/*
 * Copyright (c) 2004 by The XFree86 Project, Inc.
 * All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject
 * to the following conditions:
 *
 *   1.  Redistributions of source code must retain the above copyright
 *       notice, this list of conditions, and the following disclaimer.
 *
 *   2.  Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer
 *       in the documentation and/or other materials provided with the
 *       distribution, and in the same place and form as other copyright,
 *       license and disclaimer information.
 *
 *   3.  The end-user documentation included with the redistribution,
 *       if any, must include the following acknowledgment: "This product
 *       includes software developed by The XFree86 Project, Inc
 *       (http://www.xfree86.org/) and its contributors", in the same
 *       place and form as other third-party acknowledgments.  Alternately,
 *       this acknowledgment may appear in the software itself, in the
 *       same form and location as other such third-party acknowledgments.
 *
 *   4.  Except as contained in this notice, the name of The XFree86
 *       Project, Inc shall not be used in advertising or otherwise to
 *       promote the sale, use or other dealings in this Software without
 *       prior written authorization from The XFree86 Project, Inc.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE XFREE86 PROJECT, INC OR ITS CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef Build64BitLibraries
#define Build64BitLibraries NO
#endif

#if Build64BitLibraries

#define ExtraLibRules

#ifndef Shared64Dir
#define Shared64Dir 64
#endif

SHARED64DIR = Shared64Dir

#ifndef Shared64LibraryDef
#define Shared64LibraryDef SharedLibraryDef
#endif

#ifndef Shared64LibraryLoadFlags
#define Shared64LibraryLoadFlags SharedLibraryLoadFlags
#endif

SHLIB64LDFLAGS = Shared64LibraryLoadFlags

#ifndef Shared64PositionIndependentCFlags
#ifdef LargePositionIndependentCFlags
#define Shared64PositionIndependentCFlags LargePositionIndependentCFlags
#else
#define Shared64PositionIndependentCFlags PositionIndependentCFlags
#endif
#endif

#ifndef InstallShared64Library
#define InstallShared64Library(libname,rev,dest)			@@\
install:: Concat(Shared64Dir/lib,libname.so.rev)			@@\
	MakeDir($(DESTDIR)dest)						@@\
	$(INSTALL) -c $(INSTLIBFLAGS) Concat(Shared64Dir/lib,libname.so.rev) $(DESTDIR)dest @@\
	@if $(SOSYMLINK); then (set -x; \				@@\
	  $(RM) Concat($(DESTDIR)dest/lib,libname.so); \		@@\
	  cd $(DESTDIR)dest; \						@@\
	  $(LN) Concat(lib,libname.so.rev) Concat(lib,libname.so)); fi
#endif

#ifndef Link64WithExports
# if UseExportLists
#  define Link64WithExports(libname,rev,solist,down,up) \
	$(CCENVSETUP) $(LD) -o $@~ $(SHLIB64LDFLAGS) -h Concat(lib,libname.so.rev) solist $(REQUIREDLIBS)	@@\
	@if [ -f Concat(lib,libname.elist) ]; then \			@@\
	    (set -x; $(RM) libname.exports libname.list; \		@@\
	    $(CPP) $(ALLINCLUDES) $(EXTRA_DEFINES) $(PROTO_DEFINES) $(THREADS_DEFINES) $(DEFINES) Concat(lib,libname.elist) | CppSedMagic >libname.list; \	@@\
	    $(EXPORTLISTGEN) $@~ libname.list > libname.exports; \	@@\
	    $(CCENVSETUP) $(LD) -o $@~ $(SHLIB64LDFLAGS) -h $@ ShlibExportListOpt(libname.exports) solist $(REQUIREDLIBS); \	@@\
	    $(RM) libname.exports libname.list); \			@@\
	fi;
# else
#  define Link64WithExports(libname,rev,solist,down,up) \
	$(CCENVSETUP) $(LD) -o $@~ $(SHLIB64LDFLAGS) -h $@ solist $(REQUIREDLIBS)
# endif
#endif

#ifndef Shared64LibraryTarget
#define Shared64LibraryTarget(libname,rev,solist,down,up)		@@\
AllTarget(Concat(down/lib,libname.so.rev))				@@\
									@@\
Concat(down/lib,libname.so.rev): solist $(EXTRALIBRARYDEPS)		@@\
	$(RM) $@~							@@\
	Link64WithExports(libname,rev,solist,down,up)			@@\
	$(RM) $@							@@\
	$(MV) $@~ $@							@@\
	@if $(SOSYMLINK); then (set -x; \				@@\
	  $(RM) Concat(down/lib,libname.so); \				@@\
	  $(LN) Concat(lib,libname.so.rev) Concat(down/lib,libname.so)); fi @@\
	LinkBuildLibrarySubdir($@,down,up)				@@\
	LinkBuildLibrarySubdirMaybe(Concat(down/lib,libname.so),down,up,$(SOSYMLINK)) @@\
									@@\
clean::									@@\
	        $(RM) Concat(down/lib,libname.so.rev)			@@\
		$(RM) Concat(down/lib,libname.so)
#endif /* Shared64LibraryTarget */

#ifndef Shared64DepLibraryTarget
#define Shared64DepLibraryTarget(libname,rev,deplist,solist,down,up)	@@\
AllTarget(Concat(down/lib,libname.so.rev))				@@\
									@@\
Concat(down/lib,libname.so.rev): deplist $(EXTRALIBRARYDEPS)		@@\
	$(RM) $@~							@@\
	Link64WithExports(libname,rev,solist,down,up)			@@\
	$(RM) $@							@@\
	$(MV) $@~ $@							@@\
	@if $(SOSYMLINK); then (set -x; \				@@\
	  $(RM) Concat(down/lib,libname.so); \				@@\
	  $(LN) Concat(lib,libname.so.rev) Concat(down/lib,libname.so)); fi @@\
	LinkBuildLibrarySubdir($@,down,up)				@@\
	LinkBuildLibrarySubdirMaybe(Concat(down/lib,libname.so),down,up,$(SOSYMLINK)) @@\
									@@\
clean::									@@\
	        $(RM) Concat(down/lib,libname.so.rev)			@@\
		$(RM) Concat(down/lib,libname.so)
#endif /* Shared64DepLibraryTarget */

#define Shared64CDebugFlags $(CDEBUGFLAGS) $(CLIBDEBUGFLAGS)
#define Shared64CplusplusDebugFlags $(CXXDEBUGFLAGS) $(CXXLIBDEBUGFLAGS)
#if HasGcc
#define Shared64CArchFlags -m64
#define Shared64CplusplusArchFlags -m64
#define Shared64AsmOptions -m64
#else
#define Shared64CArchFlags -xarch=v9
#define Shared64CplusplusArchFlags xarch=v9
#define Shared64AsmOptions -xarch=v9
#endif


#define Shared64LibObjCompile(options) LibObjCompile(Shared64Dir,Shared64CArchFlags Shared64CDebugFlags Shared64LibraryDef Shared64PositionIndependentCFlags options)
#define Shared64LibObjAsm(options) LibObjAsm(Shared64Dir,-D__sparc_v9__ options,Shared64AsmOptions)
#define Shared64LibObjCplusplusCompile(options) LibObjCompile(Shared64Dir,Shared64CplusplusArchFlags Shared64CplusplusDebugFlags Shared64LibraryDef Shared64PositionIndependentCFlags options)

#define ExtraSubdir Shared64Dir
EXTRASUBDIR = ExtraSubdir
#define ObjectPrefix ExtraSubdir/
#define ExtraLibMkdir() _LibMkdir(Shared64Dir)
#define ExtraObjCompile(options) Shared64LibObjCompile(options)
#define ExtraObjAsm(options) Shared64LibObjAsm(options)
#define ExtraObjCplusplusCompile(options) Shared64LibObjCplusplusCompile(options)
#define ExtraCleanDir() LibCleanDir(Shared64Dir)

#define ExtraLibraryTarget(libname,so,objs) Shared64LibraryTarget(libname,so,objs,Shared64Dir,..)
#define ExtraDepLibraryTarget(libname,so,deplist,objs) Shared64DepLibraryTarget(libname,so,deplist,objs,Shared64Dir,..)
#define ExtraInstallLibrary(libname,so) InstallShared64Library(libname,so,$(SHLIBDIR)/Shared64Dir)

#if !defined(UseInstalled) && !defined(LdPreLib)
#define LdPreLib -L$(BUILDLIBDIR)/Shared64Dir -L$(BUILDLIBDIR)
#endif

#endif
