#
#  Hacked up Nmake makefile for GNU Emacs
#
#   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 couple 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.
#
#

!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

#CFLAGS = -std -Wb,-dwalign -G 0 -std -checkstack 4096 -excpt -g0 -Od -EL\
#	-c -Wab,-mips2 -Wab,-diag -DMIPS=1 -DNO_EXT_KEYS -DMIPSEL 	\
#	-DCONDITION_HANDLING=1 -DNT_INST=0 -DNT_UP=1 -DJAZZ		\
#	-DR4000 -Olimit 700 

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

ARCH           = alpha
CFLAGS         = -D_ALPHA_=1 -c -Zed -W2 -O2 \
                -D__stdcall= -D__cdecl= -DWIN32_LEAN_AND_MEAN 
!ELSE
!IF "$(BUILD_DEFAULT_TARGETS)" == "-386"
# Set up the compiler flags for building on x86

ARCH 	      = i386
CFLAGS 	      = -nologo -Di386=1 -DCONDITION_HANDLING=1 -DNT_UP=1 -DNT_INST=0 \
		-c -Zel -W2 -H63 -G3d -Ox -Zd

!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 -I..\src 
!ENDIF


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

GENERICFLAGS  = -DWINDOWSNT=1 -DSTDC_HEADERS=1 -DNO_LDAV=1 -DNO_ARCHIVES=1
OBJDIR	      = obj
BLD	      =	$(OBJDIR)\$(ARCH)

ALL	      =	$(BLD)\cvtmail.exe	\
		$(BLD)\digest-doc.exe	\
		$(BLD)\emacsclient.exe	\
		$(BLD)\make-docfile.exe	\
		$(BLD)\sorted-doc.exe	\
		$(BLD)\test-distrib.exe	\
		$(BLD)\ctags.exe	\
		$(BLD)\etags.exe

# don't know what (if) to do with these yet...
#
#		$(BLD)\env.exe		\
#		$(BLD)\wakeup.exe	\
#		$(BLD)\server.exe	\
#		$(BLD)\emacstool.exe	\
#		$(BLD)\fakemail.exe	\
#		$(BLD)\leditcfns.exe	\
#		$(BLD)\movemail.exe	\


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

$(BLD)\cvtmail.exe: 		$(LIBS) $(BLD)\cvtmail.obj
$(BLD)\digest-doc.exe: 		$(LIBS) $(BLD)\digest-doc.obj
$(BLD)\emacsclient.exe: 	$(LIBS) $(BLD)\emacsclient.obj
$(BLD)\make-docfile.exe: 	$(LIBS) $(BLD)\make-docfile.obj
$(BLD)\qsort.exe: 		$(LIBS) $(BLD)\qsort.obj
$(BLD)\sorted-doc.exe: 		$(LIBS) $(BLD)\sorted-doc.obj
$(BLD)\test-distrib.exe: 	$(LIBS) $(BLD)\test-distrib.obj

$(BLD)\ctags.exe: 		$(BLD)\etags.exe
	copy $(BLD)\etags.exe $(BLD)\ctags.exe

ETAGSOBJ      = $(BLD)\etags.obj \
		$(BLD)\getopt.obj \
		$(BLD)\getopt1.obj

$(BLD)\etags.exe: 		$(LIBS) $(ETAGSOBJ)
	link32 -out:$@ -debug:PARTIAL -machine:$(ARCH) -align:0x1000 -subsystem:console -entry:mainCRTStartup $(ETAGSOBJ) $(LIBS)

#
# don't know what to do with these yet...
#
# $(BLD)\yow.exe: 		$(LIBS) $(BLD)\yow.obj
# $(BLD)\emacstool.exe: 	$(LIBS) $(BLD)\emacstool.obj
# $(BLD)\env.exe: 		$(LIBS) $(BLD)\env.obj
# $(BLD)\fakemail.exe: 		$(LIBS) $(BLD)\fakemail.obj
# $(BLD)\leditcfns.exe: 	$(LIBS) $(BLD)\leditcfns.obj
# $(BLD)\server.exe: 		$(LIBS) $(BLD)\server.obj
# $(BLD)\wakeup.exe: 		$(LIBS) $(BLD)\wakeup.obj
# $(BLD)\movemail.exe: 		$(LIBS) $(BLD)\movemail.obj


