#
#  Hacked up Nmake makefile for GNU Emacs
#
#   Tim Fleehart (apollo@online.com)		17-Apr-92
#   Geoff Voelker (voelker@cs.washington.edu)	11-20-93
#
#  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, 675 Mass Ave, Cambridge, MA 02139, USA.  */
#

#
# You must have a some of environment variables set:
#
# 	BUILD_DEFAULT_TARGETS must be set to one of "-mips" ,"-386", or "-alpha"
#		Build for mips assumes r4000.
#
#	INC must ne set the full path to your NT .h files.
#
#	LIB must be set to the full path to your NT .lib files.
#
#

#
# Set up compiler flags
#
!IF "$(BUILD_DEFAULT_TARGETS)" == "-mips"
# Set up the compiler flags for building on mips

ARCH	      = mips
CFLAGS 	      = -nologo -D_MIPS_=1 /c /W3 /Od -Gt0 \
		-D__stdcall= -D__cdecl= -DWIN32_LEAN_AND_MEAN

# disable optimization --- it hangs emacs

!ELSE
!IF "$(BUILD_DEFAULT_TARGETS)" == "-386"
# Set up the compiler flags for building on x86

ARCH 	      = i386
CFLAGS 	      = -nologo -D_X86_=1 -c -Zedl -W2 -H63 -G3d -Ox

!ELSE
!IF "$(BUILD_DEFAULT_TARGETS)" == "-alpha"
# Set up the compiler flags for building on alpha

ARCH            = alpha
CFLAGS          = -D_ALPHA_=1 -c -Zed -W2 -Ox\
                 -D__stdcall= -D__cdecl= -DWIN32_LEAN_AND_MEAN
!ELSE
!ERROR You must specify BUILD_DEFAULT_TARGETS as either -alpha -mips or -386.
!ENDIF
!ENDIF
!ENDIF

!IFNDEF INC
!ERROR You need to set INC to the NT .h files directory.
!ELSE
INCP = -I. -I$(INC) -I$(INC)\crt
!ENDIF

!IFNDEF LIB
!ERROR You need to set LIB to the NT .lib files directory.
!ENDIF

#
# HAVE_CONFIG_H is required by some generic gnu sources stuck into
# the emacs source tree.
#
GENERICFLAGS  = -Demacs=1 -DWINDOWSNT -DHAVE_CONFIG_H

NAME 	      =	emacs
OBJDIR	      = obj
BLD	      =	$(OBJDIR)\$(ARCH)

TARGET	      = $(BLD)\$(NAME).exe
TLIB 	      =	$(BLD)\$(NAME).lib
TOBJ 	      =	$(BLD)\$(NAME).obj


#
# Split up the objects into two sets so that we don't run out of
# command line space when we link them into a library.
#
OBJ1 =	$(BLD)\abbrev.obj	\
	$(BLD)\alloc.obj	\
	$(BLD)\alloca.obj	\
	$(BLD)\buffer.obj	\
	$(BLD)\bytecode.obj	\
	$(BLD)\callint.obj	\
	$(BLD)\callproc.obj	\
	$(BLD)\casefiddle.obj	\
	$(BLD)\cm.obj		\
	$(BLD)\cmds.obj		\
	$(BLD)\crt0.obj		\
	$(BLD)\data.obj		\
	$(BLD)\dired.obj	\
	$(BLD)\dispnew.obj	\
	$(BLD)\doc.obj		\
	$(BLD)\doprnt.obj	\
	$(BLD)\editfns.obj	\
	$(BLD)\eval.obj		\
	$(BLD)\fileio.obj	\
	$(BLD)\filelock.obj	\
	$(BLD)\filemode.obj	\
	$(BLD)\fns.obj		\
	$(BLD)\indent.obj	\
	$(BLD)\insdel.obj	\
	$(BLD)\keyboard.obj	\
	$(BLD)\keymap.obj	\
	$(BLD)\lastfile.obj	\
	$(BLD)\lread.obj	\
	$(BLD)\macros.obj	\
	$(BLD)\marker.obj	\
	$(BLD)\minibuf.obj	\
	$(BLD)\mocklisp.obj

