# (C) COPYRIGHT International Business Machines Corp. 1996
# All Rights Reserved
# Licensed Materials - Property of IBM
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.


# DISCLAIMER OF WARRANTIES.
# The following [enclosed] code is sample code created by IBM
# Corporation. This sample code is not part of any standard or IBM
# product and is provided to you solely for the purpose of assisting
# you in the development of your applications.  The code is provided
# "AS IS". IBM MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT
# NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE, REGARDING THE FUNCTION OR PERFORMANCE OF
# THIS CODE.  THIS CODE MAY CONTAIN ERRORS.  IBM shall not be liable
# for any damages arising out of your use of the sample code, even if
# it has been advised of the possibility of such damages.
#
# DISTRIBUTION.
# This sample code can be freely distributed, copied, altered, and
# incorporated into other software, provided that it bears the above
# Copyright notice and DISCLAIMER intact.

#  Makefile for IBM SOM Server "Checkers" sample (C for AIX Compiler)

#----------------------------------------------------------------
# General settings
#----------------------------------------------------------------

#----------------------------------------------------------------
# Change the following line if SOM30 isn't installed in default location
#----------------------------------------------------------------
SOMBASE=/usr/lpp/som

INCLUDEPATH  = -I. -I$(SOMBASE)/include -I/usr/include
LIBDIRPATH   = -L . -L /usr/lib -L $(SOMBASE)/lib
CHECKERSLIBLIST = -lCheckers -lsomtk -lc_r
INITOPT      = -n SOMInitModule
LIB          = /usr/lpp/xlC/lib
OBJ          = o
C            = .c
EXP          = exp
MAKEFILE     = makefile
SYS          = AIX
CC           = xlc_r
SC           = sc
RM           = rm
CFLAGS       = $(DLL_CFLAGS) -c
SCFLAGS      = -maddstar
TARGETS      = $(DLL_TARGET).$(DLL_EXT)
CLEANFILES   = $(DLL_TARGET) $(TARGETS) $(DLL_OBJS) lib$(DLL_TARGET).$(DLL_ARCEXT) $(DLL_INITMOD).c $(DLL_TARGET).$(EXP) $(DLL_TARGET).h

#----------------------------------------------------------------
# EXE build settings
#----------------------------------------------------------------
EXE_CFLAGS   = -g $(INCLUDEPATH)

#----------------------------------------------------------------
# DLL build settings
#----------------------------------------------------------------
DLL_INITMOD  = Checkersinit
DLL_CFLAGS   = -g $(INCLUDEPATH)
DLL_OBJS     =  Checkers.o Checkersinit.o
DLL_TARGET   = Checkers
DLL_EXT      = dll
DLL_ARCEXT   = a
DLL_IDLS     = Checkers.idl

all: $(TARGETS) somdimpl somir

Checkers.dll: $(DLL_OBJS) $(DLL_TARGET).$(EXP)
	ld -o Checkers.dll -e SOMInitModule $(DLL_OBJS) \
	-bE:Checkers.exp -bM:SRE -lc \
	-L . $(LIBDIRPATH) -T512 -H512 -lsomtk
	$(AR) ruv libCheckers.a Checkers.$(EXP)
	cp Checkers.dll Checkers

#----------------------------------------------------------------
# DLL exports file
#----------------------------------------------------------------
$(DLL_TARGET).$(EXP):
	$(SC) -s$(EXP) -mdll=$(DLL_TARGET) $(DLL_IDLS)

#----------------------------------------------------------------
# DLL SOMInitModule function
#----------------------------------------------------------------
$(DLL_INITMOD).$(OBJ): $(DLL_INITMOD).c

$(DLL_INITMOD).c: $(DLL_IDLS)
	$(SC) -simod -mdll=$(DLL_TARGET) -mimod=$@ $(DLL_IDLS)

#----------------------------------------------------------------
# Clean up files that can be re-built
#----------------------------------------------------------------
clean: cleanup cleanimpl cleanir

cleanup:
	-rm $(CLEANFILES) >nul 2>&1

#----------------------------------------------------------------
# Cleanup the DSOM Implementation Repository.
#----------------------------------------------------------------
cleanimpl:
	-regimpl -D -i checkersServer
	-rm somdimpl

#----------------------------------------------------------------
# Cleanup the DSOM Implementation Repository.
#----------------------------------------------------------------
cleanir:
	-rm Checkers.ir

#----------------------------------------------------------------
# Build the DSOM Implementation Repository.
#----------------------------------------------------------------
somdimpl:
	-regimpl -A -i checkersServer
	-regimpl -a -i checkersServer -c COM::ibm::samples::Checkers
	-regimpl -L -i checkersServer
	-regimpl -l -i checkersServer
	@echo "" > somdimpl

#----------------------------------------------------------------
# Build the Interface Repository.
#----------------------------------------------------------------
somir:
	-sc -u -sir Checkers.idl

#----------------------------------------------------------------
# Suffix rules for building source files
#----------------------------------------------------------------
.SUFFIXES: .$(OBJ) .c .xh .ih .h .idl

.c.$(OBJ):
	$(CC) $(CFLAGS) $<

#----------------------------------------------------------------
# Don't have sc generate the Checkers.ih file.
# Reason:     The generated file causes a syntax error from the C compiler.
# Workaround: The corrected Checker.ih file is supplied with the sample.
# Details:    The get_board method for the attribute board trys to return
#             a board (line 290) but this needs to be casted to a 
#              "COM_ibm_samples_Checkers_Square*" (that's the work around).
# Solution:   Fix the sc compiler :-)
#             (Late discovery, didn't make it in this release)
#----------------------------------------------------------------
#.idl.ih:
#	$(SC) $(SCFLAGS) -sih $<

.idl.h:
	$(SC) $(SCFLAGS) -sh $<

.idl.c:
	$(SC) $(SCFLAGS) -sc $<

Checkers.ih: Checkers.idl

Checkers.h: Checkers.idl

Checkers.c: Checkers.idl

Checkers.$(OBJ): Checkers.c Checkers.ih Checkers.h

