/*	$NetBSD: xpkgwedge.def,v 1.11 2004/04/30 19:44:21 tv Exp $	*/

#ifdef BeforeVendorCF

/*
 * OS-specific overrides for Interix to make it behave similarly to NetBSD
 * when creating binaries for pkgsrc.
 */
#ifdef __INTERIX
#undef  ForceNormalLib /* this is always YES on Interix */
#define NullMakeCommand @ true
#define SharedLibraryLoadFlags -shared -Wl,-rpath,$(USRLIBDIRPATH)

#ifdef UseInstalled  
#define ExtraLoadFlags -Wl,-rpath,$(USRLIBDIRPATH)
#define LinkBuildSonameLibrary(lib) true
#else
#define ExtraLoadFlags -Wl,-rpath,$(USRLIBDIRPATH) -Wl,-rpath-link,$(BUILDLIBDIR)
#define LinkBuildSonameLibrary(lib) (RemoveFile($(BUILDLIBDIR)/lib); \
	cd $(BUILDLIBDIR); $(LN) $(BUILDINCTOP)/$(CURRENT_DIR)/lib .)
#endif

/*
 * Oy, what a hack: see pkgsrc/devel/libtool for an explanation of the
 * bizarre --image-base option used below.
 */
#define SharedLibraryTarget(libname,rev,solist,down,up)			@@\
AllTarget(Concat(lib,libname.so.rev))					@@\
									@@\
Concat(lib,libname.so.rev):  solist					@@\
	$(RM) $@~							@@\
	@SONAME=`echo $@ | sed 's/\.[^\.]*$$//'`; set -x; \		@@\
		(cd down; $(CC) -o up/$@~ $(SHLIBLDFLAGS) \		@@\
			-Wl,--image-base,$$(($$RANDOM %4096/2*262144+1342177280)) \ @@\
			-Wl,-h,$$SONAME solist $(REQUIREDLIBS)); \	@@\
		$(RM) $$SONAME; $(LN) $@ $$SONAME; \			@@\
		LinkBuildSonameLibrary($$SONAME)			@@\
	$(RM) $@							@@\
	$(MV) $@~ $@							@@\
	LinkBuildLibrary($@)						@@\
	$(RM) Concat(lib,libname.so)					@@\
	$(LN) $@ Concat(lib,libname.so)					@@\
	LinkBuildLibrary(Concat(lib,libname.so))			@@\
									@@\
clean::									@@\
	@SONAME=`echo Concat(lib,libname.so.rev) | sed 's/\.[^\.]*$$//'`; \ @@\
	set -x; $(RM) $$SONAME						@@\
	$(RM) Concat(lib,libname.so)					@@\
	$(RM) Concat(lib,libname.so.rev)

#define InstallSharedLibrary(libname,rev,dest)				@@\
install:: Concat(lib,libname.so.rev)					@@\
	MakeDir($(DESTDIR)dest)						@@\
	$(INSTALL) $(INSTALLFLAGS) $(INSTBINFLAGS) Concat(lib,libname.so.rev) $(DESTDIR)dest @@\
	@T=`echo Concat($(DESTDIR)dest/lib,libname.so.rev) | sed 's/\.[^\.]*$$//'`;\ @@\
	  set -x; $(RM) $$T && $(LN) Concat(lib,libname.so.rev) $$T	@@\
	$(RM) Concat($(DESTDIR)dest/lib,libname.so)			@@\
	$(LN) Concat(lib,libname.so.rev) Concat($(DESTDIR)dest/lib,libname.so)

#endif /* __INTERIX && BeforeVendorCF */

#endif /* BeforeVendorCF */

#ifdef AfterVendorCF

/*
 * The following defines inject a "PREFIX=" make-time option that lets the
 * user twiddle the ProjectRoot setting with a single switch.  This makes
 * the command "make PREFIX=/path/to/install all install" work as expected.
 */

#ifndef ProjectRoot
/*
 * Assume the worst:  this should not happen in practice, as this setup
 * does not work with the classical /usr/{include,lib}/X11 layout.
 */
#define ProjectRoot /usr/X11
#endif

X11_ROOT = ProjectRoot

#undef ProjectRoot
#define ProjectRoot $(PREFIX)
#undef ConfigDir
#define ConfigDir $(X11_ROOT)/lib/X11/config

/*
 * This emits dual -I and -L options to cc automatically, one for the actual
 * X11 root, and one for the user-set prefix.
 */
#define X11ProjectRoot $(X11_ROOT)

/* 
 * InstallAppDefaultsLong - general rule to install application default file
 * if the InstallAppDefFiles configuration parameter is set.
 *
 * This is the same as the one in X11.tmpl, but without the LinkConfDirectory.
 * LinkConfDirectory removes the app-defaults directory in $(PREFIX)/lib/X11
 * and creates a link to the real X11 app-defaults directory and moves the old
 * app-defaults files into it. This is not what we want for pkgsrc.
 */
#ifndef InstallAppDefaultsLong
#if InstallAppDefFiles
#define InstallAppDefaultsLong(file,class)				@@\
InstallNamedTarget(install,file.ad,$(INSTAPPFLAGS),$(XAPPLOADDIR),class)
#else
#define InstallAppDefaultsLong(file,class)				@@\
InstallNamedTargetNoClobber(install,file.ad,$(INSTAPPFLAGS),$(XAPPLOADDIR),class)
#endif /* InstallAppDefFiles */
#endif /* InstallAppDefaultsLong */

#ifdef UseInstalled
/*
 * We need to redefine ImakeCmd so that imake will look in both
 * $(PREFIX)/lib/X11/config and $(VIEWBASE)/lib/X11/config *before*
 * looking in the standard X11 config directory to override any
 * configuration files installed there.
 */
#undef ImakeCmd
#define ImakeCmd imake -I$(PREFIX)/lib/X11/config -I$(VIEWBASE)/lib/X11/config
#endif

#endif /* AfterVendorCF */
