DEFS      = -DLEX_OUTPUT_ROOT="\"lex.yy\""
TOPSRCDIR = ..
TOPOBJDIR = ..
SRCDIR    = .

EXEEXT    = 
MODULE    = none
EXTRAINCL = -I/usr/include/freetype2
FREETYPELIBS = -lfreetype -lz

PROGRAMS = \
	bin2res$(EXEEXT) \
	fnt2bdf$(EXEEXT) \
	fnt2fon$(EXEEXT) \
	make_ctests$(EXEEXT) \
	makedep$(EXEEXT) \
	relpath$(EXEEXT) \
	sfnt2fnt$(EXEEXT) \
	wineprefixcreate

MANPAGES = \
	winemaker.man

C_SRCS = \
	bin2res.c \
	fnt2bdf.c \
	fnt2fon.c \
	make_ctests.c \
	makedep.c \
	relpath.c \
	sfnt2fnt.c \

INSTALLSUBDIRS = \
	widl \
	winebuild \
	winedump \
	winegcc \
	wmc \
	wrc

SUBDIRS = \
	$(INSTALLSUBDIRS) \
	winapi

UPDATE_DESKTOP_DATABASE = update-desktop-database

all: $(PROGRAMS) $(MANPAGES) $(SUBDIRS)


# Global rules shared by all makefiles     -*-Makefile-*-
#
# Each individual makefile must define the following variables:
# TOPSRCDIR    : top-level source directory
# TOPOBJDIR    : top-level object directory
# SRCDIR       : source directory for this module
# MODULE       : name of the module being built
#
# Each individual makefile may define the following additional variables:
# C_SRCS       : C sources for the module
# C_SRCS16     : 16-bit C sources for the module
# RC_SRCS      : resource source files
# EXTRA_SRCS   : extra source files for make depend
# EXTRA_OBJS   : extra object files
# IMPORTS      : dlls to import
# DELAYIMPORTS : dlls to import in delayed mode
# SUBDIRS      : subdirectories that contain a Makefile
# EXTRASUBDIRS : subdirectories that do not contain a Makefile
# INSTALLSUBDIRS : subdirectories to run make install/uninstall into
# MODCFLAGS    : extra CFLAGS for this module

# First some useful definitions

SHELL     = /bin/sh
CC        = gcc
CFLAGS    = -g -O2
CPPFLAGS  = 
LIBS      = 
BISON     = bison
LEX       = flex
LEXLIB    = -lfl
EXEEXT    = 
OBJEXT    = o
LIBEXT    = so
DLLEXT    = .so
IMPLIBEXT = def
LDSHARED  = $(CC) -shared $(SONAME:%=-Wl,-soname,%) $(VERSCRIPT:%=-Wl,--version-script=%)
DLLTOOL   = false
DLLWRAP   = 
AR        = ar rc
RANLIB    = ranlib
STRIP     = strip
WINDRES   = false
LN        = ln
LN_S      = ln -s
TOOLSDIR  = $(TOPOBJDIR)
AS        = as
LD        = ld
LDFLAGS   = 
PRELINK   = prelink
RM        = rm -f
MV        = mv
LINT      = 
LINTFLAGS = 
FONTFORGE = fontforge
INCLUDES     = -I$(SRCDIR) -I. -I$(TOPSRCDIR)/include -I$(TOPOBJDIR)/include $(EXTRAINCL)
EXTRACFLAGS  = -Wall -pipe -fno-strict-aliasing -gstabs+ -Wdeclaration-after-statement -Wpointer-arith
ALLCFLAGS    = $(INCLUDES) $(DEFS) $(DLLFLAGS) $(EXTRACFLAGS) $(CPPFLAGS) $(CFLAGS) $(MODCFLAGS)
ALLLINTFLAGS = $(INCLUDES) $(DEFS) $(LINTFLAGS)
IDLFLAGS     = $(INCLUDES) $(DEFS) $(EXTRAIDLFLAGS)
WINEBUILDFLAGS = $(DLLFLAGS) --as-cmd "$(AS)"
MKINSTALLDIRS= $(TOPSRCDIR)/tools/mkinstalldirs -m 755
WINAPI_CHECK = $(TOPSRCDIR)/tools/winapi/winapi_check
WINEWRAPPER  = $(TOPSRCDIR)/tools/winewrapper
C2MAN        = $(TOPSRCDIR)/tools/c2man.pl
RUNTEST      = $(TOPSRCDIR)/tools/runtest
WINEBUILD    = $(TOOLSDIR)/tools/winebuild/winebuild
MAKEDEP      = $(TOOLSDIR)/tools/makedep
MAKECTESTS   = $(TOOLSDIR)/tools/make_ctests
WRC          = $(TOOLSDIR)/tools/wrc/wrc
BIN2RES      = $(TOOLSDIR)/tools/bin2res
WMC          = $(TOOLSDIR)/tools/wmc/wmc
WIDL         = $(TOOLSDIR)/tools/widl/widl
WINEGCC      = $(TOOLSDIR)/tools/winegcc/winegcc
RELPATH      = $(TOOLSDIR)/tools/relpath
SFNT2FNT     = $(TOOLSDIR)/tools/sfnt2fnt
FNT2FON      = $(TOOLSDIR)/tools/fnt2fon
RC           = $(WRC)
RC16         = $(WRC)
RCFLAGS      = --nostdinc $(INCLUDES) $(DEFS) $(EXTRARCFLAGS)
RC16FLAGS    = -O res16 $(RCFLAGS)
LDPATH       = LD_LIBRARY_PATH="$(TOOLSDIR)/libs/unicode:$$LD_LIBRARY_PATH"
DLLDIR       = $(TOPOBJDIR)/dlls
LIBDIR       = $(TOPOBJDIR)/libs
LIBPORT      = -L$(TOPOBJDIR)/libs/port -lwine_port
LIBUNICODE   = -L$(TOPOBJDIR)/libs/unicode -lwine_unicode
LIBWINE      = -L$(TOPOBJDIR)/libs/wine -lwine



