# Makefile for Windows NT.  Assumes Microsoft compiler.
# modified 2007 August by Friedrich Dominicus:
#			- copied from NT_X64_STATIC_THREADS_MAKEFILES
#                       - checked agaist gc.mak (NT_THREADS_MAKEFILE)
#                       - added changes to integrate the tools
#                       - currently just with debug information
# problems can be sent to
#                     frido at q-software-solutions.de
#
# or the mailing list


MY_CPU=AMD64
CPU=$(MY_CPU)
!include <ntwin32.mak>

# Make sure that .cc is not viewed as a suffix.  It is for VC++2005, but # not earlier versions.  We can deal with either, but not inconsistency.
.SUFFIXES:
.SUFFIXES: .obj .cpp .c

# Atomic_ops installation directory.  For win32, the source directory
# should do, since we only need the headers.
# We assume this was manually unpacked, since I'm not sure there is
# a Windows standard command line tool to do this.
AO_SRC_DIR=libatomic_ops/src
AO_INCLUDE_DIR=$(AO_SRC_DIR)

OBJS= alloc.obj reclaim.obj allchblk.obj misc.obj mach_dep.obj os_dep.obj mark_rts.obj headers.obj mark.obj obj_map.obj blacklst.obj finalize.obj new_hblk.obj dbg_mlc.obj fnlz_mlc.obj malloc.obj stubborn.obj dyn_load.obj typd_mlc.obj ptr_chck.obj gc_cpp.obj mallocx.obj win32_threads.obj extra\msvc_dbg.obj thread_local_alloc.obj

all: gc64.dll gctest.exe cord\de.exe test_cpp.exe

.c.obj:
	$(cc) $(cdebug) $(cflags) $(cvarsmt) -Iinclude -I$(AO_INCLUDE_DIR) -DALL_INTERIOR_POINTERS -DGC_DLL -DGC_THREADS -D_CRT_SECURE_NO_DEPRECATE $*.c /Fo$*.obj /wd4701
# Disable "may not be initialized" warnings.  They're too approximate.
# Disable crt security warnings, since unfortunately they warn about all sorts # of safe uses of strncpy.  It would be nice to leave the rest enabled.

.cpp.obj:
	$(cc) $(cdebug) $(cflags) $(cvarsmt) -Iinclude -I$(AO_INCLUDE_DIR) -DALL_INTERIOR_POINTERS -DGC_DLL -DGC_THREADS -D_CRT_SECURE_NO_DEPRECATE $*.cpp /Fo$*.obj

$(OBJS) tests\test.obj: include\private\gc_priv.h include\private\gc_hdrs.h include\gc.h include\private\gcconfig.h include\private\gc_locks.h include\private\gc_pmark.h include\gc_mark.h include\gc_disclaim.h include\private\msvc_dbg.h


LINK64=link.exe
LINK64_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib \
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo \
/subsystem:windows /dll /incremental:no /pdb:"gc.pdb" /machine:X64 /out:"gc64.dll" \
/implib:"gc64_dll.lib"

gc64.dll : $(OBJS)
	$(LINK64)  $(ldebug) $(LINK64_FLAGS) $(OBJS)


gctest.exe: tests\test.obj gc64_dll.lib
#  This produces a "GUI" applications that opens no windows and writes to
# the log file "gctest.gc.log".
	$(link) $(ldebug) $(guiflags) -out:$*.exe tests\test.obj $(guilibs) gc64_dll.lib

cord\de_win.rbj: cord\de_win.res
	cvtres /MACHINE:$(MY_CPU) /OUT:cord\de_win.rbj cord\de_win.res

cord\tests\de.obj cord\tests\de_win.obj: include\cord.h include\cord_pos.h cord\tests\de_win.h cord\tests\de_cmds.h

cord\de_win.res: cord\tests\de_win.rc cord\tests\de_win.h cord\tests\de_cmds.h
	$(rc) $(rcvars) -r -fo cord\de_win.res cord\tests\de_win.rc

# Cord/de is a real win32 gui application.
cord\de.exe: cord\cordbscs.obj cord\cordxtra.obj cord\tests\de.obj cord\tests\de_win.obj cord\de_win.rbj gc64_dll.lib
	$(link) $(ldebug) $(guiflags) -stack:16384 -out:cord\de.exe cord\cordbscs.obj cord\cordxtra.obj cord\tests\de.obj cord\tests\de_win.obj cord\de_win.rbj gc64_dll.lib $(guilibs)

gc_cpp.obj: include\gc_cpp.h include\gc.h

gc_cpp.cpp: gc_cpp.cc
#	copy gc_cpp.cc gc_cpp.cpp

test_cpp.cpp: tests\test_cpp.cc
	copy tests\test_cpp.cc test_cpp.cpp

# This generates the C++ test executable.  The executable expects # a single numeric argument, which is the number of iterations.
# The output appears in the file "test_cpp.gc.log".
test_cpp.exe: test_cpp.obj include\gc_cpp.h include\gc.h gc64_dll.lib
	$(link) $(ldebug) $(guiflags) -stack:16384 -out:test_cpp.exe test_cpp.obj gc64_dll.lib $(guilibs)

AO_SCR_DIR:
	tar xvfz $(AO_SRC_DIR).tar.gz;

clean:
	del *.obj gc64_dll.lib gc64.dll
