# make -f Makefile-64-linux rebuild
#-------------------------------------------------------------------------
# Makefile-64-linux: makefile to build libBSF4ooRexx850.so-64-amd64
#
# ooRexx 5.x, 2005-06-07, 2009-09-08, 2017-01-08, 2022-09-21
#
# make -f Makefile-64-linux [ all | clean | clean_dll | rebuild ]
#-------------------------------------------------------------------------

#       20220921, rgf: use JAVA_HOME, rename to *BSF4ooRexx850*

# ------------------------ Apache Version 2.0 license -------------------------
#    Copyright (C) 2001-2022 Rony G. Flatscher
#
#    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/java/j2sdk1.4.2_08
# JDK_BASE = /home/rony/dev/jdk1.6.0_06
# JDK_BASE = /usr/lib/jvm/java-6-sun
# JDK_BASE = /usr/lib/jvm/java-6-openjdk-amd64

# 2015-07-27
# JDK_BASE = /usr/lib/jvm/java-6-oracle

# 2016-10-15, rgf
# JDK_BASE = /usr/lib/jvm/java-6-openjdk
# rgf, 2018-09-22: now uses JAVA_HOME environment variable
JDK_BASE = $(JAVA_HOME)

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

INC_PATH_ORX = -I/opt/ooRexx/include $(INC_PATH)

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


# --------------------------------------------------------
# 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
#
# cc = gcc -fPIC
cc = gcc
link = gcc

BITNESS         = 64
ARCH            = amd64

#
# CFLAGS		= -c -O3 -D__cplusplus -DUNIX -m64 -DBSF4REXX_64_BIT
# CFLAGS		= -fPIC -c -O3 -D__cplusplus -DUNIX -m$(BITNESS) -DBSF4REXX_$(BITNESS)_BIT
# rgf, 2018-09-22, "-Og" cf. <https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html>
CFLAGS		= -fPIC -c -g -Og -D__cplusplus -DUNIX -m$(BITNESS) -DBSF4REXX_$(BITNESS)_BIT
# CFLAGS		= -fPIC -c -g -D__cplusplus -DUNIX -m$(BITNESS) -DBSF4REXX_$(BITNESS)_BIT


CFLAGS_ORX      = -DUSE_OREXX

LINK_FLAGS      = -shared -rdynamic -lpthread -lc  -lm

# rgf, 2017-01-25: "-lrexxutil" not needed
# LINK_ORX_FLAGS  = -lrexx -lrexxapi -lrexxutil
LINK_ORX_FLAGS  = -lrexx -lrexxapi

BSF_SONAME      = libBSF4ooRexx850.so
BSF_OBJ_ORX     = $(BLD_PATH)/BSF4ooRexx850-$(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) -Wl,-soname,$(BSF_SONAME) -o $@ $(BSF_OBJ_ORX) $(LIB_PATH) $(LINK_FLAGS) $(LINK_ORX_FLAGS)

	$(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