obj=    dispnew.o frame.o scroll.o xdisp.o window.o \
	term.o cm.o $(XOBJ) \
	emacs.o keyboard.o macros.o keymap.o sysdep.o \
	buffer.o filelock.o insdel.o marker.o \
	minibuf.o fileio.o dired.o filemode.o \
	cmds.o casetab.o casefiddle.o indent.o search.o regex.o undo.o \
	alloc.o data.o doc.o editfns.o callint.o \
	eval.o floatfns.o fns.o print.o lread.o \
	abbrev.o syntax.o mocklisp.o bytecode.o \
	process.o callproc.o \
	doprnt.o

lispdir = ..\lisp

#
# These are the lisp files that are loaded up in loadup.el
#
lisp= \
	$(lispdir)\abbrev.elc \
	$(lispdir)\buff-menu.elc \
	$(lispdir)\byte-run.elc \
	$(lispdir)\c-mode.elc \
	$(lispdir)\files.elc \
	$(lispdir)\fill.elc \
	$(lispdir)\float-sup.elc \
	$(lispdir)\frame.elc \
	$(lispdir)\help.elc \
	$(lispdir)\indent.elc \
	$(lispdir)\isearch.elc \
	$(lispdir)\lisp-mode.elc \
	$(lispdir)\lisp.elc \
	$(lispdir)\loaddefs.el \
	$(lispdir)\map-ynp.elc \
	$(lispdir)\mouse.elc \
	$(lispdir)\page.elc \
	$(lispdir)\paragraphs.elc \
	$(lispdir)\paths.elc \
	$(lispdir)\register.elc \
	$(lispdir)\replace.elc \
	$(lispdir)\scroll-bar.elc \
	$(lispdir)\select.elc \
	$(lispdir)\simple.elc \
	$(lispdir)\startup.elc \
	$(lispdir)\subr.elc \
	$(lispdir)\text-mode.elc \
	$(lispdir)\vc-hooks.elc \
	$(lispdir)\winnt-patch.elc \
	$(lispdir)\window.elc

# only do the .c files until we get the docfile stuff fully working
DOC	      = DOC
$(DOC):
		rm -f $(DOC)
		$(BLD)\make-docfile -d ..\src $(obj) > $(DOC)
		$(BLD)\make-docfile -d ..\src $(lisp) >> $(DOC)


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

{$(BLD)}.obj{$(BLD)}.exe:
	@- 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
	@- link32 -out:$@ -debug:PARTIAL -machine:mips -subsystem:console -entry:mainCRTStartup $*.obj $(LIBS)

.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"


{$(BLD)}.obj{$(BLD)}.exe:
	@- 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
	@- link32 -out:$@ -debug:PARTIAL -machine:alpha -subsystem:console -entry:mainCRTStartup $*.obj $(LIBS)

.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

{$(BLD)}.obj{$(BLD)}.exe:
	link32 -out:$@ -debug:PARTIAL -machine:i386 -align:0x1000 -subsystem:console -entry:mainCRTStartup $*.obj $(LIBS)

.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 executables
#
all:		$(ALL) $(DOC)

#
# Assuming INSTALL_DIR is defined, build and install emacs in it.
# Only install etags, ctags, and the DOC file.
#
CP 	      = xcopy /fr
INSTALL_FILES = $(BLD)\etags.exe $(BLD)\ctags.exe
install:	$(INSTALL_FILES)
		- mkdir $(INSTALL_DIR)\bin
		$(CP) $(BLD)\etags.exe $(INSTALL_DIR)\bin
		$(CP) $(BLD)\ctags.exe $(INSTALL_DIR)\bin
		- mkdir $(INSTALL_DIR)\data
		$(CP) $(DOC) $(INSTALL_DIR)\data

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