# make -f Makefile-64-aix rebuild
#-------------------------------------------------------------------------
# Makefile-64-aix: makefile to build libBSF4ooRexx.so-64-aix
#
# ooRexx 4.x, 2005-06-07, 2009-09-08, 2017-01-09
#
# make -f Makefile-64-linux [ all | orexx | clean | clean_dll | rebuild ]
#-------------------------------------------------------------------------

# ------------------------ Apache Version 2.0 license -------------------------
#    Copyright (C) 2001-2017 Rony G. Flatscher, 2013 Martin Pichler, Austria
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
# -----------------------------------------------------------------------------


# -----------------------  Path Definitions  ----------------------------

# build path to use
# BLD_PATH = ~/tmp
# BLD_PATH = .
BLD_PATH = ./tmp

# directory to copy generated lib to
TGT_LIB_DIR     = ./lib

#JDK_BASE = /usr/lib/jvm/java-6-openjdk-amd64

# 2013-07-30, Martin Pichler
JDK_BASE = /usr/java6_64

INC_PATH = -I. -I/usr/local/include -I$(JDK_BASE)/include -I$(JDK_BASE)/include/aix

INC_PATH_ORX = -I/opt/ooRexx/include

LIB_PATH = -L. -L/usr/local/lib -L/usr/lib -L/opt/ooRexx/lib/ooRexx


# --------------------------------------------------------
# delete command to use
del_cmd  = rm -f

# copy command to use
copy_cmd = cp

# source file to compile
BSF_SRC	= BSF4ooRexx.cc

#
# Compiler macros
#
# rgf, 20170126: move to CFLAGS like in the other Makefiles
# cc = gcc -c -fPIC
cc = gcc
link = gcc

BITNESS         = 64
ARCH            = aix

#
# CFLAGS_ori     = -c -ggdb -D__cplusplus
#CFLAGS		= -c -O3 -D__cplusplus -DUNIX -m64 -DBSF4REXX_64_BIT
# CFLAGS= -maix64 -DAIX61 -DUNIX -D_ALL_SOURCE -DFUNCPROTO=15 -O -DBSF4REXX_64_BIT -DOBJECT_MODE=64
CFLAGS= -c -fPIC -m$(ARCH)$(BITNESS) -DAIX61 -DUNIX -D_ALL_SOURCE -DFUNCPROTO=15 -O -DBSF4REXX_$(BITNESS)_BIT -DOBJECT_MODE=$(BITNESS)
CFLAGS_ORX      = -DUSE_OREXX

# link_lib_flags_lib_bsf4rexx_ori = -shared -rdynamic -lpthreads -lrexxapi -lc  -lm
LINK_FLAGS = -shared -lpthread -lc -lm
# rgf, 2017-01-26: "-lrexxutil" not needed
# LINK_ORX_FLAGS  = -lrexx -lrexxapi -lrexxutil
LINK_ORX_FLAGS  = -lrexx -lrexxapi


BSF_SONAME      = libBSF4ooRexx.so
BSF_OBJ_ORX     = $(BLD_PATH)/BSF4ooRexx-$(BITNESS)-$(ARCH).o
BSF_ORX_TARGET  = $(BLD_PATH)/$(BSF_SONAME)-$(BITNESS)-$(ARCH)
BSF4REXX	= $(BLD_PATH)/$(BSF_SONAME)


# *************************************************************************** #
# Rules									      #
# *************************************************************************** #
# .cc.o:
#	  $(cc) $(CFLAGS) -o$*.o $(INC_PATH) $(LIB_PATH) $*.cc

#---------------------------------------------------------- Generate library

orexx :		$(BSF_ORX_TARGET)
#---------------------------------------------------------- END section

# Object Rexx ----------------------------------------------
$(BSF_ORX_TARGET) : $(BSF_SRC)
	echo
	echo Building $@ ...
	echo

	$(cc) $(CFLAGS) $(CFLAGS_ORX) -o$(BSF_OBJ_ORX) $(INC_PATH) $(INC_PATH_ORX) $(LIB_PATH) $(BSF_SRC)

#	$(link) -maix64 -DAIX61 -DUNIX -Wl,-b64,-brtl -g -o $(BLD_PATH)/$@ $(BSF_OBJ_ORX) $(LIB_PATH) $(LINK_FLAGS) $(LINK_ORX_FLAGS) -lstdc++

	$(link) -m$(ARCH)$(BITNESS) -DAIX61 -DUNIX -Wl,-b$(BITNESS),-brtl,-soname,$(BSF_SONAME) -g -o $@ $(BSF_OBJ_ORX) \
                $(LIB_PATH) $(LINK_FLAGS) $(LINK_ORX_FLAGS) -lstdc++

	$(copy_cmd) $(BSF_ORX_TARGET) $(BSF4REXX)
	$(copy_cmd) $(BSF_ORX_TARGET) $(TGT_LIB_DIR)


#---------------------------------------------------------- END section
# -------------------------------------------------------------------
# builds all
rebuild: clean clean_dll orexx

#---------------------------------------------------------- END section
# just clean up the mess, just leave the dll
clean:
	- $(del_cmd) $(BLD_PATH)/*.o

#---------------------------------------------------------- END section
clean_dll:
	- $(del_cmd) $(BLD_PATH)/*.so*


# -------------------------------------------------------------------
# builds all
all: clean orexx

