#===========================================================================
#
# 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
#
# 10/29/02   46765   Sontag   Put in conditionals for Linux.
# 01/31/03   47450   Sontag   Added lines for AIX
# 07/20/04   49860   Sontag   Build joapi on Windows via MinGW
# 01/14/05   52462   Sontag   Added osys_proc library
# 03/01/05   51433   Sontag   The obssf lib was removed
# 12/01/05   42283   Sontag   Eliminating the prsc_pkg and res libraries
# 09/15/06   56506   MSwam    Make sure catalog is after oapi
# 09/28/06   52073   Sontag   Port GUI's to OSX
# 12/20/06   56084   MSwam    Move arg,osfile up (no more OAPI dependence) 
#===========================================================================
# Delete implicit rules
.SUFFIXES:

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

MAKE+= -I $(TOPDIR)/src --no-print-directory --no-builtin-rules

# Include the individual application makefiles
# The OPUS corba files should be built first
#
target_files := $(wildcard *.make)
targets := $(basename $(target_files))

# On some OS's, the order of creation is important; some libs require others
# Note that jmsg has been removed (for now)

order := doesntmatter
ifeq ($(shell uname),AIX)
   order := important
endif
ifeq ($(shell uname),Darwin)
   order := important
endif
ifeq ($(order),important)
	#
	# First take out the ones which need to be ordered
	targets := $(filter-out err_pkg str osfile osys time_utils, $(targets))
	targets := $(filter-out osys_proc kw_pkg kr_rules, $(targets))
	targets := $(filter-out des stcrypt file otools util, $(targets))
	targets := $(filter-out jmsg joapi oapi opus_jvm ores_pkg, $(targets))
	targets := $(filter-out arg cdb fio kw_fits osys2 catalog, $(targets))
	#
	# Now put them back in the right order
	targets := des stcrypt time_utils arg osfile $(targets) 
	targets := str osys_proc osys err_pkg $(targets) 
	targets := $(targets) joapi oapi otools file cdb fio util
	targets := $(targets) ores_pkg kw_pkg kr_rules kw_fits opus_jvm osys2 catalog
else
	# Otherwise, just make sure jmsg joapi and oapi are built last,
	# and that osys2 is skipped
	targets := $(filter-out osys2, $(targets))
	targets := $(filter-out jmsg joapi oapi, $(targets)) joapi oapi jmsg
endif

ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
	targets := CORBAExceptions CORBAGaugable CORBAOpusUser CORBAPingable
	targets := $(targets) CORBAopus_corba_bb joapi str oxml
endif

all : $(targets)

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

FORCE:

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

include $(TOPDIR)/src/Makeshare.include
