# debug, e.g.:    nmake /f Makefile-64-windows clean && nmake /f Makefile-64-windows
# release, e.g.:  nmake /f Makefile-64-windows clean && nmake /f Makefile-64-windows RELEASE=1
# 64-bit version, rgf, 2009-09-07

#/*----------------------------------------------------------------------------*/
#/*                                                                            */
#/* Copyright (c) 2008-2017 Rexx Language Association. All rights reserved.    */
#/*                                                                            */
#/* This program and the accompanying materials are made available under       */
#/* the terms of the Common Public License v1.0 which accompanies this         */
#/* distribution. A copy is also available at the following address:           */
#/* http://www.oorexx.org/license.html                                         */
#/*                                                                            */
#/* Redistribution and use in source and binary forms, with or                 */
#/* without modification, are permitted provided that the following            */
#/* conditions are met:                                                        */
#/*                                                                            */
#/* Redistributions of source code must retain the above copyright             */
#/* notice, this list of conditions and the following disclaimer.              */
#/* Redistributions in binary form must reproduce the above copyright          */
#/* notice, this list of conditions and the following disclaimer in            */
#/* the documentation and/or other materials provided with the distribution.   */
#/*                                                                            */
#/* Neither the name of Rexx Language Association nor the names                */
#/* of its contributors may be used to endorse or promote products             */
#/* derived from this software without specific prior written permission.      */
#/*                                                                            */
#/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS        */
#/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT          */
#/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS          */
#/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   */
#/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,      */
#/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED   */
#/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,        */
#/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY     */
#/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING    */
#/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS         */
#/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.               */
#/*                                                                            */
#/*----------------------------------------------------------------------------*/


# This is a Visual C++, nMake compatible make file for the myData example.
#
#
# The compiler needs to be able to find the ooRexx native API headers and
# libraries. If REXX_HOME is set on the system, the correct directory will be
# automatically added to the LIB and INCLUDE environment variables by this make
# file.
#
# Otherwise, either uncomment the next line and define the correct REXX_HOME, or
# be sure the LIB and INCLUDE environment variables allow the compiler to find
# the ooRexx native API headers and libraries.
#
# On a build system for ooRexx, you can set REXX_HOME to point to Win32Dbg or
# Win32Rel, as appropriate, in your build directory.  For this to work, you
# will have to have built the interpreter.

#REXX_HOME = C:\work.ooRexx\wc\main\Win32Dbg   # For example
REXX_HOME = F:\work\svn\bsf4oorexx\trunk\bsf4oorexx.dev\source_cc\rexxapi.win\win64

# Define RELEASE on the command line, or here, to build a non-debug version.  By
# default debug versions are built.  I.e. nMake RELEASE=1
# RELEASE = 1

# rgf --->
# need access to "org_rexxla_bsf_engines_rexx_RexxAndJava.h", created from "RexxAndJava" with "javah"
# also use JDK include path for "win32"
INC_PATH	=  .;$(JAVA_HOME)\include;$(JAVA_HOME)\include\win32
INCLUDE = $(INCLUDE);$(INC_PATH)
OP_SYS          = -DWINDOWS

# --------------------------------------------------------
# delete command to use
del_cmd  = del

# copy command to use
copy_cmd = copy


# -----------------------  Path Definitions  ----------------------------
# build path to use
BLD_PATH = tmp

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

BSF_SRC	        = BSF4ooRexx.cc
BSF_OBJ_ORX     = $(BLD_PATH)\BSF4ooRexx-64-amd64.obj
BSF_ORX_TARGET  = $(BLD_PATH)\BSF4ooRexx.dll-64-amd64
BSF4REXX	= $(BLD_PATH)\BSF4ooRexx.dll


# <--- rgf


# What we are going to build
# old-all: BSF4ooRexx-64.dll

!IF DEFINED(REXX_HOME)
INCLUDE = $(INCLUDE);$(REXX_HOME)\api
LIB = $(LIB);$(REXX_HOME)\api
!ENDIF

# fallback: the directory the 64-bit ooRexx API files are located locally (e.g. if REXX_HOME points to 32-bit ooRexx ooRexx or is not available at all)
REXX_API_DIR = .\rexxapi.win\64
INCLUDE = $(INCLUDE);$(REXX_API_DIR)
LIB = $(LIB);$(REXX_API_DIR)
REXX_LIBS = rexx.lib rexxapi.lib

