/*
 * Copyright 1993 Network Computing Devices, Inc.
 *
 * Permission to use, copy, modify, distribute, and sell this software and
 * its documentation for any purpose is hereby granted without fee, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name Network Computing Devices, Inc. not be
 * used in advertising or publicity pertaining to distribution of this 
 * software without specific, written prior permission.
 * 
 * THIS SOFTWARE IS PROVIDED `AS-IS'.  NETWORK COMPUTING DEVICES, INC.,
 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
 * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NONINFRINGEMENT.  IN NO EVENT SHALL NETWORK
 * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING
 * SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA,
 * OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
 * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 * 
 * $NCDId: @(#)NetAudio.tmpl,v 1.24 1994/09/27 16:51:26 greg Exp $
 */

#if WantAutoSharedAudioLibrary
#define NormalLibAudio          NormalLibX
#define SharedLibAudio          SharedLibX
#define DebugLibAudio           DebugLibX
#define ProfileLibAudio         ProfileLibX
#else
#define NormalLibAudio		YES
#define SharedLibAudio		NO
#define DebugLibAudio		NO
#define ProfileLibAudio		NO
#endif

/*
 * Enable the next line if <NetAudio.tmpl> and audio include files/libraries
 * are installed for normal use via installed imake or xmkmf into the 
 * installed X11 area.  
 */
#if 0
#define AuUseInstalled YES
#endif

/*
 * _AuUse - makes a choice based on AuUseInstalled.
 */
#ifndef _AuUse
#ifdef AuUseInstalled
#define _AuUse(a,b) a
#else
#define _AuUse(a,b) b
#endif
#endif

/*
 * _AuUseCat - combination of _AuUse and Concat.
 *           exists to avoid problems with some preprocessors
 */
#ifndef _AuUseCat
#if __STDC__ && !defined(UnixCpp)
#ifdef AuUseInstalled
#define _AuUseCat(a,b,c) a##c
#else
#define _AuUseCat(a,b,c) b##c
#endif
#else
#ifdef AuUseInstalled
#define _AuUseCat(a,b,c) a/**/c
#else
#define _AuUseCat(a,b,c) b/**/c
#endif
#endif
#endif

         AUSRC = $(TOP)/lib/audio

#if SharedLibAudio
/*
 * Shared library support is unfortunatly different on every machine
 */
#ifndef SharedAudioRev
#define SharedAudioRev 2.0
#endif
    SOAUDIOREV = SharedAudioRev
/* 
 * If not AuUseInstalled, search audio source area before installed area.
 * That way, the binary will use the source area library if invoked
 * from the source area for testing, and the installed version
 * if invoked elsewhere.
 */

#ifdef SunArchitecture
      DEPAULIB = 
#if SystemV4	/* Solaris 2 */
/* 
 * Solaris 2.3 standard imake config files omits the -R$(USRLIBDIR) option, so 
 * supplying it here helps ease installation on such systems.
 */
 LOCAL_LDFLAGS = _AuUse(-L$(USRLIBDIR) -R$(USRLIBDIR), -L$(AUSRC) -R$(AUSRC) -L$(USRLIBDIR) -R$(USRLIBDIR))
         AULIB = -laudio
#else		/* SunOS 4 */
 LOCAL_LDFLAGS = _AuUse(-L$(USRLIBDIR), -L$(AUSRC) -L$(USRLIBDIR))
         AULIB = -laudio
#endif
#else /* SunArchitecture */

/* place #ifdef's for other architectures around these lines */
 LOCAL_LDFLAGS = _AuUse(-L$(USRLIBDIR), -L$(AUSRC) -L$(USRLIBDIR))
      DEPAULIB =
         AULIB = -laudio

#endif /* SunArchitecture */


#else /* SharedLibAudio */
 LOCAL_LDFLAGS =
      DEPAULIB = _AuUseCat($(USRLIBDIR),$(AUSRC),/libaudio.a)
         AULIB = LoaderLibPrefix _AuUse(-laudio,$(DEPAULIB))
#endif /* SharedLibAudio */

  AUDIODEPLIBS = $(DEPAULIB) $(DEPXTOOLLIB) $(DEPXLIB)
     AUDIOLIBS = $(AULIB) $(XTOOLLIB) $(XLIB) -lm
  BUILDINCROOT = $(TOP)/usr.include
   BUILDINCDIR = $(BUILDINCROOT)