OBJ2 = 	$(BLD)\ntinevt.obj	\
	$(BLD)\ntproc.obj	\
	$(BLD)\ntterm.obj	\
	$(BLD)\print.obj	\
	$(BLD)\process.obj	\
	$(BLD)\regex.obj	\
	$(BLD)\scroll.obj	\
	$(BLD)\search.obj	\
	$(BLD)\syntax.obj	\
	$(BLD)\sysdep.obj	\
	$(BLD)\term.obj		\
	$(BLD)\termcap.obj	\
	$(BLD)\tparam.obj	\
	$(BLD)\undo.obj		\
	$(BLD)\window.obj	\
	$(BLD)\xdisp.obj	\
	\
	$(BLD)\casetab.obj	\
	$(BLD)\floatfns.obj	\
	$(BLD)\frame.obj	\
	$(BLD)\getloadavg.obj	\
	$(BLD)\gmalloc.obj	\
	$(BLD)\intervals.obj	\
	$(BLD)\prefix-args.obj	\
	$(BLD)\ralloc.obj	\
	$(BLD)\textprop.obj	\
	$(BLD)\vm-limit.obj

LIBS =	$(TLIB)			\
	$(LIB)\setargv.obj	\
	$(LIB)\kernel32.lib	\
	$(LIB)\advapi32.lib	\
$(LIB)\libc.lib


!IF "$(BUILD_DEFAULT_TARGETS)" == "-mips"
#
#
# mips
#
#

$(TARGET): $(LIBS) $(TOBJ)
	link32 -stack:0x2000000 -base:0xc00000 -out:$(TARGET) -debug:PARTIAL -debugtype:COFF -machine:mips -subsystem:console -entry:mainCRTStartup $(TOBJ) $(LIBS)


#
# Split up the library build into two phases...otherwise we run out of
# command line space.
#
$(TLIB): $(OBJ1) $(OBJ2)
	@- lib32 -out:$(TLIB) $(OBJ1)
	@- lib32 -out:$(TLIB) $(TLIB) $(OBJ2)

.c{$(BLD)}.obj:
	@- if not exist $(OBJDIR) md $(OBJDIR) >nul 2>&1
	@- if not exist $(BLD) md $(BLD) >nul 2>&1
	@- chmode -r $@ >nul 2>&1
	@- del $@ >nul 2>&1
	mcl $(CFLAGS) $(GENERICFLAGS) $(INCP) -Fo$@ $<

!ELSE
!IF "$(BUILD_DEFAULT_TARGETS)" == "-alpha"
$(TARGET): $(LIBS) $(TOBJ)
	link32 -stack:0x2000000 -base:0xc00000 -out:$(TARGET) -debug:PARTIAL -debugtype:COFF -machine:alpha -subsystem:console -entry:mainCRTStartup $(TOBJ) $(LIBS)


#
# Split up the library build into two phases...otherwise we run out of
# command line space.
#
$(TLIB): $(OBJ1) $(OBJ2)
	@- lib32 -out:$(TLIB) $(OBJ1)
	@- lib32 -out:$(TLIB) $(TLIB) $(OBJ2)

.c{$(BLD)}.obj:
	@- if not exist $(OBJDIR) md $(OBJDIR) >nul 2>&1
	@- if not exist $(BLD) md $(BLD) >nul 2>&1
	@- chmode -r $@ >nul 2>&1
	@- del $@ >nul 2>&1
	claxp $(CFLAGS) $(GENERICFLAGS) $(INCP) -Fo$@ $<
!ELSE
#
#
# i386
#
#

$(TARGET): $(LIBS) $(TOBJ)
	link32 -stack:0x2000000 -base:0xc00000 -out:$(TARGET) -debug:PARTIAL -debugtype:COFF -machine:i386 -align:0x1000 -subsystem:console -entry:mainCRTStartup $(TOBJ) $(LIBS)

#
# Split up the library build into two phases...otherwise we run out of
# command line space.
#
$(TLIB): $(OBJ1) $(OBJ2)
	@- lib32 -out:$(TLIB) $(OBJ1)
	@- lib32 -out:$(TLIB) $(TLIB) $(OBJ2)

.c{$(BLD)}.obj:
	@- if not exist $(OBJDIR) md $(OBJDIR) >nul 2>&1
	@- if not exist $(BLD) md $(BLD) >nul 2>&1
	@- chmode -r $@ >nul 2>&1
	@- del $@ >nul 2>&1
	cl386 $(CFLAGS) $(GENERICFLAGS) $(INCP) -Fo$@ $<

!ENDIF
!ENDIF

#
# Build the executable
#
all:		$(TARGET)


#
# Assuming INSTALL_DIR is defined, build and install emacs in it.
#
CP 	      = xcopy /fr
install:	all
		- mkdir $(INSTALL_DIR)\bin
		$(CP) $(TARGET) $(INSTALL_DIR)\bin

#
# Maintenance
# 
clean:;		del /q *~
		delnode /q deleted
		delnode /q obj


