# -*- Makefile -*- for callback

#### Start of system configuration section. ####

# Flags that can be set on the nmake command line:
#   MFLAGS={-ML|-MT|-MD} for defining the compilation model
#     MFLAGS=-ML (the default)  Single-threaded, statically linked - libc.lib
#     MFLAGS=-MT                Multi-threaded, statically linked  - libcmt.lib
#     MFLAGS=-MD                Multi-threaded, dynamically linked - msvcrt.lib
#   DEBUG=1   for compiling with debugging information
# Note that nmake command line flags are automatically passed to subdirectory
# Makefiles. Therefore we don't need to pass them explicitly to subdirectory
# Makefiles, but the subdirectory Makefiles need to have the same defaults.
# Building as a DLL not supported yet.
DLL=0
!if !defined(DEBUG)
DEBUG=0
!endif
!if !defined(MFLAGS)
!if !$(DLL)
MFLAGS=
!else
MFLAGS=-MD
!endif
!endif

!if $(DEBUG)
OPTIMFLAGS = -Od -Z7
!else
OPTIMFLAGS = -D_NDEBUG -O1
!endif

HOST = i386-pc-win32-msvc
CPU = i386

# Directories used by "make":
srcdir = .

# Directories used by "make install":
prefix = /usr/local
local_prefix = /usr/local
exec_prefix = $(prefix)
libdir = $(exec_prefix)/lib
includedir = $(prefix)/include
mandir = $(prefix)/man

# Programs used by "make":
CC = cl
CFLAGS = $(MFLAGS) $(OPTIMFLAGS)
CPP = cl -E
INCLUDES = -I. -I$(srcdir)
AR = lib
AR_FLAGS = /out:
MV = ren
LN = copy
RM = -del

# Programs used by "make install":
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

#### End of system configuration section. ####

SHELL = /bin/sh

OBJECTS = vacall_r/vacall.obj vacall_r/misc.obj vacall_r/structcpy.obj trampoline_r/trampoline.obj

all : $(OBJECTS) callback.h vacall_r.h trampoline_r.h callback.lib $(srcdir)/callback.3 $(srcdir)/callback.html

callback.h : $(srcdir)/callback.h.in
	-$(LN) $(srcdir)\callback.h.in callback.h

vacall_r.h : vacall_r/vacall_r.h
	$(LN) vacall_r\vacall_r.h vacall_r.h

vacall_r/vacall_r.h : vacall_r/vacall_r.h.msvc
	$(RM) vacall_r\vacall_r.h
	$(LN) vacall_r\vacall_r.h.msvc vacall_r\vacall_r.h

vacall_r/config.h : vacall_r/config.h.msvc
	$(RM) vacall_r\config.h
	$(LN) vacall_r\config.h.msvc vacall_r\config.h

vacall_r/vacall.obj : vacall_r/vacall-$(CPU).obj
	$(RM) vacall_r\vacall.obj
	$(LN) vacall_r\vacall-$(CPU).obj vacall_r\vacall.obj

vacall_r/vacall-i386.obj : $(srcdir)/vacall_r/vacall-i386-msvc.c vacall_r/vacall_r.h
	$(RM) vacall_r\vacall-i386.obj
	$(CC) -c $(srcdir)/vacall_r/vacall-i386-msvc.c /Fovacall_r/vacall-i386.obj

vacall_r/misc.obj : $(srcdir)/vacall_r/misc.c vacall_r/vacall_r.h vacall_r/config.h
	$(CC) $(CFLAGS) $(INCLUDES) -c $(srcdir)/vacall_r/misc.c /Fovacall_r/misc.obj

vacall_r/structcpy.obj : $(srcdir)/vacall_r/structcpy.c
	$(CC) $(CFLAGS) -c $(srcdir)/vacall_r/structcpy.c /Fovacall_r/structcpy.obj

trampoline_r.h : trampoline_r/trampoline_r.h
	$(LN) trampoline_r\trampoline_r.h trampoline_r.h

trampoline_r/trampoline_r.h : $(srcdir)/trampoline_r/trampoline_r.h.in
	-$(LN) $(srcdir)\trampoline_r\trampoline_r.h.in trampoline_r\trampoline_r.h

trampoline_r/config.h : $(srcdir)/trampoline_r/config.h.msvc
	-$(LN) $(srcdir)\trampoline_r\config.h.msvc trampoline_r\config.h

trampoline_r/trampoline.obj : $(srcdir)/trampoline_r/trampoline.c trampoline_r/trampoline_r.h trampoline_r/config.h
	$(CC) $(CFLAGS) $(INCLUDES) -c $(srcdir)/trampoline_r/trampoline.c /Fotrampoline_r/trampoline.obj

!if !$(DLL)
callback.lib : $(OBJECTS)
	$(RM) callback.lib
	$(AR) $(AR_FLAGS)callback.lib $(OBJECTS)
!else
# callback.dll and callback.lib are created together.
callback.lib : $(OBJECTS)
	$(CC) $(MFLAGS) -LD $(OBJECTS) -Fecallback.dll
!endif

test1.obj : $(srcdir)/trampoline_r/test1.c trampoline_r/trampoline_r.h
	$(CC) $(CFLAGS) $(INCLUDES) -c $(srcdir)/trampoline_r/test1.c

test1.exe : test1.obj callback.lib
	$(RM) test1.ilk
	$(CC) $(CFLAGS) test1.obj callback.lib /Fetest1.exe

test2.obj : $(srcdir)/trampoline_r/test2.c trampoline_r/trampoline_r.h
	$(CC) $(CFLAGS) $(INCLUDES) -c $(srcdir)/trampoline_r/test2.c

test2.exe : test2.obj callback.lib
	$(RM) test2.ilk
	$(CC) $(CFLAGS) test2.obj callback.lib /Fetest2.exe

tests.obj : $(srcdir)/tests.c callback.h vacall_r.h trampoline_r.h
	$(CC) $(CFLAGS) $(INCLUDES) -c $(srcdir)/tests.c

tests.s : $(srcdir)/tests.c callback.h vacall_r.h trampoline_r.h
	$(CC) $(CFLAGS) $(INCLUDES) -c $(srcdir)/tests.c /FAs /Fatests.s

tests.exe : tests.obj callback.lib
	$(CC) $(CFLAGS) tests.obj callback.lib /Fetests.exe

uniq-u.exe : $(srcdir)/uniq-u.c
	$(CC) $(CFLAGS) $(srcdir)/uniq-u.c -Feuniq-u.exe
	$(RM) uniq-u.obj

check1 : all test1.exe
	test1.exe

check2 : all test1.exe test2.exe
	test1.exe
	test2.exe

check : all test1.exe test2.exe tests.exe uniq-u.exe
	test1.exe
	test2.exe
	tests.exe > tests.out
	uniq-u < tests.out > tests.output.$(HOST)

mostlyclean : clean

clean : force
	$(RM) vacall_r\vacall.obj vacall_r\vacall-i386.obj vacall_r\misc.obj vacall_r\structcpy.obj trampoline_r\trampoline.obj callback.lib callback.exp callback.dll core
	$(RM) test1.obj test1.exe test2.obj test2.exe
	$(RM) tests.obj tests.s tests.exe uniq-u.exe tests.out

distclean : clean
	$(RM) config.status config.log config.cache Makefile vacall_r\vacall_r.h vacall_r\config.h trampoline_r\config.h trampoline_r\trampoline_r.h vacall_r.h trampoline_r.h tests.output.*

maintainer-clean : distclean

force :

