# This Makefile understands the following targets:
#
# all (default):	build wine
# lib:                  build libwine
# clean:		remove all intermediate files
# distclean:		also remove all files created by configure
# install:              install everything
# depend:		create the dependencies
# etags:		create a TAGS file for Emacs.
# manpages:		compile manpages for Wine API
#

# Main target to build

MAIN_TARGET = @MAIN_TARGET@
LIB_TARGET  = @LIB_TARGET@

# Directories

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

LIBSUBDIRS = \
	rc \
	tools \
	controls \
	files \
	graphics \
	graphics/metafiledrv \
	graphics/x11drv \
	ipc \
	library \
	loader \
	memory \
	misc \
	msdos \
	multimedia \
	objects \
	ole \
	relay32 \
	resources \
	scheduler \
	tsx11 \
	win32 \
	windows

EMUSUBDIRS = \
	debugger \
	graphics/win16drv \
	if1632 \
	miscemu

PROGSUBDIRS = libtest programs

DOCSUBDIRS = documentation

# All sub-directories
ALLSUBDIRS = \
	$(LIBSUBDIRS) \
	$(EMUSUBDIRS) \
	$(PROGSUBDIRS) \
	$(DOCSUBDIRS)

# Sub-directories to run make depend into
DEPENDSUBDIRS = $(LIBSUBDIRS) $(EMUSUBDIRS) $(DOCSUBDIRS)

# Sub-directories to run make install into
INSTALLSUBDIRS = $(DOCSUBDIRS)

LIBOBJS = \
	controls/controls.o \
	files/files.o \
	graphics/graphics.o \
	graphics/metafiledrv/metafiledrv.o \
	graphics/x11drv/x11drv.o \
	ipc/ipc.o \
	loader/loader.o \
	memory/memory.o \
	misc/misc.o \
	msdos/msdos.o \
	multimedia/multimedia.o \
	objects/objects.o \
	ole/ole.o \
	relay32/relay32.o \
	resources/resources.o \
	scheduler/scheduler.o \
	tsx11/tsx11.o \
	win32/win32.o \
	windows/windows.o

EMUOBJS = \
	debugger/debugger.o \
	graphics/win16drv/win16drv.o \
	if1632/if1632.o \
	miscemu/miscemu.o

all: $(MAIN_TARGET)

@MAKE_RULES@

install:: install_$(MAIN_TARGET)

emu: wine

lib: $(LIBSUBDIRS) $(LIB_TARGET)

wine wine.sym: $(LIBSUBDIRS) $(LIB_TARGET) $(EMUSUBDIRS) dummy
	$(CC) -o wine $(EMUOBJS) $(LIB_TARGET) $(LDOPTIONS) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)
	nm -n wine | grep -v _compiled >wine.sym

libwine.a: $(LIBOBJS)
	$(RM) $@
	$(AR) $@ $(LIBOBJS)
	$(RANLIB) $@

libwine.so.1.0: $(LIBOBJS)
	$(CC) -shared -Wl,-soname,libwine.so -o$@ $(LIBOBJS) $(LDOPTIONS) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)

install_emu: install_lib
	$(INSTALL_PROGRAM) wine $(bindir)/wine

install_lib: install_includes
	$(INSTALL_DATA) $(LIB_TARGET) $(libdir)

install_includes: dummy
	if [ -d $(includedir) ]; then : ; else $(MKDIR) $(includedir); fi 
	cd include; $(INSTALL_DATA) windows.h wintypes.h $(includedir)

$(ALLSUBDIRS): dummy
	@cd $@; $(SUBMAKE)

install_programs: dummy
	@cd programs; $(SUBMAKE) install

install::
	for i in $(INSTALLSUBDIRS); do (cd $$i && $(MAKE) install) || exit 1; done

depend:: dummy
	for i in $(DEPENDSUBDIRS); do (cd $$i && $(MAKE) depend) || exit 1; done

TAGS etags:
	etags `find $(TOPSRCDIR) -name '*.[chS]' -print | grep -v dbgmain`

manpages:
	-$(MKDIR) $(TOPOBJDIR)/documentation/man3w
	for i in $(LIBSUBDIRS); do (cd $$i && $(MAKE) man); done

clean::
	for i in $(ALLSUBDIRS); do (cd $$i; $(MAKE) clean) || exit 1; done
	for i in include; do (cd $$i; $(RM) *.o \#*\# *~ *.bak *.orig *.rej *.flc); done
	$(RM) wine wine.sym libwine.a libwine.so.1.0 TAGS

distclean: clean
	$(RM) config.* Make.rules include/config.h
	$(RM) `find . \( -name Makefile -o -size 0 \) -print`

configure: configure.in
	autoconf

include/config.h.in: configure.in include/acconfig.h
	autoheader -l include

### Dependencies:
