# Start of settings from configure.bat 
COMPILER=gcc
NODEBUG=1 
NOCYGWIN=1 
INSTALL_DIR=d:/Meadow-netinstall/dist
MAGICKDIR="C:\Program Files\ImageMagick-6.2.4-Q16"
# End of settings from configure.bat
 
#
#  Makefile definition file for building GNU Emacs on the Microsoft W32 API.
#  Copyright (c) 2000-2001 Free Software Foundation, Inc.
#  
#  GNU Emacs is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#  
#  GNU Emacs is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with GNU Emacs; see the file COPYING.  If not, write to
#  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#  Boston, MA 02111-1307, USA.

# Ensure 'all' is the default target
all:

# NOTES
# 
# I tried to force gmake to use the native shell for simplicity, by
# setting SHELL as below, but this didn't work reliably because of
# various case sensitivity niggles.  Specifically, COMSPEC (which is in
# fact usually spelled ComSpec on NT, to make life difficult) typically
# references "cmd.exe" (on NT) when the file is actually called
# "CMD.EXE" on disk for hysterical raisons.  As a result, GNU make
# thinks it doesn't exist (unless compiled with a switch to ignore
# case), and so doesn't change which shell it will invoke to execute
# commands.
# 
# It would be possible, though very tedious using just gmake facilities,
# to convert the COMSPEC value to uppercase to solve this problem, but
# it isn't worth it.  That is partly because, even when using the native
# shell, gmake tends to not be happy with backslashes in command
# strings.  The obvious solution is to use forward slashes as much as
# possible, which can be made to work most of the time (putting
# filenames in quotes often helps), but there are still some internal
# cmd.exe commands like `del' and `copy' that won't work with them.
# Although it is possible to convert slashes to backslashes when
# necessary, gmake requires explicitly calling its subst function, which
# nmake does not understand).  For this reason, it is simplest to
# mandate that rm and cp be available, so we can use Unix-format file
# names everywhere.  (Fortunately both MS and GNU make, and the
# respective compilers, are happy with Unix-format names.)
# 
# Since we cannot easily force the choice of a particular shell, we must
# make the effort to cope with whichever shell is being used.
# Fortunately, the only command we need to use that is shell specific is
# the testing of a file's existence for the purpose of working out when
# we are copying files to their original location.  That particular
# requirement is abstracted easily enough.
# 
# The only other problem area was the change of directory when running
# temacs to dump emacs.exe (where gmake doesn't support cd foo in any
# useful way), but that has been resolved by modifying the Windows
# unexec function slightly to not require the directory change while
# still allowing objects and binaries to be in subdirectories.

# This doesn't work.
#SHELL:=$(COMSPEC)

include ../nt/meadow.defs

# Determine whether make is using sh or cmd/command as shell; cmd.exe
# will output "ECHO is on" when echo is given by itself, while sh will
# not produce any output.
sh_output := $(shell echo)
ifeq "$(findstring ECHO, $(sh_output))" "ECHO"
THE_SHELL = $(COMSPEC)$(ComSpec)
SHELLTYPE=CMD
else
USING_SH = 1
THE_SHELL = $(SHELL)
SHELLTYPE=SH
CURDIR=$(subst \,/,$(shell cygpath -w $(shell pwd)))
endif

MAKETYPE=gmake

THISDIR		= .

# Cygwin has changed quoting rules somewhat since b20, in a way that
# affects makefiles using sh as the command processor, so we need to
# detect which rules to use.
# Now Meadow2 requires new Cygwin and suppress this noisy warnings.
ifdef USING_SH
#sh_output := $(shell echo [Please ignore a syntax error on the next line - it is intentional] 1>&2)
#sh_output := $(shell echo foo")
#ifeq "$(sh_output)" ""
NEW_CYGWIN = 1
#endif
endif

ALL_DEPS	= $^
EMPTY =
SPACE = $(EMPTY) $(EMPTY)

SUBSYSTEM_WINDOWS=-Wl,-subsystem,windows
SUBSYSTEM_CONSOLE=-Wl,-subsystem,console

# INSTALL_DIR is the directory into which emacs will be installed.
#
ifndef INSTALL_DIR
INSTALL_DIR     = c:/Meadow
endif

INSTALL_DIR_M   = $(shell cygpath -u $(INSTALL_DIR))
INSTALL_DIR_M_DOS = $(shell cygpath -w $(INSTALL_DIR_M))
INSTALL_DIR_DOS = $(shell cygpath -w $(INSTALL_DIR))

export EMACSLOADPATH