EXTRA_INCLUDES = -I$(BUILDINCROOT)
    INCLUDESRC = $(TOP)/usr.include
        INCDIR = $(INCROOT)/audio
    WIDGET_DIR = $(TOP)/clients/audio/widgets
    WIDGET_LIB = $(WIDGET_DIR)/libwidgets.a
    WIDGET_INC = -I$(WIDGET_DIR)


#if ProjectX < 5 	/* override search order for X11R4 */
   ALLINCLUDES = $(INCLUDES) $(EXTRA_INCLUDES) $(TOP_INCLUDES) $(STD_INCLUDES)
     LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS) $(EXTRA_LDOPTIONS) $(LOCAL_LDFLAGS)

#ifndef XCOMM
#define XCOMM #
#endif
#endif

#if SystemV4 && !defined(SGIArchitecture) && !defined(SunArchitecture) && !defined(LabtamArchitecture)
     SYS_LIBS = -lc /usr/ucblib/libucb.a
#endif

/*
 * Rules
 */

#define	AuInstallScript(program,dest)					    @@\
install:: program							    @@\
	MakeDir($(DESTDIR)dest)						    @@\
	$(INSTALL) -c $(INSTBINFLAGS) program $(DESTDIR)dest/program

#define	AuInstallManPage(file,destdir) AuInstallManPageLong(file,destdir,file)

#define	AuInstallManPageLong(file,destdir,dest)				    @@\
install.man:: file.man							    @@\
	@(rel=`cat $(TOP)/RELEASE | \				     	    @@\
	  sed 's/Network Audio System Release //'`; \			    @@\
	  sed -f $(TOP)/config/mungeman \				    @@\
	      -e "s/_RELEASE_/$$rel/" < file.man > tmp.man)		    @@\
	InstallManPageLong(tmp,destdir,dest)				    @@\
	@$(RM) tmp.man

#define SingleAudioProgram(program)					    @@\
	InstallProgram(program,$(BINDIR))				    @@\
	AuInstallManPage(program,$(MANDIR))				    @@\
	SingleProgramTarget(program, program.o, $(AUDIOLIBS), $(SYS_LIBS))

#define SimpleAudioProgram(program)					    @@\
	AudioProgram(program, program.c, program.o)

#define	AuComplexProgramTarget(program)					    @@\
        PROGRAM = program						    @@\
									    @@\
AllTarget(program)							    @@\
									    @@\
program: $(OBJS) $(DEPLIBS)						    @@\
	RemoveTargetProgram($@)						    @@\
	$(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS) @@\
									    @@\
InstallProgram(program,$(BINDIR))					    @@\
AuInstallManPage(program,$(MANDIR))					    @@\
DependTarget()								    @@\
LintTarget()								    @@\
									    @@\
clean::									    @@\
	$(RM) $(PROGRAM)

#define AudioProgram(program, srcs, objs)				    @@\
        DEPLIBS = $(AUDIODEPLIBS)					    @@\
LOCAL_LIBRARIES = $(AUDIOLIBS)						    @@\
  SYS_LIBRARIES = $(SYS_LIBS) 						    @@\
           SRCS = srcs							    @@\
           OBJS = objs							    @@\
									    @@\
AuComplexProgramTarget(program)

#define SimpleAudioXtProgram(program)					    @@\
	AudioXtProgram(program, program.c, program.o)

#define AudioXtProgram(program, srcs, objs)				    @@\
        DEPLIBS = $(AUDIODEPLIBS) $(WIDGET_LIB) XawClientDepLibs	    @@\
LOCAL_LIBRARIES = $(AUDIOLIBS) $(WIDGET_LIB) XawClientLibs		    @@\
  SYS_LIBRARIES = $(SYS_LIBS) 						    @@\
       INCLUDES = $(WIDGET_INC)						    @@\
           SRCS = srcs							    @@\
           OBJS = objs							    @@\
									    @@\
AuComplexProgramTarget(program)

#define BuildReleaseHeader()						    @@\
release.h: $(TOP)/RELEASE				    		    @@\
	@echo "static char *release = \"@(#)`cat $(TOP)/RELEASE`\";" > $@   @@\
						    			    @@\
depend:: release.h				    			    @@\
						    			    @@\
clean::			    			    			    @@\
	$(RM) release.h
