#===========================================================================
#
# OPUS/SHARE Makefile
#
# author: Scott Binegar
#
# This file goes in both the src/libs and src/apps directories.
# It calls either all of the .make files or just the .make file for a
# particular target.  In the following examples, the command follows
# the explaination and is preceeded by the % (prompt).
#
# Examples:
#
# To build all files in the directory just type the command:
#	% gmake 
# 
# To only build one specific application (like oapi) type the command:
#	% gmake oapi
#
# To delete files generated for one specific application (like oapi):
#	% gmake oapi.clean
#
# 05/15/02   45317  WMiller  Support Linux
# 10/29/02   46765  Sontag   Put in conditionals for Linux.
# 01/31/03   47450  Sontag   Added lines for AIX
# 04/26/03   48141  MSwam    Filter out kwset for Linux,AIX
# 06/24/03   47450  Sontag   Changes for AIX
# 03/18/04   50605  Sontag   We can build destest on Linux and AIX
# 07/20/04   49860  Sontag   Build joapi on Windows via MinGW
# 10/10/06   52073  Sontag   Move build restrictions to their .make files
# 01/19/07   57334  Sontag   eqn_test_driver can be built anywhere
# 12/23/09   63939  MSwam    add SOLARIS,BIG_ENDIAN settings
#===========================================================================
#
# Delete implicit rules 
.SUFFIXES:

ifndef TOPDIR
        TOPDIR:=$(shell pwd | sed -e 's?/src.*??')
endif

MAKE+= -I $(TOPDIR)/src --no-print-directory --no-builtin-rules
#
# Determine the operating system
#
OSNAME:=$(shell uname)

ifeq ($(OSNAME),OSF1)
# Set the definitions for Tru64
  ITS_AXP_UNIX := 1
  export ITS_AXP_UNIX
endif

ifeq ($(OSNAME),SunOS)
# Set the definitions for Sun Solaris
  ITS_BIG_ENDIAN := 1
  ITS_SPARC_SOLARIS := 1
  export ITS_SPARC_SOLARIS 
endif

ifeq ($(OSNAME),Linux)
# Set the definitions for Linux
  ITS_LINUX := 1
  export ITS_LINUX
endif

ifeq ($(OSNAME),AIX)
# Set the definitions for AIX
  ITS_BIG_ENDIAN := 1
  ITS_IBM_AIX := 1
  export ITS_IBM_AIX
endif

ifeq ($(OSNAME),Darwin)
# Set the definitions for Mac OSX
  ITS_PPC_OSX := 1
  export ITS_PPC_OSX
endif

# Include the individual application makefiles
#
target_files := $(wildcard *.make)
targets := $(basename $(target_files))

# Build the servers first so we don't have to wait as long to test a new bld
targets := $(filter-out opus_bb_server opus_env_server, $(targets))
targets := $(filter-out opus_event_service opus_server_monitor, $(targets))
targets := $(filter-out osfile_stretch_file opus_id, $(targets))
#
targets := opus_bb_server opus_event_service opus_server_monitor $(targets)
targets := osfile_stretch_file opus_id opus_env_server $(targets)

# On Cygwin we don't much care about execs (for now) so just build a token eg
ifeq ($(findstring CYGWIN,$(OSNAME)),CYGWIN)
	# consumer_test also builds, tho w/ non-jni-joapi
	targets := time_stamp test_SAX_parser eqn_test_driver
endif

all : $(targets)

$(targets) : FORCE
	@$(MAKE) -f $@.make

FORCE:

%.clean : %.make
	@$(MAKE) -f $< clean

vpath %.include $(TOPDIR)/src

include $(TOPDIR)/src/Makeshare.include