# Determine the architecture we're running on.
# Define ARCH for our purposes; 
# Define CPU for use by ntwin32.mak;
# Define CONFIG_H to the appropriate config.h for the system;
#
ifdef PROCESSOR_ARCHITECTURE
# We're on Windows NT
CPU		= $(PROCESSOR_ARCHITECTURE)
CONFIG_H	= config.nt
OS_TYPE		= windowsnt
 ifeq "$(PROCESSOR_ARCHITECTURE)" "x86"
ARCH		= i386
CPU		= i386
 else
  ifeq "$(PROCESSOR_ARCHITECTURE)" "MIPS"
ARCH		= mips
  else
   ifeq "$(PROCESSOR_ARCHITECTURE)" "ALPHA"
ARCH		= alpha
   else
    ifeq "$(PROCESSOR_ARCHITECTURE)" "PPC"
ARCH		= ppc
    else
error Unknown architecture type "$(PROCESSOR_ARCHITECTURE)"
    endif
   endif
  endif
 endif
else
# We're on Windows 95
ARCH		= i386
CPU		= i386
CONFIG_H	= config.nt
OS_TYPE		= windows95
endif

AR		= ar -rsc
AR_OUT		=
CC		= gcc
CC_OUT		= -o$(SPACE)
LINK		= gcc
LINK_OUT	= -o$(SPACE)
RC		= windres -O coff
RC_OUT		= -o$(SPACE)
RC_INCLUDE	= --include-dir$(SPACE)

libc		= 
baselibs	= 
O		= o
A		= a

BASE_LIBS	= $(libc) $(baselibs)

ADVAPI32	= -ladvapi32
COMDLG32	= -lcomdlg32
GDI32		= -lgdi32
MPR		= -lmpr
SHELL32		= -lshell32
USER32		= -luser32
WSOCK32		= -lwsock32

ifdef NOOPT
DEBUG_CFLAGS	= -DEMACSDEBUG
else
DEBUG_CFLAGS	= 
endif
ifdef MEADOW
MEADOW_CFLAGS	= -DMEADOW="\"$(MEADOW_VERSION)\"" \
		  -DMEADOW_VERSION_STRING=$(MEADOW_VERSION_STRING)

ifdef W32_VER4
MEADOW_CFLAGS	+= -DW32_VER4
endif

CFLAGS          = -I. -DWIN32_LEAN_AND_MEAN $(ARCH_CFLAGS) -D$(ARCH) \
		  -D_CRTAPI1=_cdecl \
		  $(DEBUG_CFLAGS) $(USER_CFLAGS) $(LOCAL_FLAGS)	\
		  $(MEADOW_CFLAGS)
else
CFLAGS          = -I. -DWIN32_LEAN_AND_MEAN $(ARCH_CFLAGS) -D$(ARCH) \
		  -D_CRTAPI1=_cdecl \
		  $(DEBUG_CFLAGS) $(USER_CFLAGS) $(LOCAL_FLAGS)
endif
EMACS_EXTRA_C_FLAGS = -DUSE_CRT_DLL=1

# see comments in allocate_heap in w32heap.c before changing any of the
# -stack, -heap, or -image-base settings.
ifdef MEADOW
STARTUP_ENTRY = _mw32_start
else
STARTUP_ENTRY = __start
endif

TEMACS_EXTRA_LINK = -Wl,-stack,0x00800000 -Wl,-heap,0x00100000 -Wl,-image-base,0x01000000 -g $(SUBSYSTEM_CONSOLE) -Wl,-entry,$(STARTUP_ENTRY) -Wl,-Map,$(BLD)/temacs.map

ifdef NOOPT
OBJDIR          = oo
else
OBJDIR          = oo-spd
endif
$(OBJDIR):;	-mkdir -p "$(OBJDIR)"
BLD             = $(OBJDIR)/$(ARCH)
$(BLD):         $(OBJDIR)
		-mkdir -p "$(BLD)"

COMPILER_TEMP_FILES =

CP		= cp -f
ifeq "$(OS_TYPE)" "windows95"
CP_DIR		= xcopy /f/r/i/e/d/k/y
else
CP_DIR		= xcopy /f/r/i/e/d/k/y /EXCLUDE:"..\nt\excludes.Meadow"
endif
DEL		= rm -f
DEL_TREE	= rm -rf

ifdef USING_SH

IFNOTSAMEDIR	= if [ ! -s ../same-dir.tst ] ; then
FOREACH		= for f in
FORVAR		= $${f}
FORDO		= ; do
ENDFOR		= ; done
ENDIF		= ; fi
ARGQUOTE	= '
ifdef NEW_CYGWIN
DQUOTE		= "
else
DQUOTE		= ""
endif

