# 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
# uninstall:		uninstall 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@

# Directories

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

TOOLSUBDIRS = \
	tools \
	tools/wrc

LIBSUBDIRS = \
	controls \
	console \
	dlls/advapi32 \
	dlls/avifil32 \
	dlls/comctl32 \
	dlls/commdlg \
	dlls/crtdll \
	dlls/dciman32 \
	dlls/imagehlp \
	dlls/imm32 \
	dlls/lzexpand \
	dlls/mpr \
	dlls/msacm \
	dlls/msacm32 \
	dlls/msnet32 \
	dlls/msvideo \
	dlls/ntdll \
	dlls/psapi \
	dlls/rasapi32 \
	dlls/shell32 \
	dlls/sound \
	dlls/stress \
	dlls/tapi32 \
	dlls/ver \
	dlls/version \
	dlls/win32s \
	dlls/win87em \
	dlls/winaspi \
	dlls/windebug \
	dlls/wing \
	dlls/winspool \
	dlls/wnaspi32 \
	files \
	graphics \
	graphics/enhmetafiledrv \
	graphics/metafiledrv \
	graphics/psdrv \
	graphics/ttydrv \
	graphics/win16drv \
	if1632 \
	library \
	loader \
	loader/ne \
	loader/dos \
	memory \
	misc \
	msdos \
	multimedia \
	objects \
	ole \
	relay32 \
	resources \
	scheduler \
	server \
	win32 \
	windows \
	windows/ttydrv

X11SUBDIRS = \
	graphics/x11drv \
	tsx11 \
	windows/x11drv

EMUSUBDIRS = \
	debugger \
	miscemu

PROGSUBDIRS = libtest programs

DOCSUBDIRS = documentation

INCSUBDIRS = include

# Sub-directories to run make into
BUILDSUBDIRS = \
	$(TOOLSUBDIRS) \
	$(LIBSUBDIRS) \
	$(X11SUBDIRS) \
	$(EMUSUBDIRS) \
	$(PROGSUBDIRS) \
	$(DOCSUBDIRS)

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

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

# Sub-directories to run make lint into
LINTSUBDIRS = $(LIBSUBDIRS) $(X11SUBDIRS) $(EMUSUBDIRS) $(DOCSUBDIRS)

LIBOBJS = \
	controls/controls.o \
	console/console.o \
	dlls/advapi32/advapi32.o \
	dlls/avifil32/avifil32.o \
	dlls/comctl32/comctl32.o \
	dlls/commdlg/commdlg.o \
	dlls/crtdll/crtdll.o \
	dlls/dciman32/dciman32.o \
	dlls/imagehlp/imagehlp.o \
	dlls/imm32/imm32.o \
	dlls/lzexpand/lzexpand.o \
	dlls/mpr/mpr.o \
	dlls/msacm/msacm.o \
	dlls/msacm32/msacm32.o \
	dlls/msnet32/msnet32.o \
	dlls/msvideo/msvideo.o \
	dlls/ntdll/ntdll.o \
	dlls/psapi/psapi.o \
	dlls/rasapi32/rasapi32.o \
	dlls/shell32/shell32.o \
	dlls/sound/sound.o \
	dlls/stress/stress.o \
	dlls/tapi32/tapi32.o \
	dlls/ver/ver.o \
	dlls/version/version.o \
	dlls/win32s/win32s.o \
	dlls/win87em/win87em.o \
	dlls/winaspi/winaspi.o \
	dlls/windebug/windebug.o \
	dlls/wing/wing.o \
	dlls/winspool/winspool.o \
	dlls/wnaspi32/wnaspi32.o \
	files/files.o \
	graphics/graphics.o \
	graphics/enhmetafiledrv/enhmetafiledrv.o \
	graphics/metafiledrv/metafiledrv.o \
	graphics/psdrv/psdrv.o \
	graphics/ttydrv/ttydrv.o \
	graphics/win16drv/win16drv.o \
	if1632/if1632.o \
	loader/loader.o \
	loader/ne/ne.o \
	loader/dos/dos.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 \
	server/server.o \
	win32/win32.o \
	windows/windows.o \
	windows/ttydrv/ttydrv.o

