# @(#)makefile_nt.udf	1.26 Copyright 2003-2008 ANSYS Inc.
#
#	All Rights Reserved
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
# 
# purpose:
#    This file is the makefile for NT UDF builds.
#
# usage:
#    Change file name 'makefile_nt.udf' to 'makefile'.
#    Place the makefile file in the target dir.
#    Place the helper file 'user_nt.udf' in same directory.
#    Edit user_nt.udf file.
#    Execute an 'nmake'  (no arguments needed).
#
# notes:
#    The user should not need to change this file.
#    The following macros are expected to be in the user_nt.udf file:
#      SOURCES, VERSION and COMMUNICATOR.
#    The macro FLUENT_LIB is automatically defined here based on VERSION
#      and COMMUNICATOR.
#    Only this makefile and the helper file 'user_nt.udf' needs to be 
#      the target dir, all other files are automatically generated, 
#      and removed in an 'nmake clean'.
#    The source file is expected in ..\..\src directory.
#    Make sure the VC compiler is set up for command line mode, use
#      the file Vcvars32.bat from Visual Studio to assist this. 
#    This makefile uses the public domain program 'sed', make sure
#      sed is in your executable path.
#    The '^' char in the SRC literal is a quote for the '\' char,
#      otherwise interpretted as a line continuation char.
#    Use the 'nmake clean' command to restart builds.
#	makefile_master.nt 2004/07/20
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 
#
#	makefile_slave.nt 2004/07/20
#	Modified for compilation of ADDONs
#
#	Passed in arguments from makefile_master.nt:
#	LIB_RELEASE
#	RELEASE
#	VERSION
#	COMMUNICATOR
#	MAKEFILE_NAME
#	FLUENT_INC
#	INTEL_C
#	DEBUG
#	SRC
#

#
# Sundial IDA Paths and Libs
#
IDA_PATH = "..\..\sundials\ida-2.7.0"
IDA_INCLUDE_PATH = $(IDA_PATH)\include
IDA_LIBS_PATH = $(IDA_PATH)\lib
IDA_LIBS = sundials_ida.lib sundials_nvecserial.lib
#

# Source path
!IF !DEFINED(SRC)
SRC = ..\..\src\
!ENDIF

# Source files - always defined here!!!
# The following files are for GM Battery Module
SOURCES = $(SRC)cae_user.c
# Pre-compiled objects to be linked
PRECOMPILED_OBJECTS = cae_batt.obj cae_mem.obj cae_efield.obj cae_echem.obj \
	  ecm_p2d.obj spc_funcs.obj

# If this makefile is not called from makefile_client.nt, one needs to
# define all the above variables as follows:
# The Fluent version
!IF !DEFINED(RELEASE)
RELEASE = 16.0
LIB_VER = 16.0.0
LIB_RELEASE = $(LIB_VER:.=)
!ENDIF
# Makefile and it's path
!IF !DEFINED(MAKEFILE_NAME)
MAKEFILE_NAME = $(SRC)makefile_slave_client.nt
!INCLUDE user_nt.udf
# communicator which is supposed to be define in user_nt.udf
!IF DEFINED(PARALLEL_NODE)
COMMUNICATOR = $(PARALLEL_NODE)
!ENDIF
!ENDIF
# Compiler to use
!IF !DEFINED(INTEL_C)
INTEL_C = 0
!ENDIF
# If generate the debug version
!IF !DEFINED(DEBUG)
DEBUG = 0
!ENDIF

!IF ("$(PROCESSOR_ARCHITECTURE)" == "x86")
FLUENT_ARCH = ntx86
!ENDIF

!IF ("$(PROCESSOR_ARCHITECTURE)" == "AMD64")
FLUENT_ARCH = win64
EXTRA_CFLAGS = $(EXTRA_CFLAGS) /D_CRT_SECURE_NO_DEPRECATE
!ENDIF

# set FLUENT_LIB based on VERSION macro

!IF (("$(VERSION)" == "3d") || \
     ("$(VERSION)" == "3ddp"))
FLUENT_LIB = fl$(LIB_RELEASE).lib
!ENDIF

!IF (("$(VERSION)" == "3d_host") || \
     ("$(VERSION)" == "3ddp_host"))
COMM = net
FLUENT_LIB = mport.lib fl$(LIB_RELEASE).lib
!ENDIF

TARGET = libudf.dll


!IF (("$(VERSION)" == "3d_node") || \
     ("$(VERSION)" == "3ddp_node"))
!IF (("$(PARALLEL_NODE)" != "none") && ("$(PARALLEL_NODE)" != "net"))
PARALLEL_NODE = mpi
COMM = mpi
!ENDIF
FLUENT_LIB = mport.lib fl_$(COMMUNICATOR)$(LIB_RELEASE).lib
TARGET = libudf_$(COMMUNICATOR).dll
!ENDIF

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 