else

IFNOTSAMEDIR	= if not exist ../same-dir.tst
FOREACH		= for %%f in (
FORVAR		= %%f
FORDO		= ) do
ENDFOR		=
ENDIF		=
ARGQUOTE	= "
DQUOTE		= \"

endif

ifdef NODEBUG
DEBUG_FLAG = 
DEBUG_LINK =
else
DEBUG_FLAG = -g
DEBUG_LINK = -g
endif

ifdef NOCYGWIN
NOCYGWIN = -mno-cygwin
endif

ifeq "$(ARCH)" "i386"
ifdef NOOPT
ARCH_CFLAGS     = -D_X86_=1 -c $(DEBUG_FLAG) $(NOCYGWIN)
else
ARCH_CFLAGS     = -D_X86_=1 -c $(DEBUG_FLAG) $(NOCYGWIN) -mcpu=i686 -O2 \
		  # -fbuiltin \
		  # -finline-functions \
		  # -fomit-frame-pointer
endif
ARCH_LDFLAGS	= $(SYS_LDFLAGS)
else
ERROR Unknown architecture type "$(ARCH)".
endif

LINK_FLAGS	= $(ARCH_LDFLAGS) $(DEBUG_LINK) $(NOCYGWIN) $(USER_LDFLAGS)

.DEFAULT:

$(BLD)/%.o: %.c
		$(CC) $(CFLAGS) $(CC_OUT)$@ $<
#  Makefile for GNU Emacs on the Microsoft W32 API.
#  Copyright (c) 2000-2001 Free Software Foundation, Inc.
#
#  This file is part of GNU Emacs.
#  
#  GNU Emacs is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#  
#  GNU Emacs is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with GNU Emacs; see the file COPYING.  If not, write to the
#  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#  Boston, MA 02111-1307, USA.
#

ALL =

all: $(ALL)

SQUOTE='
# '

lisp = $(CURDIR)

# You can specify a different executable on the make command line,
# e.g. "make EMACS=../src/emacs ...".

ifdef MEADOW
EMACS = "$(THISDIR)/../bin/Meadow.exe"
else
EMACS = "$(THISDIR)/../bin/emacs.exe"
endif

# Command line flags for Emacs.  This must include --multibyte,
# otherwise some files will not compile.

EMACSOPT = -batch --no-init-file --no-site-file --multibyte

# Set EMACSLOADPATH correctly (already defined in environment).
EMACSLOADPATH=$(lisp)

lisptagsfiles1 = $(lisp)/*.el
lisptagsfiles2 = $(lisp)/*/*.el
ETAGS = "../lib-src/$(BLD)/etags"

# Files which should not be compiled.
# - emacs-lisp/cl-specs.el:  only contains `def-edebug-spec's so there's
#   no point compiling it, although it doesn't hurt.

DONTCOMPILE = \
	$(lisp)/cus-load.el \
	$(lisp)/cus-start.el \
	$(lisp)/emacs-lisp/cl-specs.el \
	$(lisp)/eshell/esh-maint.el \
	$(lisp)/eshell/esh-groups.el \
	$(lisp)/finder-inf.el \
	$(lisp)/forms-d2.el \
	$(lisp)/forms-pass.el \
	$(lisp)/generic-x.el \
	$(lisp)/international/latin-1.el \
	$(lisp)/international/latin-2.el \
	$(lisp)/international/latin-3.el \
	$(lisp)/international/latin-4.el \
	$(lisp)/international/latin-5.el \
	$(lisp)/international/latin-8.el \
	$(lisp)/international/latin-9.el \
	$(lisp)/international/mule-conf.el \
	$(lisp)/loaddefs.el \
	$(lisp)/loadup.el \
	$(lisp)/mail/blessmail.el \
	$(lisp)/patcomp.el \
	$(lisp)/paths.el \
	$(lisp)/play/bruce.el \
	$(lisp)/subdirs.el \
	$(lisp)/term/internal.el \
	$(lisp)/term/AT386.el  \
	$(lisp)/term/apollo.el \
	$(lisp)/term/bobcat.el \
	$(lisp)/term/iris-ansi.el \
	$(lisp)/term/keyswap.el \
	$(lisp)/term/linux.el \
	$(lisp)/term/lk201.el \
	$(lisp)/term/news.el \
	$(lisp)/term/vt102.el \
	$(lisp)/term/vt125.el \
	$(lisp)/term/vt200.el \
	$(lisp)/term/vt201.el \
	$(lisp)/term/vt220.el \
	$(lisp)/term/vt240.el \
	$(lisp)/term/vt300.el \
	$(lisp)/term/vt320.el \
	$(lisp)/term/vt400.el \
	$(lisp)/term/vt420.el \
	$(lisp)/term/wyse50.el \
	$(lisp)/term/xterm.el \
	$(lisp)/version.el