# Installation infos

INSTALL         = /usr/bin/install -c $(INSTALL_FLAGS)
INSTALL_PROGRAM = ${INSTALL} $(INSTALL_PROGRAM_FLAGS)
INSTALL_SCRIPT  = ${INSTALL} $(INSTALL_SCRIPT_FLAGS)
INSTALL_DATA    = ${INSTALL} -m 644 $(INSTALL_DATA_FLAGS)
prefix          = /usr/local
exec_prefix     = ${prefix}
bindir          = ${exec_prefix}/bin
libdir          = ${exec_prefix}/lib
datadir         = ${prefix}/share
infodir         = ${prefix}/info
mandir          = ${prefix}/man
sysconfdir      = ${prefix}/etc
includedir      = ${prefix}/include/wine
dlldir          = ${exec_prefix}/lib/wine
prog_manext     = 1
api_manext      = 3w
conf_manext     = 5
CLEAN_FILES     = *.o *.a *.so *.ln *.$(LIBEXT) \\\#*\\\# *~ *% .\\\#* *.bak *.orig *.rej \
                  *.flc *.tab.c *.tab.h lex.yy.c core

OBJS = $(C_SRCS:.c=.o) $(EXTRA_OBJS)

RCOBJS = $(RC_SRCS:.rc=.res.o)
LINTS  = $(C_SRCS:.c=.ln)

# Implicit rules

.SUFFIXES: .mc .rc .mc.rc .res .res.o .spec .spec.o .idl .tlb .h .ok .sfd .ttf .man.in .man

.c.o:
	$(CC) -c $(ALLCFLAGS) -o $@ $<

.s.o:
	$(AS) -o $@ $<

.mc.mc.rc:
	$(LDPATH) $(WMC) -i -U -H /dev/null -o $@ $<

.rc.res:
	$(LDPATH) $(RC) $(RCFLAGS) -fo$@ $<

.res.res.o:
	$(WINDRES) -i $< -o $@

.spec.spec.o:
	$(WINEBUILD) $(WINEBUILDFLAGS) --dll -o $@ --main-module $(MODULE) --export $<

.idl.h:
	$(WIDL) $(IDLFLAGS) -h -H $@ $<

.idl.tlb:
	$(WIDL) $(IDLFLAGS) -t -T $@ $<

.c.ln:
	$(LINT) -c $(ALLLINTFLAGS) $< || ( $(RM) $@ && exit 1 )

.c.ok:
	$(RUNTEST) $(RUNTESTFLAGS) $< && touch $@

.sfd.ttf:
	$(FONTFORGE) -script $(TOPSRCDIR)/fonts/genttf.ff $< $@

.man.in.man:
	sed -e 's,@bindir\@,$(bindir),g' -e 's,@dlldir\@,$(dlldir),g' -e 's,@PACKAGE_STRING\@,Wine 0.9.10,g' $< >$@ || ($(RM) $@ && false)

# 'all' target first in case the enclosing Makefile didn't define any target

all: Makefile

filter:
	@$(TOPSRCDIR)/tools/winapi/make_filter --make $(MAKE) all

.PHONY: all filter

# Rules for resources

$(RC_BINARIES): $(BIN2RES) $(RC_BINSRC)
	$(BIN2RES) -f -o $@ $(SRCDIR)/$(RC_BINSRC)

$(RC_SRCS:.rc=.res) $(RC_SRCS16:.rc=.res): $(WRC) $(RC_BINARIES) $(RC_TLB)

