
CROSS_CC = ../../tools/cross-mingw/install/bin/mingw32-gcc
CC = gcc
CC := $(shell type $(CROSS_CC) >/dev/null 2>&1 && echo $(CROSS_CC) \
	|| echo $(CC))
CROSS_AR = ../../tools/cross-mingw/install/bin/mingw32-ar
AR = ar
AR := $(shell type $(CROSS_AR) >/dev/null 2>&1 && echo $(CROSS_AR) \
	|| echo $(AR))
CROSS_RANLIB = ../../tools/cross-mingw/install/bin/mingw32-ranlib
RANLIB = ranlib
RANLIB := $(shell type $(CROSS_RANLIB) >/dev/null 2>&1 && echo $(CROSS_RANLIB) \
	|| echo $(RANLIB))

DISTDIR = ../../dist

SRCROOT = ../../common/vhd-util
OBJDIR = obj

LIBVHDDIR = ../../common/libvhd

CPPFLAGS += -I$(SRCROOT) -I$(LIBVHDDIR)
CPPFLAGS += -g -Wall -Werror -O2

LDFLAGS += -g

all: vhd-util.exe

VPATH = $(OBJDIR)

vhd-util_SRCS  = vhd-util-check.c
vhd-util_SRCS += vhd-util-coalesce.c
vhd-util_SRCS += vhd-util-create.c
vhd-util_SRCS += vhd-util-fill.c
vhd-util_SRCS += vhd-util-modify.c
vhd-util_SRCS += vhd-util-query.c
vhd-util_SRCS += vhd-util-read.c
vhd-util_SRCS += vhd-util-repair.c
vhd-util_SRCS += vhd-util-resize.c
vhd-util_SRCS += vhd-util-revert.c
#vhd-util_SRCS += vhd-util-scan.c
vhd-util_SRCS += vhd-util-set-field.c
vhd-util_SRCS += vhd-util-snapshot.c
vhd-util_SRCS += vhd-util.c
vhd-util_OBJS  = $(patsubst %.c,%.o,$(vhd-util_SRCS))
vhd-util_OBJS := $(subst /,_,$(vhd-util_OBJS))

OBJS = $(vhd-util_OBJS)
$(OBJS): $(OBJDIR)/.exists

vhd-util.exe: $(vhd-util_OBJS)
	$(LINK.o) -o $@ $(patsubst %,$(OBJDIR)/%,$(vhd-util_OBJS)) \
	  -L$(LIBVHDDIR)/obj -lvhd -liconv -luuid

$(vhd-util_OBJS): %.o : $(SRCROOT)/%.c
	$(COMPILE.c) $< -o $(OBJDIR)/$@

clean:
	@rm -rf .deps obj

%/.exists:
	mkdir -p $(@D)/.hg
	touch $@