# Files to compile before others during a bootstrap.  This is done to
# speed up the bootstrap process.  The CC files are compiled first
# because CC mode tweaks the compilation process, and requiring
# cc-mode when it is not compiled doesn't work during the
# bootstrapping.

COMPILE_FIRST = \
	$(lisp)/emacs-lisp/byte-opt.el \
	$(lisp)/emacs-lisp/bytecomp.el \
	$(lisp)/subr.el \
	$(lisp)/progmodes/cc-mode.el \
	$(lisp)/progmodes/cc-vars.el

# The actual Emacs command run in the targets below.

emacs = $(EMACS) $(EMACSOPT)

# Common command to find subdirectories

setwins=subdirs=`find $$wd -type d -print`; \
	for file in $$subdirs; do \
	   case $$file in */Old | */RCS | */CVS | */CVS/* | */=* ) ;; \
		*) wins="$$wins $$file" ;; \
	   esac; \
        done

# Have to define the list of subdirs manually when not using sh.
WINS=\
	calendar \
	emacs-lisp \
	emulation \
	eshell \
	gnus \
	international \
	language \
	mail \
	net \
	play \
	progmodes \
	term \
	textmodes \
	toolbar

doit:

cus-load.el:
	touch $@
custom-deps: cus-load.el doit
	@echo Directories: $(WINS)
	-$(emacs) -l cus-dep --eval $(ARGQUOTE)(setq find-file-hooks nil)$(ARGQUOTE) -f custom-make-dependencies $(lisp) $(WINS)

finder-inf.el:
	echo (provide $(SQUOTE)finder-inf)>> $@

finder-data: finder-inf.el doit
	@echo Directories: $(WINS)
	$(emacs) -l finder -f finder-compile-keywords-make-dist $(lisp) $(WINS)

loaddefs.el:
	echo ;;; loaddefs.el --- automatically extracted autoloads> $@
	echo ;;; Code:>> $@
	echo >> $@
	echo ;;; Local Variables:>> $@
	echo ;;; version-control: never>> $@
	echo ;;; no-byte-compile: t>> $@
	echo ;;; no-update-autoloads: t>> $@
	echo ;;; End:>> $@
	echo ;;; loaddefs.el ends here>> $@

autoloads: loaddefs.el doit
	@echo Directories: $(WINS)
	$(emacs) -l autoload \
		--eval $(ARGQUOTE)(setq find-file-hooks nil \
			find-file-suppress-same-file-warnings t \
			generated-autoload-file \
			  $(DQUOTE)$(lisp)/loaddefs.el$(DQUOTE))$(ARGQUOTE) \
		-f batch-update-autoloads $(lisp) $(WINS)

subdirs.el:
	$(MAKE) $(MFLAGS) update-subdirs

# Need separate version for sh and native cmd.exe
update-subdirs: update-subdirs-$(SHELLTYPE)

update-subdirs-CMD: doit
	@set QWINS=
	@for %d in ($(WINS)) do if not (%d)==(term) set QWINS=%QWINS% "%d"
	echo ;; In load-path, after this directory should come> subdirs.el
	echo ;; certain of its subdirectories.  Here we specify them.>> subdirs.el
	echo (normal-top-level-add-to-load-path $(SQUOTE)(%QWINS%))>> subdirs.el

update-subdirs-SH: doit
	wd=$(lisp); $(setwins); \
	for file in $$wins; do \
	   $(srcdir)/update-subdirs $$file; \
	done;

updates: update-subdirs autoloads finder-data custom-deps

TAGS: $(lisptagsfiles1) $(lisptagsfiles2)
	$(ETAGS) $(lisptagsfiles1) $(lisptagsfiles2)

TAGS-LISP: $(lispsource)$(lisptagsfiles1) $(lispsource)$(lisptagsfiles2)
	$(ETAGS) -o TAGS-LISP $(lispsource)$(lisptagsfiles1) $(lispsource)$(lisptagsfiles2)

.SUFFIXES: .elc .el

.el.elc:
	-$(emacs) -f batch-byte-compile $<

$(DONTCOMPILE:.el=.elc):
	-$(DEL) $@