X11OBJS = \
	graphics/x11drv/x11drv.o \
	tsx11/tsx11.o \
	windows/x11drv/x11drv.o

EMUOBJS = \
	debugger/debugger.o \
	miscemu/miscemu.o

LIB_TARGET  = @LIB_TARGET@

ALT_LINK    = @ALT_LINK@

all: Makefile Make.rules $(MAIN_TARGET)
	@echo "Wine build complete."

LIBLINTS = $(LIBOBJS:.o=.ln) 
X11LINTS = $(X11OBJS:.o=.ln)
EMULINTS = $(EMUOBJS:.o=.ln)

lint:: llib-lwine.ln $(EMULINTS)
	$(LINT) $(ALLLINTFLAGS) -L. -lwine $(EMULINTS)

@MAKE_RULES@

Make.rules: Make.rules.in configure
	@echo $? is newer than 'Make.rules', please rerun ./configure!
	@exit 1

install:: install_$(MAIN_TARGET)

uninstall:: uninstall_$(MAIN_TARGET)

emu: wine

lib: $(LIBSUBDIRS) $(X11SUBDIRS) $(LIB_TARGET)

wine wine.sym: $(LIB_TARGET) $(EMUOBJS) $(X11OBJS) $(LIBOBJS)
	$(CC) -o wine $(EMUOBJS) $(ALT_LINK) $(LDOPTIONS) $(X_LIBS) $(XLIB) $(LIBS)
	nm -n wine | grep -v _compiled >wine.sym

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

llib-lwine.ln : $(LIBLINTS) $(X11LINTS)
	$(LINT) $(ALLLINTFLAGS) -owine $(LIBLINTS) $(X11LINTS)

libwine.so.1.0: $(LIBOBJS) $(X11OBJS)
	$(LDSHARED) -o$@ $(LIBOBJS) $(X11OBJS) $(LDOPTIONS)
	ln -sf $@ libwine.so

install_emu: install_lib
	[ -d $(bindir) ] || $(MKDIR) $(bindir)
	$(INSTALL_PROGRAM) wine $(bindir)/wine
	$(INSTALL_PROGRAM) loader/dos/dosmod $(bindir)/dosmod

uninstall_emu: uninstall_lib
	$(RM) $(bindir)/wine $(bindir)/dosmod

install_lib: dummy
	[ -d $(libdir) ] || $(MKDIR) $(libdir)
	if [ -f wine.sym ]; then $(INSTALL_DATA) wine.sym $(libdir)/wine.sym; fi
	if [ $(LIB_TARGET) ]; then \
	    $(INSTALL_DATA) $(LIB_TARGET) $(libdir); \
	    if [ $(LIB_TARGET) = libwine.so.1.0 ]; then $(LDCONFIG); fi \
	fi

uninstall_lib: dummy
	cd $(libdir); $(RM) $(LIB_TARGET) libwine.a libwine.so wine.sym

$(X11OBJS) $(EMUOBJS) $(LIBOBJS): $(TOOLSUBDIRS) dummy
	@cd `dirname $@`; $(SUBMAKE)

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

$(LIBLINTS) $(X11LINTS) $(EMULINTS): dummy
	@echo $@ | sed 's%\(.*\)\/[^\/]*%cd \1 \&\& make lint%' | sh


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

uninstall_programs: dummy
	@cd programs; $(SUBMAKE) uninstall

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

uninstall::
	for i in $(INSTALLSUBDIRS); do (cd $$i && $(MAKE) uninstall) || 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

htmlpages:
	-$(MKDIR) $(TOPOBJDIR)/documentation/html
	for i in $(LIBSUBDIRS); do (cd $$i && $(MAKE) html); done

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

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

# We depend on configure above for checks, so we better don't use this rule.
#configure: configure.in
#	autoconf

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

### Dependencies:
