NULL=
BASEDIR=.
BINDIR=bin
OBJDIR=obj
KJSDIR=kjs
PCREDIR=pcre

ICUDIR=$(BASEDIR)\..\..\icu

#
# Define compiler flags
#
CC = cl.exe
CFLAGS = $(CFLAGS) /nologo
# 4996 - deprecated function, only needed for VS 2005 in which a lot
#  of C standard functions that cause security risks (strcat, strcpy,
#  printf etc.) were declared deprecated)
# 4138 - */ found outside of comment
# 4355 'this' : used in  base member initializer list
CFLAGS = $(CFLAGS) /wd4138 /wd4996 /wd4355
CFLAGS = $(CFLAGS) /D "HAVE_CONFIG_H"
CFLAGS = $(CFLAGS) /D "WIN32" /D "__STD_C"
CFLAGS = $(CFLAGS) /D "_MBCS" /D "_REENTRANT" /EHsc /W1
CFLAGS = $(CFLAGS) /I$(BASEDIR)\os-win32
CFLAGS = $(CFLAGS) /I$(BASEDIR)\pcre
CFLAGS = $(CFLAGS) /I$(KJSDIR)
CFLAGS = $(CFLAGS) /I$(ICUDIR)\include

# /Zm increases max memory used by the compiler. It's for VC6 and compiling chartables.c
#CFLAGS = $(CFLAGS) /Zm300

!if "$(DEBUG)"=="1"
CFLAGS = $(CFLAGS) /MDd /Od /Zi
!else
CFLAGS = $(CFLAGS) /D "NDEBUG" /MD /Zi
!endif

#
# Define linker flags
#
LD = link.exe
LDFLAGS = $(LDFLAGS) /nologo
LDFLAGS = $(LDFLAGS) /LIBPATH:$(BINDIR) /LIBPATH:$(ICUDIR)\lib
#LIBS = $(LIBS) icuin.lib icudt.lib icuio.lib icuuc.lib
TESTKJS_LIBS = $(LIBS) jscore.lib
LIBS = $(LIBS) icuuc.lib

!if "$(DEBUG)"=="1"
LDFLAGS = $(LDFLAGS) /DEBUG
!else
LDFLAGS = $(LDFLAGS) /OPT:NOWIN98 /DEBUG
!endif

#
# Archiver flags
#
AR       = lib.exe
ARFLAGS  = $(ARFLAGS) /nologo

PCRE_OBJS=\
    $(OBJDIR)\pcre.obj \
    $(NULL)

#
# jscore.dll
#
JSCORE_DLL_OBJS=\
    $(OBJDIR)\array_object.obj \
    $(OBJDIR)\bool_object.obj \
    $(OBJDIR)\collector.obj \
    $(OBJDIR)\date_object.obj \
    $(OBJDIR)\debugger.obj \
    $(OBJDIR)\dtoa.obj \
    $(OBJDIR)\error_object.obj \
    $(OBJDIR)\fast_malloc.obj \
    $(OBJDIR)\fpconst.obj \
    $(OBJDIR)\function.obj \
    $(OBJDIR)\function_object.obj \
    $(OBJDIR)\grammar.obj \
    $(OBJDIR)\identifier.obj \
    $(OBJDIR)\internal.obj \
    $(OBJDIR)\interpreter.obj \
    $(OBJDIR)\interpreter_map.obj \
    $(OBJDIR)\lexer.obj \
    $(OBJDIR)\list.obj \
    $(OBJDIR)\lookup.obj \
    $(OBJDIR)\math_object.obj \
    $(OBJDIR)\nodes.obj \
    $(OBJDIR)\nodes2string.obj \
    $(OBJDIR)\number_object.obj \
    $(OBJDIR)\object.obj \
    $(OBJDIR)\object_object.obj \
    $(OBJDIR)\operations.obj \
    $(OBJDIR)\property_map.obj \
    $(OBJDIR)\property_slot.obj \
    $(OBJDIR)\protected_values.obj \
    $(OBJDIR)\reference.obj \
    $(OBJDIR)\reference_list.obj \
    $(OBJDIR)\regexp.obj \
    $(OBJDIR)\regexp_object.obj \
    $(OBJDIR)\scope_chain.obj \
    $(OBJDIR)\string_object.obj \
    $(OBJDIR)\ustring.obj \
    $(OBJDIR)\value.obj \
    $(NULL)

JSCORE_DLL_NAME=jscore.dll
JSCORE_DLL_LIB_NAME=jscore.lib

TESTKJS_OBJS=\
    $(OBJDIR)\testkjs.obj \
    $(NULL)

TESTKJS_EXE_NAME=testkjs.exe
TESTKJS_PDB_NAME=testkjs.pdb

#all: $(BINDIR)\$(JSCORE_DLL_NAME)

all: $(BINDIR)\$(TESTKJS_EXE_NAME)

clean:
    if exist $(OBJDIR) rmdir /S /Q $(OBJDIR)
    if exist $(BINDIR) rmdir /S /Q $(BINDIR)

$(OBJDIR):
    if not exist $(OBJDIR) mkdir $(OBJDIR)

$(BINDIR):
    if not exist $(BINDIR) mkdir $(BINDIR)

#
# jscore DLL
#
$(BINDIR)\$(JSCORE_DLL_NAME) : $(BINDIR) $(PCRE_OBJS) $(JSCORE_DLL_OBJS) $(BASEDIR)\jscore.def
#       $(LD) $(LDFLAGS) $(LIBS) /DLL /DEF:$(BASEDIR)\jscore.def \
       $(LD) $(LDFLAGS) $(LIBS) /DLL \
               $(PCRE_OBJS) $(JSCORE_DLL_OBJS) \
               /IMPLIB:$(BINDIR)\$(JSCORE_DLL_LIB_NAME) \
               /OUT:$(BINDIR)\$(JSCORE_DLL_NAME)

$(BINDIR)\icuuc32.dll :
    copy $(ICUDIR)\bin\icuuc34.dll $(BINDIR)

$(BINDIR)\icudt32.dll :
    copy $(ICUDIR)\bin\icudt34.dll $(BINDIR)

$(BINDIR)\$(TESTKJS_EXE_NAME) : $(BINDIR) $(PCRE_OBJS) $(JSCORE_DLL_OBJS) $(TESTKJS_OBJS) \
        $(BINDIR)\icudt32.dll \
        $(BINDIR)\icuuc32.dll
    $(LD) $(LDFLAGS) $(LIBS) \
        $(PCRE_OBJS) $(JSCORE_DLL_OBJS) \
        $(TESTKJS_OBJS) \
        /PDB:$(BINDIR)\$(TESTKJS_PDB_NAME) \
        /OUT:$(BINDIR)\$(TESTKJS_EXE_NAME)

$(JSCORE_DLL_OBJS) : $(OBJDIR)

{$(BASEDIR)\kjs}.cpp{$(OBJDIR)}.obj::
       $(CC) $(CFLAGS) /Fo$(OBJDIR)\ /c $<

{$(BASEDIR)\pcre}.c{$(OBJDIR)}.obj::
       $(CC) $(CFLAGS) /Fo$(OBJDIR)\ /c /Tp $<
