#	$Id: //depot/idl/IDL_71/idldir/external/rpc/Makefile#1 $
#
#
#  Copyright (c) 1995-2009, ITT Visual Information Solutions. All
#  rights reserved. Reproduction by any means whatsoever is prohibited
#  without express written permission.
#
#
# makefile for new rpc routines.
#
# Purpose:
# 	This makefile is used to build the routines that make up
#	the IDL rpc system.
#
# Edits:
# 	The IDL_DIR macro might need to be edited if the location
#	of IDL is not the standard location on your system.

IDL_DIR = /usr/local/itt/idl

# Define macros used in the makefile.

SERVER_OBJS = rpc_srvr.o rpc_tout.o
CLIENT_OBJ  = rpc_clnt.o 


# The following macros are defined when this file recurses and should 
# not be edited since they are overridden at run time.

LD_SYS_PRE 	=
LD_SYS_POST 	=   
FLAGS 		= 
C_FLAGS		= -c $(FLAGS) $(ARCH_FLAGS)
LD 		= ld
CC		= cc
SHELL		= /bin/sh

# Declare a flag when a different arch is being used
ARCH_FLAGS      = 

# The following macro is used to define sub-directory of the IDL_DIR/bin
# directory for the system the file run on.

BIN_DIR 	= 

# Some systems (sun os) use flags to specify dynamic libs and static ones
# during link time.

BDYNAMIC	=
BSTATIC		=
SO_VERSION 	= 
SHL_EXTENSION	=so
SHL_LD_FLAGS	=


TEST_POST	=

LD_LIBRARY_PATH = .

# build the loader flags that are required to build the idlrpc executable.

LD_FLAGS = $(LD_SYS_PRE) $(ARCH_FLAGS) -L$(IDL_DIR)/bin/$(BIN_DIR) -lidl $(LD_SYS_POST)

# The following is the default entry point. This section will determine 
# what system we are on and call make again with the correct flags set.

all : 
	@echo "OS type detected: "`uname`
	@case `uname` in \
	   "Darwin" ) if [ `uname -p` = "i386" ]; then make rpclib \
			  "LD=cc" \
		          "SHL_CFLAGS= -fPIC" \
			  "SHL_LD_FLAGS=-dynamiclib -multiply_defined suppress" \
			  "FLAGS=-no-cpp-precomp  -dynamic -fno-common" \
			  "LD_SYS_POST= -lMesaGLU6_2 -lMesaGL6_2 -lOSMesa6_2 -lfreetype2_3_6" \
			  "TEST_LD_FLAGS=-L." \
			  "BIN_DIR=bin.darwin.i386" \
			  "SHL_EXTENSION=dylib"; \
 			else make rpclib \
			  "LD=cc" \
		          "SHL_CFLAGS= -fPIC" \
			  "SHL_LD_FLAGS=-dynamiclib -multiply_defined suppress" \
			  "FLAGS=-no-cpp-precomp  -dynamic -fno-common" \
			  "LD_SYS_POST= -lMesaGLU6_2 -lMesaGL6_2 -lOSMesa6_2 -lfreetype2_3_6" \
			  "TEST_LD_FLAGS=-L." \
			  "BIN_DIR=bin.darwin.ppc" \
			  "SHL_EXTENSION=dylib"; \
			fi \
			 ;; \
	   "Linux" )  if [ `uname -i` = "x86_64" ]; then \
			      make rpclib \
			      "SHL_CFLAGS= -fPIC" \
			      "FLAGS= -m64" \
			      "LD_SYS_POST=-Wl,-rpath,. -lfreetype2_3_6" \
			      "SHL_LD_FLAGS= -shared" \
			      "TEST_LD_FLAGS=-L. -Wl,-rpath,." \
			      "BIN_DIR=bin.linux.x86_64"; \
			else \
			      make rpclib \
			      "SHL_CFLAGS= -fPIC" \
			      "FLAGS= -m32" \
			      "LD_SYS_POST=-Wl,-rpath,. -lfreetype2_3_6 -lgcc_s" \
			      "SHL_LD_FLAGS= -shared" \
			      "TEST_LD_FLAGS=-L. -Wl,-rpath,." \
			      "BIN_DIR=bin.linux.x86"; \
			fi \
			;; \
	   "SunOS") if [ -d /proc -a `mach` = i386 ]; then \
	           	make rpclib "FLAGS=-DSOLARIS -Xa -xlibmieee" \
	           	"ARCH_FLAGS= -m64" \
			"LD_SYS_POST= -lnsl -lm -lsunmath" \
			"SHL_CFLAGS=-KPIC" \
			"SHL_LD_FLAGS=-Bsymbolic -z nodefs -R . -G" \
			"TEST_LD_FLAGS= -z defs -i -R . -L." \
			"TEST_POST=-lnsl" \
			"BIN_DIR=bin.solaris2.x86_64"; \
	      	    elif [ -d /proc ]; then \
	           	make rpclib "FLAGS= -DSOLARIS" \
			"LD_SYS_POST= -lnsl" \
			"SHL_CFLAGS=-K pic" \
			"SHL_LD_FLAGS=-Bsymbolic -z nodefs -R . -G" \
			"TEST_LD_FLAGS= -z defs -i -R . -L." \
			"TEST_POST=-lnsl" \
			"BIN_DIR=bin.solaris2.sparc"; \
	   	    fi  \
		;; \
	   *) echo "This system is not supported" ;; \
       esac

# The following is the entry point that triggers the actual build 

rpclib: idlrpc  libidl_rpc.$(SHL_EXTENSION)$(SO_VERSION) idl_rpc_test \
		idl_rpc_obsolete.o example

idlrpc: $(SERVER_OBJS)
	rm -f idl_rpc_xdr.o
	$(CC) $(C_FLAGS) idl_rpc_xdr.c
	$(CC) $(ARCH_FLAGS) -o idlrpc $(SERVER_OBJS) idl_rpc_xdr.o $(LD_FLAGS)
	rm -f idl_rpc_xdr.o

# Build the client API shared library. 

libidl_rpc.$(SHL_EXTENSION)$(SO_VERSION): rpc_clnt.o
	$(CC) $(C_FLAGS) $(SHL_CFLAGS) -DIDL_RPC_CLIENT idl_rpc_xdr.c 
	$(LD) $(ARCH_FLAGS) $(SHL_LD_FLAGS) \
		-o libidl_rpc.$(SHL_EXTENSION)$(SO_VERSION) \
		rpc_clnt.o idl_rpc_xdr.o 

rpc_clnt.o:
	$(CC) $(C_FLAGS) $(SHL_CFLAGS) rpc_clnt.c

# Build the testing routine.

idl_rpc_test: idl_rpc_test.o
	$(CC) -o idl_rpc_test $(ARCH_FLAGS) $(TEST_LD_FLAGS) idl_rpc_test.o \
			-lidl_rpc $(TEST_POST)

example : example.o
	$(CC) -o example $(ARCH_FLAGS) $(TEST_LD_FLAGS) example.o \
			-lidl_rpc $(TEST_POST)

tidy: 
	rm -f $(CLIENT_OBJS) $(SERVER_OBJS)
clean : 
	rm -f libidl_rpc.* idlrpc example $(SERVER_OBJS) rpc_clnt.o example.o \
		idl_rpc_xdr.o idl_rpc_test idl_rpc_test.o idl_rpc_obsolete.o

.SUFFIXES: .c .o

.c.o :
	$(CC) $(C_FLAGS) $*.c