WARNINGFLAGS = /W3 /Wp64 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE

DEF_FILE = /def:BSF4ooRexx-64.def

!IF DEFINED(RELEASE)
# Set the compile and link flags for a release build
OOREXX_CFLAGS = /nologo /EHsc /O2 /Gr /Gs /FAcs /MT $(WARNINGFLAGS) -DWINDOWS -DBSF4REXX_64_BIT /c /Fo$(@B).obj
EXE_LFLAGS = /nologo /SUBSYSTEM:Console $(REXX_LIBS) user32.lib comdlg32.lib gdi32.lib kernel32.lib
DLL_LFLAGS = /nologo /SUBSYSTEM:Windows $(REXX_LIBS) $(DEF_FILE) /DLL
!ELSE # release not defined
# Set the compile and link flags for a debug build
OOREXX_CFLAGS =  /nologo /EHsc /Zi /Od /Gr /MTd $(WARNINGFLAGS) -DWINDOWS -DBSF4REXX_64_BIT /c
EXE_LFLAGS = /nologo /DEBUG -debugtype:cv /SUBSYSTEM:Console $(REXX_LIBS) user32.lib comdlg32.lib gdi32.lib kernel32.lib
DLL_LFLAGS = /nologo /DEBUG -debugtype:cv /SUBSYSTEM:Windows $(REXX_LIBS) $(DEF_FILE) /DLL
#rgf-with-map DLL_LFLAGS = /nologo /DEBUG -debugtype:cv /SUBSYSTEM:Windows $(REXX_LIBS) $(DEF_FILE) /DLL  /mapinfo:exports
!ENDIF


# ------------- what we are going to build
all: $(BSF4REXX)

# -------------
$(BSF4REXX) : $(BSF_OBJ_ORX)
    @echo "--- linking step, target:" $(BSF4REXX) "dependent on:" $(BSF_OBJ_ORX) "---"
#    link $(DLL_LFLAGS) $(@B).obj -out:$(@B).dll
# rgf, 20170108: "bufferoverflowu.lib" necessary for 64-bit!
    link $(DLL_LFLAGS) $(BSF_OBJ_ORX) bufferoverflowu.lib -out:$(BSF_ORX_TARGET)
    @echo "finished linking."
    @echo " "

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

# rgf's developer test installation on Windows as of 2017-01-08: just remove the following statement
#    $(copy_cmd)  $(BSF4REXX)  ..\..\bsf4oorexx\BSF4ooRexx.dll
 @echo "done."


# ----------- BSF4ooRexx-64-amd64.obj
# $(BSF_OBJ_ORX) : $(BSF_SRC)
$(BSF_OBJ_ORX) : $(BSF_SRC)
    @echo "--- compiling step, target:" $(BSF_OBJ_ORX) "dependent on:" $(BSF_SRC) "---"
#    @echo "--- INCLUDE:" $(INCLUDE)
#    @echo "--- LIB:" $(LIB)
#  cl $(OOREXX_CFLAGS) /Fo$(@B).obj BSF4ooRexx.cc
    cl $(OOREXX_CFLAGS) /Fo$(BSF_OBJ_ORX)  $(BSF_SRC)
    @echo "finished compiling."
    @echo " "

mostlyclean:
	$(del_cmd)  $(BLD_PATH)\*.obj $(BLD_PATH)\*.ilk $(BLD_PATH)\*.lib $(BLD_PATH)\*.exp  $(BLD_PATH)\*.cod $(BLD_PATH)\*.res $(BLD_PATH)\*.map 1>nul 2>&1

clean:
        attrib -h $(BLD_PATH)\* 1>nul 2>&1
	$(del_cmd) $(BLD_PATH)\*.dll $(BLD_PATH)\*.obj $(BLD_PATH)\*.ilk $(BLD_PATH)\*.pdb $(BLD_PATH)\*.lib $(BLD_PATH)\*.exp $(BLD_PATH)\*.suo $(BLD_PATH)\*.cod $(BLD_PATH)\*.res $(BLD_PATH)\*.sln $(BLD_PATH)\*.map 1>nul 2>&1

