###############################################################################
##    Makefile
##
##    This file is part of Dark Hook 2
##    Copyright (C) 2005-2009 Tom N Harris <telliamed@whoopdedo.org>
##
##    This program is free software; you can redistribute it and/or modify
##    it under the terms of the GNU General Public License as published by
##    the Free Software Foundation; either version 2 of the License, or
##    (at your option) any later version.
##
##    This program is distributed in the hope that it will be useful,
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##    GNU General Public License for more details.
##
##    You should have received a copy of the GNU General Public License
##    along with this program; if not, write to the Free Software
##    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
##
###############################################################################

.SUFFIXES:
.SUFFIXES: .o .c .cpp .rc

srcdir = .
LGDIR = ../lg

CC = g++
AR = ar
LD = g++
DLLTOOL = dlltool
RC = windres

DEFINES = -DWINVER=0x0400 -D_WIN32_WINNT=0x0400 -DWIN32_LEAN_AND_MEAN
INCLUDES = -I. -I$(LGDIR)
LIBS = -llg -lstdc++ -luuid
ARFLAGS = rc
LDFLAGS = -mno-cygwin -mwindows -mdll -Wl,--image-base=0x12200000 -L$(LGDIR)
CFLAGS = -W -Wall -mno-cygwin -masm=intel -O2
DLLFLAGS = --add-underscore

ALL = dh2.osl libdh2.a

DLLSRCS = dh2.cpp dh2dll.cpp dh2lib.cpp
DLLOBJS = exports.o dh2.o dh2dll.o dh2_res.o

.INTERMEDIATE: exports.o

LIBSRCS = dh2lib.cpp
LIBOBJS = dh2lib.o

%.o: %.c
	$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ -c $<

%.o: %.cpp
	$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ -c $<

all:	$(ALL)

clean:
	$(RM) $(ALL) $(DLLOBJS) $(LIBOBJS)

dh2_res.o: dh2.rc
	$(RC) $(DEFINES) -o $@ -i $<

exports.o: dh2dll.o
	$(DLLTOOL) $(DLLFLAGS) --output-exp $@ $^

dh2.osl: $(DLLOBJS)
	$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)

libdh2.a: $(LIBOBJS)
	$(AR) $(ARFLAGS) $@ $?


dh2.o: dh2.cpp dh2.h darkhook.h objprop.h

dh2dll.o: dh2dll.cpp dh2.h darkhook.h

dh2lib.o: dh2lib.cpp darkhook.h