!IF ("$(INTEL_C)" == "1")
CC = icl /nologo /W3
!ELSE
CC = cl /nologo /W3
!ENDIF

LD = link /nologo

!IF ("$(DEBUG)" == "1")
CDBG_FLAG = /MTd /RTC1 /Zi /Od
LDBG_FLAG = /debug
!ELSE
CDBG_FLAG = /MT /O2 /GA /Gs
LDBG_FLAG = 
!ENDIF

# compile flags 
#  /c for compile only,  /Za for ansi c and __STDC__ is set
CFLAGS = /c /Za /DUDF_EXPORTING $(CDBG_FLAG) $(EXTRA_CFLAGS)

UDFDATA = udf_names.c

# generate object names from source names
SOURCES2 = $(SOURCES:..\..\src\=)
SRC_OBJECT = $(SOURCES2:.c=.obj)
UDF_OBJECT = $(UDFDATA:.c=.obj) 

OBJECTS = $(UDF_OBJECT) $(SRC_OBJECT)

INCLUDES= -I"$(FLUENT_INC)"\fluent$(RELEASE)\$(FLUENT_ARCH)\$(VERSION) \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\main \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\addon-wrapper \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\io \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\species \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\pbns \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\numerics \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\sphysics \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\storage \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\mphase \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\bc \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\models \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\material \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\amg \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\util \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\mesh \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\udf \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\ht \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\dx \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\turbulence \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\parallel \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\etc \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\ue \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\dpm \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\src\dbns \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\cortex\src \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\client\src \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\tgrid\src \
          -I"$(FLUENT_INC)"\fluent$(RELEASE)\multiport\src \
	  -I"$(IDA_INCLUDE_PATH)"

LIBS = /Libpath:"$(FLUENT_INC)"\fluent$(RELEASE)\$(FLUENT_ARCH)\$(VERSION) /Libpath:"$(IDA_LIBS_PATH)"\$(FLUENT_ARCH) /Libpath:"$(FLUENT_INC)"\fluent$(RELEASE)\multiport\$(FLUENT_ARCH)\$(COMM)\shared

all::   starttime $(TARGET) endtime

$(UDF_OBJECT):: $(UDFDATA)
	$(CC) $(CFLAGS) $(INCLUDES)  $**
	
$(SRC_OBJECT):: $(SOURCES)
	$(CC) $(CFLAGS) $(INCLUDES)  $**
	
$(TARGET):: $(MAKEFILE_NAME) $(UDF_OBJECT) $(SRC_OBJECT)
	@echo # Linking $@ because of $?
	$(LD) $(LIBS) /dll $(LDBG_FLAG)  /out:$(TARGET) \
	      $(OBJECTS) $(PRECOMPILED_OBJECTS) $(IDA_LIBS) $(FLUENT_LIB)
	
$(UDFDATA):: $(MAKEFILE_NAME) $(SRC_OBJECT)
	@echo # Generating $@ because of $?
	@echo /* This file generated automatically. */ > $@
	@echo /*          Do not modify.            */ >> $@
	@echo #include "udf.h" >> $@
	@echo #include "prop.h" >> $@
	@echo #include "dpm.h" >> $@
		
	@sed -n "s/^\(DEFINE_[_A-Z]*(.*)\)/extern \1;/p" $(SOURCES) >> $@
	
	@echo __declspec(dllexport) UDF_Data udf_data[] = { >> $@
	
	@sed -n "s/^DEFINE_\([_A-Z]*\)( *\([_a-zA-Z0-9]*\).*)/\{\"\2\", (void (*)())\2, UDF_TYPE_\1\},/p" $(SOURCES) >> $@
	
	@echo }; >> $@
	
	@echo __declspec(dllexport) int n_udf_data = sizeof(udf_data)/sizeof(UDF_Data); >> $@
	@echo #include "version.h" >> $@
	@echo __declspec(dllexport) void UDF_Inquire_Release(int *major, int *minor, int *revision) >> $@
	@echo { >> $@
	@echo   *major = RampantReleaseMajor; >> $@
	@echo   *minor = RampantReleaseMinor; >> $@
	@echo   *revision = RampantReleaseRevision; >> $@
	@echo } >> $@
	

clean::
	@del  *.dll $(OBJECTS) *.ilk *.exp *.lib *.pdb *.c

starttime::
        @echo --------------------------------------------------------
##        @echo Start time
##        @date /t
        @echo --------------------------------------------------------
endtime::
        @echo --------------------------------------------------------
##        @echo End time
##        @date /t
        @echo --------------------------------------------------------
