TOPSRCDIR = @top_srcdir@
TOPOBJDIR = ..
SRCDIR    = @srcdir@
VPATH     = @srcdir@
MODULE    = wine

C_SRCS = \
	glibc.c \
	kthread.c \
	main.c \
	preloader.c \
	pthread.c

KTHREAD_OBJS = kthread.o main.o version.o
PTHREAD_OBJS = pthread.o main.o version.o

MAIN_BINARY    = @MAIN_BINARY@
EXTRA_BINARIES = @EXTRA_BINARIES@
WINE_BINARIES  = $(MAIN_BINARY) $(EXTRA_BINARIES)

PROGRAMS = \
	wine \
	wine-glibc \
	wine-kthread \
	wine-preloader \
	wine-pthread\

MANPAGES = wine.man

INSTALLDIRS = $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)/man$(prog_manext)

all: $(WINE_BINARIES) $(MODULE) $(MANPAGES)

@MAKE_RULES@

LIBPTHREAD  = @LIBPTHREAD@
LDEXECFLAGS = @LDEXECFLAGS@

wine-glibc: glibc.o Makefile.in
	$(CC) -o $@ glibc.o $(LIBWINE_LDFLAGS) $(LIBPORT) $(LIBPTHREAD) $(EXTRALIBS) $(LDFLAGS)

wine-preloader: preloader.o Makefile.in
	$(CC) -o $@ -static -nostartfiles -nodefaultlibs -Wl,-Ttext=0x7c000000 preloader.o $(LIBPORT) $(LDFLAGS)

wine-kthread: $(KTHREAD_OBJS) Makefile.in
	$(CC) -o $@ $(LDEXECFLAGS) $(KTHREAD_OBJS) $(LIBWINE_LDFLAGS) $(LIBPORT) $(EXTRALIBS) $(LDFLAGS)

wine-pthread: $(PTHREAD_OBJS) Makefile.in
	$(CC) -o $@ $(LDEXECFLAGS) $(PTHREAD_OBJS) $(LIBWINE_LDFLAGS) $(LIBPORT) $(LIBPTHREAD) $(EXTRALIBS) $(LDFLAGS)

$(MODULE): $(MAIN_BINARY)
	$(RM) $(MODULE) && $(LN_S) $(MAIN_BINARY) $(MODULE)

install:: $(WINE_BINARIES) $(MANPAGES) $(INSTALLDIRS)
	for f in $(WINE_BINARIES); do \
	  if [ "$(MAIN_BINARY)" = "$$f" ]; \
	  then $(INSTALL_PROGRAM) $$f $(DESTDIR)$(bindir)/$(MODULE); \
	  else $(INSTALL_PROGRAM) $$f $(DESTDIR)$(bindir)/$$f; \
	  fi; \
	done
	$(INSTALL_DATA) wine.man $(DESTDIR)$(mandir)/man$(prog_manext)/wine.$(prog_manext)

uninstall::
	-cd $(DESTDIR)$(bindir) && $(RM) $(WINE_BINARIES) $(MODULE)
	$(RM) $(DESTDIR)$(mandir)/man$(prog_manext)/wine.$(prog_manext)

clean::
	$(RM) version.c version-stamp

version-stamp: dummy
	(GIT_DIR=$(TOPSRCDIR)/.git git-describe HEAD 2>/dev/null || echo "wine-@PACKAGE_VERSION@") | sed -e 's/\(.*\)/const char wine_version[] = "\1";/' >$@ || ($(RM) $@ && exit 1)

version.c: version-stamp
	@cmp -s version-stamp $@ || cp version-stamp $@

@DEPENDENCIES@  # everything below this line is overwritten by make depend