# Compile all Lisp files, except those from DONTCOMPILE.  This
# compiles files unconditionally.  All .elc files are made writable
# before compilation in case we checked out read-only (CVS option -r).
# Files MUST be compiled one by one.  If we compile several files in a
# row we can't make sure that the compilation environment is clean.
# We also set the load-path of the Emacs used for compilation to the
# current directory and its subdirectories, to make sure require's and
# load's in the files being compiled find the right files.

compile-files: subdirs.el $(addsuffix c,$(COMPILE_FIRST)) $(addsuffix c,$(addprefix $(lisp)/, $(wildcard *.el) $(wildcard */*.el))) doit

# Backup compiled Lisp files in elc.tar.gz.  If that file already
# exists, make a backup of it.

backup-compiled-files:
	-mv $(lisp)/elc.tar.gz $(lisp)/elc.tar.gz~
	-tar czf $(lisp)/elc.tar.gz $(lisp)/*.elc $(lisp)/*/*.elc

# Compile Lisp files, but save old compiled files first.

compile: backup-compiled-files compile-files

# Recompile all Lisp files which are newer than their .elc files.
# Note that this doesn't create .elc files.  It only recompiles if an
# .elc is present.

recompile: doit
	$(emacs) -f batch-byte-recompile-directory .

# Prepare a bootstrap in the lisp subdirectory.  Build loaddefs.el,
# because it's not sure it's up-to-date, and if it's not, that might
# lead to errors during the bootstrap because something fails to
# autoload as expected.  Remove compiled Lisp files so that
# bootstrap-emacs will be built from sources only.

# Need separate version for sh and native cmd.exe
bootstrap-clean: bootstrap-clean-$(SHELLTYPE)

bootstrap-clean-CMD:
	if exist $(EMACS) $(MAKE) $(MFLAGS) autoloads
	-for %f in (. $(WINS)) do for %g in (%f\*.elc) do @$(DEL) %g

bootstrap-clean-SH:
	if test -f $(EMACS); then $(MAKE) $(MFLAGS) autoloads; fi
	rm -f ./*.elc
	rm -f ./*/*.elc

# Generate/update files for the bootstrap process.

bootstrap: autoloads compile-files custom-deps

#
# Assuming INSTALL_DIR_M is defined, copy the elisp files to it
# Windows 95 makes this harder than it should be.
#
install:
		- mkdir -p "$(INSTALL_DIR_M)/lisp"
		- $(DEL) ../same-dir.tst
		- $(DEL) "$(INSTALL_DIR_M)/same-dir.tst"
		echo SameDirTest > "$(INSTALL_DIR_M)/same-dir.tst"
#ifdef COPY_LISP_SOURCE
		$(IFNOTSAMEDIR) $(CP_DIR) . "$(INSTALL_DIR_M_DOS)\lisp" $(ENDIF)
#else
#		$(IFNOTSAMEDIR) $(CP_DIR) *.elc "$(INSTALL_DIR_M_DOS)\lisp" $(ENDIF)
#		$(IFNOTSAMEDIR) $(CP) cus-load.el "$(INSTALL_DIR_M)/lisp" $(ENDIF)
#		$(IFNOTSAMEDIR) $(CP) forms*.el "$(INSTALL_DIR_M)/lisp" $(ENDIF)
#		$(IFNOTSAMEDIR) $(CP) patcomp.el "$(INSTALL_DIR_M)/lisp" $(ENDIF)
#		$(IFNOTSAMEDIR) $(CP) subdirs.el "$(INSTALL_DIR_M)/lisp" $(ENDIF)
#		$(IFNOTSAMEDIR) $(CP) version.el "$(INSTALL_DIR_M)/lisp" $(ENDIF)
#		$(IFNOTSAMEDIR) $(CP) mail/blessmail.el "$(INSTALL_DIR_M)/lisp/mail" $(ENDIF)
#		$(IFNOTSAMEDIR) $(CP) mail/sc.el "$(INSTALL_DIR_M)/lisp/mail" $(ENDIF)
#		$(IFNOTSAMEDIR) $(CP) play/bruce.el "$(INSTALL_DIR_M)/lisp/play" $(ENDIF)
#		$(IFNOTSAMEDIR) $(CP) international/latin-*.el "$(INSTALL_DIR_M)/lisp/international" $(ENDIF)
#		$(IFNOTSAMEDIR) $(CP) international/mule-conf.el "$(INSTALL_DIR_M)/lisp/international" $(ENDIF)
#endif
		- $(DEL) ../same-dir.tst
		- $(DEL) "$(INSTALL_DIR_M)/same-dir.tst"

#
# Maintenance
# 
clean:
		- $(DEL) *~
