XCOMM $XFree86: xc/config/cf/darwinLib.rules,v 1.4 2002/01/16 00:39:59 keithp Exp $
/*
 * Darwin/Mac OS X shared library rules
 */

#ifndef UseElfFormat
#define UseElfFormat NO
#endif
#ifndef HasSharedLibraries
#define HasSharedLibraries YES
#endif
#ifndef ForceNormalLib
#define ForceNormalLib YES
#endif

#ifndef SharedDataSeparation
#define SharedDataSeparation NO
#endif
#ifndef SharedCodeDef
#define SharedCodeDef /**/
#endif
#ifndef SharedLibraryDef
#define SharedLibraryDef /**/
#endif
#ifndef ShLibIncludeFile
#define ShLibIncludeFile <darwinLib.tmpl>
#endif
#ifndef SharedLibraryLoadFlags
#define SharedLibraryLoadFlags -dynamiclib
#endif
#ifndef PositionIndependentCFlags
#define PositionIndependentCFlags -dynamic
#endif
#ifndef ExtraLoadFlags
#define ExtraLoadFlags /**/
#endif

/*
 * InstallSharedLibrary - generate rules to install the shared library.
 */
#ifndef InstallSharedLibrary
#define InstallSharedLibrary(libname,rev,dest)				@@\
install:: Concat(lib,libname.rev.dylib)					@@\
	MakeDir($(DESTDIR)dest)						@@\
	$(INSTALL) $(INSTALLFLAGS) $(INSTLIBFLAGS) Concat(lib,libname.rev.dylib) $(DESTDIR)dest @@\
	@MAJREV=`expr rev : '\([^.]*\)'`; \				@@\
	  set -x; $(RM) Concat($(DESTDIR)dest/lib,libname.$$MAJREV.dylib) && \ @@\
	  $(LN) Concat(lib,libname.rev.dylib) Concat($(DESTDIR)dest/lib,libname.$$MAJREV.dylib) @@\
	@if $(SOSYMLINK); then (set -x; \				@@\
	  $(RM) Concat($(DESTDIR)dest/lib,libname.dylib); \		@@\
	  $(LN) Concat(lib,libname.rev.dylib) Concat($(DESTDIR)dest/lib,libname.dylib)); fi
#endif /* InstallSharedLibrary */

/*
 * 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
#ifdef UseInstalled
#define LinkBuildSonameLibrary(lib) true
#else
#define LinkBuildSonameLibrary(lib) (RemoveFile($(BUILDLIBDIR)/lib); \
	cd $(BUILDLIBDIR); $(LN) $(BUILDINCTOP)/$(CURRENT_DIR)/lib .)
#endif

#define SharedLibraryTarget(libname,rev,solist,down,up)			@@\
AllTarget(Concat(lib,libname.rev.dylib))				@@\
									@@\
Concat(lib,libname.rev.dylib):  solist $(EXTRALIBRARYDEPS)		@@\
	$(RM) $@~							@@\
	@MAJREV=`expr rev : '\([^.]*\)'`; \				@@\
	  INSTALLNAME=Concat(lib,libname.$$MAJREV.dylib); \		@@\
	  set -x; (cd down; $(CC) -o up/$@~ $(SHLIBLDFLAGS) -install_name $(USRLIBDIR)/$$INSTALLNAME -current_version rev -compatibility_version rev solist $(REQUIREDLIBS)); \ @@\
	  $(RM) $$INSTALLNAME; $(LN) $@ $$INSTALLNAME; \		@@\
	  LinkBuildSonameLibrary($$INSTALLNAME)				@@\
	$(RM) $@							@@\
	$(MV) $@~ $@							@@\
	@if $(SOSYMLINK); then (set -x; \				@@\
	  $(RM) Concat(lib,libname.dylib); \				@@\
	  $(LN) $@ Concat(lib,libname.dylib)); fi			@@\
	LinkBuildLibrary($@)						@@\
	LinkBuildLibraryMaybe(Concat(lib,libname.dylib),$(SOSYMLINK))	@@\
									@@\
clean::									@@\
	@MAJREV=`expr rev : '\([^.]*\)'`; \				@@\
	set -x; $(RM) Concat(lib,libname.$$MAJREV.dylib)		@@\
	$(RM) Concat(lib,libname.rev.dylib) Concat(lib,libname.dylib)

#endif /* SharedLibraryTarget */

/*
 * SharedDepLibraryTarget - generate rules to create a shared library.
 */
#ifndef SharedDepLibraryTarget
#ifdef UseInstalled
#ifndef LinkBuildSonameLibrary
#define LinkBuildSonameLibrary(lib) true
#endif
#else
#ifndef LinkBuildSonameLibrary
#define LinkBuildSonameLibrary(lib) (RemoveFile($(BUILDLIBDIR)/lib); \
	cd $(BUILDLIBDIR); $(LN) $(BUILDINCTOP)/$(CURRENT_DIR)/lib .)
#endif
#endif

#define SharedDepLibraryTarget(libname,rev,deplist,solist,down,up)	@@\
AllTarget(Concat(lib,libname.rev.dylib))				@@\
									@@\
Concat(lib,libname.rev.dylib):  deplist $(EXTRALIBRARYDEPS)		@@\
	$(RM) $@~							@@\
	@MAJREV=`expr rev : '\([^.]*\)'`; \				@@\
	  INSTALLNAME=Concat(lib,libname.$$MAJREV.dylib); \		@@\
	  set -x; (cd down; $(CC) -o up/$@~ $(SHLIBLDFLAGS) -install_name $(USRLIBDIR)/$$INSTALLNAME -current_version rev -compatibility_version rev solist $(REQUIREDLIBS)); \ @@\
	  $(RM) $$INSTALLNAME; $(LN) $@ $$INSTALLNAME; \		@@\
	  LinkBuildSonameLibrary($$INSTALLNAME)				@@\
	$(RM) $@							@@\
	$(MV) $@~ $@							@@\
	@if $(SOSYMLINK); then (set -x; \				@@\
	  $(RM) Concat(lib,libname.dylib); \				@@\
	  $(LN) $@ Concat(lib,libname.dylib)); fi			@@\
	LinkBuildLibrary($@)						@@\
	LinkBuildLibraryMaybe(Concat(lib,libname.dylib),$(SOSYMLINK))	@@\
									@@\
clean::									@@\
	@MAJREV=`expr rev : '\([^.]*\)'`; \				@@\
	set -x; $(RM) Concat(lib,libname.$$MAJREV.dylib)		@@\
	$(RM) Concat(lib,libname.rev.dylib) Concat(lib,libname.dylib)

#endif /* SharedDepLibraryTarget */

#ifndef SharedDepModuleTarget
#define SharedDepModuleTarget(name,deps,solist)				@@\
AllTarget(name)								@@\
									@@\
name: deps								@@\
	$(RM) $@~							@@\
	$(CC) -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 /* SharedLibraryDataTarget */

#ifndef InstallSharedLibraryData
#define InstallSharedLibraryData(libname,rev,dest)
#endif /* InstallSharedLibraryData */
