###############################################################################
# Product:     OpenCTM
# File:        Makefile.msvc
# Description: Makefile for MS Visual Studio 2008 for Windows.
###############################################################################
# Copyright (c) 2009-2010 Marcus Geelnard
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
#     1. The origin of this software must not be misrepresented; you must not
#     claim that you wrote the original software. If you use this software
#     in a product, an acknowledgment in the product documentation would be
#     appreciated but is not required.
#
#     2. Altered source versions must be plainly marked as such, and must not
#     be misrepresented as being the original software.
#
#     3. This notice may not be removed or altered from any source
#     distribution.
###############################################################################

LZMADIR = liblzma
CC = cl
CFLAGS = /nologo /Ox /W3 /c /DOPENCTM_BUILD /I$(LZMADIR) /DLZMA_PREFIX_CTM /D_CRT_SECURE_NO_WARNINGS
CFLAGS_LZMA = /nologo /Ox /W3 /c /DLZMA_PREFIX_CTM
RM = del /Q
RC = rc

DYNAMICLIB = openctm.dll
LINKLIB = openctm.lib

OBJS = openctm.obj \
       stream.obj \
       compressRAW.obj \
       compressMG1.obj \
       compressMG2.obj

LZMA_OBJS = Alloc.obj \
            LzFind.obj \
            LzmaDec.obj \
            LzmaEnc.obj \
            LzmaLib.obj

SRCS = openctm.c \
       stream.c \
       compressRAW.c \
       compressMG1.c \
       compressMG2.c

LZMA_SRCS = $(LZMADIR)\Alloc.c \
            $(LZMADIR)\LzFind.c \
            $(LZMADIR)\LzmaDec.c \
            $(LZMADIR)\LzmaEnc.c \
            $(LZMADIR)\LzmaLib.c

all: $(DYNAMICLIB)

.PHONY: clean

clean:
	$(RM) $(DYNAMICLIB) $(LINKLIB) $(OBJS) $(LZMA_OBJS) openctm.res

$(DYNAMICLIB): $(OBJS) $(LZMA_OBJS) openctm-msvc.def openctm.res
	link /nologo /out:$@ /dll /implib:$(LINKLIB) /def:openctm-msvc.def $(OBJS) $(LZMA_OBJS) openctm.res

openctm.res: openctm.rc
	$(RC) openctm.rc

openctm.obj: openctm.c openctm.h internal.h
	$(CC) $(CFLAGS) openctm.c

stream.obj: stream.c openctm.h internal.h
	$(CC) $(CFLAGS) stream.c

compressRAW.obj: compressRAW.c openctm.h internal.h
	$(CC) $(CFLAGS) compressRAW.c

compressMG1.obj: compressMG1.c openctm.h internal.h
	$(CC) $(CFLAGS) compressMG1.c

compressMG2.obj: compressMG2.c openctm.h internal.h
	$(CC) $(CFLAGS) compressMG2.c

Alloc.obj: $(LZMADIR)\Alloc.c $(LZMADIR)\Alloc.h
	$(CC) $(CFLAGS_LZMA) $(LZMADIR)\Alloc.c

LzFind.obj: $(LZMADIR)\LzFind.c $(LZMADIR)\LzFind.h $(LZMADIR)\Types.h $(LZMADIR)\LzHash.h $(LZMADIR)\NameMangle.h
	$(CC) $(CFLAGS_LZMA) $(LZMADIR)\LzFind.c

LzmaDec.obj: $(LZMADIR)\LzmaDec.c $(LZMADIR)\LzmaDec.h $(LZMADIR)\Types.h $(LZMADIR)\NameMangle.h
	$(CC) $(CFLAGS_LZMA) $(LZMADIR)\LzmaDec.c

LzmaEnc.obj: $(LZMADIR)\LzmaEnc.c $(LZMADIR)\LzmaEnc.h $(LZMADIR)\Types.h $(LZMADIR)\LzFind.h $(LZMADIR)\NameMangle.h
	$(CC) $(CFLAGS_LZMA) $(LZMADIR)\LzmaEnc.c

LzmaLib.obj: $(LZMADIR)\LzmaLib.c $(LZMADIR)\LzmaEnc.h $(LZMADIR)\Types.h $(LZMADIR)\LzmaDec.h $(LZMADIR)\Alloc.h $(LZMADIR)\LzmaLib.h $(LZMADIR)\NameMangle.h
	$(CC) $(CFLAGS_LZMA) $(LZMADIR)\LzmaLib.c