# Rules for makefile

Makefile: Makefile.in $(TOPSRCDIR)/configure
	@echo Makefile is older than $?, please rerun $(TOPSRCDIR)/configure
	@exit 1

# Rule for linting

$(MODULE).ln : $(LINTS)
	if test "$(LINTS)" ; \
	then \
		$(LINT) $(ALLLINTFLAGS) -o$(MODULE) $(LINTS) ; \
	        $(MV) llib-l$(MODULE).ln $(MODULE).ln ; \
	else \
		$(LINT) $(ALLLINTFLAGS) -C$(MODULE) /dev/null ; \
	fi

lint:: $(MODULE).ln

# Rules for Windows API checking

winapi_check:: dummy
	$(WINAPI_CHECK) $(WINAPI_CHECK_FLAGS) $(WINAPI_CHECK_EXTRA_FLAGS) .

.PHONY: winapi_check

# Rules for dependencies

$(SUBDIRS:%=%/__depend__): dummy
	cd `dirname $@` && $(MAKE) depend

depend: $(IDL_SRCS:.idl=.h) $(SUBDIRS:%=%/__depend__)
	$(MAKEDEP) $(INCLUDES) -C$(SRCDIR) $(C_SRCS) $(C_SRCS16) $(RC_SRCS) $(RC_SRCS16) $(MC_SRCS) $(IDL_SRCS) $(EXTRA_SRCS)

.PHONY: depend $(SUBDIRS:%=%/__depend__)

# Rules for cleaning

$(SUBDIRS:%=%/__clean__): dummy
	cd `dirname $@` && $(MAKE) clean

$(SUBDIRS:%=%/__testclean__): dummy
	cd `dirname $@` && $(MAKE) testclean

$(EXTRASUBDIRS:%=%/__clean__): dummy
	-cd `dirname $@` && $(RM) $(CLEAN_FILES)

testclean:: $(SUBDIRS:%=%/__testclean__)

clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
	$(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(RC_SRCS16:.rc=.res) $(MC_SRCS:.mc=.mc.rc) $(IDL_SRCS:.idl=.h) $(PROGRAMS) $(RC_BINARIES) $(RC_TLB) $(MANPAGES)

.PHONY: clean testclean $(SUBDIRS:%=%/__clean__) $(SUBDIRS:%=%/__testclean__) $(EXTRASUBDIRS:%=%/__clean__)

# Rules for installing

$(SUBDIRS:%=%/__install__): dummy
	cd `dirname $@` && $(MAKE) install

$(SUBDIRS:%=%/__install-lib__): dummy
	cd `dirname $@` && $(MAKE) install-lib

$(SUBDIRS:%=%/__install-dev__): dummy
	cd `dirname $@` && $(MAKE) install-dev

$(SUBDIRS:%=%/__uninstall__): dummy
	cd `dirname $@` && $(MAKE) uninstall

install:: $(INSTALLSUBDIRS:%=%/__install__)

uninstall:: $(INSTALLSUBDIRS:%=%/__uninstall__)

.PHONY: install install-lib install-dev uninstall \
	$(SUBDIRS:%=%/__install__) $(SUBDIRS:%=%/__uninstall__) \
	$(SUBDIRS:%=%/__install-lib__) $(SUBDIRS:%=%/__install-dev__)

# Rules for checking that no imports are missing

$(SUBDIRS:%=%/__checklink__): dummy
	@cd `dirname $@` && $(MAKE) checklink

.PHONY: checklink $(SUBDIRS:%=%/__checklink__)

# Rules for testing

$(SUBDIRS:%=%/__test__): dummy
	@cd `dirname $@` && $(MAKE) test

$(SUBDIRS:%=%/__crosstest__): dummy
	@cd `dirname $@` && $(MAKE) crosstest

.PHONY: check test crosstest $(SUBDIRS:%=%/__test__) $(SUBDIRS:%=%/__crosstest__)

# Misc. rules

$(MC_SRCS:.mc=.mc.rc): $(WMC)

$(IDL_SRCS:.idl=.h): $(WIDL)

$(RC_TLB:.idl=.tlb): $(WIDL)

$(SUBDIRS): dummy
	@cd $@ && $(MAKE)

dummy:

.PHONY: dummy $(SUBDIRS)

# End of global rules

makedep$(EXEEXT): makedep.o
	$(CC) $(CFLAGS) -o $@ makedep.o

make_ctests$(EXEEXT): make_ctests.o
	$(CC) $(CFLAGS) -o $@ make_ctests.o

fnt2bdf$(EXEEXT): fnt2bdf.o
	$(CC) $(CFLAGS) -o $@ fnt2bdf.o $(LIBPORT)

fnt2fon$(EXEEXT): fnt2fon.o
	$(CC) $(CFLAGS) -o $@ fnt2fon.o $(LIBPORT)

relpath$(EXEEXT): relpath.o
	$(CC) $(CFLAGS) -o $@ relpath.o $(LIBPORT)

sfnt2fnt$(EXEEXT): sfnt2fnt.o
	$(CC) $(CFLAGS) -o $@ sfnt2fnt.o $(LIBUNICODE) $(LIBPORT) $(FREETYPELIBS)

bin2res$(EXEEXT): bin2res.o
	$(CC) $(CFLAGS) -o $@ bin2res.o $(LIBPORT)

wineprefixcreate: wineprefixcreate.in relpath$(EXEEXT)
	sed -e "s,@bintodlldir\@,`$(RELPATH) $(bindir) $(dlldir)`,g" -e "s,@bintodatadir\@,`$(RELPATH) $(bindir) $(datadir)/wine`,g" $(SRCDIR)/wineprefixcreate.in >$@ || ($(RM) $@ && false)
	chmod +x wineprefixcreate

install install-lib:: wineprefixcreate
	$(MKINSTALLDIRS) $(DESTDIR)$(bindir) $(DESTDIR)$(datadir)/wine $(DESTDIR)$(datadir)/applications
	$(INSTALL_SCRIPT) wineprefixcreate $(DESTDIR)$(bindir)/wineprefixcreate
	$(INSTALL_DATA) $(SRCDIR)/wine.inf $(DESTDIR)$(datadir)/wine/wine.inf
	$(INSTALL_DATA) $(SRCDIR)/wine.desktop $(DESTDIR)$(datadir)/applications/wine.desktop
	-$(UPDATE_DESKTOP_DATABASE)

install install-dev:: $(INSTALLSUBDIRS:%=%/__install__) $(MANPAGES)
	$(MKINSTALLDIRS) $(DESTDIR)$(bindir) $(DESTDIR)$(mandir)/man$(prog_manext)
	$(INSTALL_SCRIPT) $(SRCDIR)/winemaker $(DESTDIR)$(bindir)/winemaker
	$(INSTALL_DATA) winemaker.man $(DESTDIR)$(mandir)/man$(prog_manext)/winemaker.$(prog_manext)

uninstall::
	$(RM) $(DESTDIR)$(bindir)/winemaker $(DESTDIR)$(bindir)/wineprefixcreate $(DESTDIR)$(mandir)/man$(prog_manext)/winemaker.$(prog_manext) $(DESTDIR)$(datadir)/wine/wine.inf $(DESTDIR)$(datadir)/applications/wine.desktop
	-$(UPDATE_DESKTOP_DATABASE)

### Dependencies:
bin2res.o: bin2res.c ../include/config.h ../include/wine/port.h
fnt2bdf.o: fnt2bdf.c ../include/config.h ../include/wine/port.h \
 ./fnt2bdf.h ../include/wine/wingdi16.h ../include/windef.h \
 ../include/winnt.h ../include/basetsd.h ../include/pshpack2.h \
 ../include/poppack.h ../include/pshpack4.h ../include/guiddef.h \
 ../include/pshpack8.h ../include/winbase.h ../include/winerror.h \
 ../include/wingdi.h ../include/wine/winbase16.h ../include/winnls.h \
 ../include/wine/windef16.h ../include/pshpack1.h \
 ../include/wine/library.h
fnt2fon.o: fnt2fon.c ../include/config.h ../include/wine/port.h \
 ../include/wine/winbase16.h ../include/windef.h ../include/winnt.h \
 ../include/basetsd.h ../include/pshpack2.h ../include/poppack.h \
 ../include/pshpack4.h ../include/guiddef.h ../include/pshpack8.h \
 ../include/winbase.h ../include/winerror.h ../include/winnls.h \
 ../include/wine/windef16.h ../include/pshpack1.h \
 ../include/wine/library.h ../include/wine/wingdi16.h \
 ../include/wingdi.h
make_ctests.o: make_ctests.c ../include/config.h
makedep.o: makedep.c ../include/config.h ../include/wine/port.h
relpath.o: relpath.c ../include/config.h
sfnt2fnt.o: sfnt2fnt.c ../include/config.h ../include/wine/port.h \
 ../include/wine/unicode.h ../include/windef.h ../include/winnt.h \
 ../include/basetsd.h ../include/pshpack2.h ../include/poppack.h \
 ../include/pshpack4.h ../include/guiddef.h ../include/pshpack8.h \
 ../include/winbase.h ../include/winerror.h ../include/winnls.h \
 ../include/wine/wingdi16.h ../include/wingdi.h \
 ../include/wine/winbase16.h ../include/wine/windef16.h \
 ../include/pshpack1.h ../include/wine/library.h
