1#  -*- Makefile -*- definition file for building GNU Emacs on Windows NT.
2#  Copyright (C) 2000, 2001, 2002, 2003, 2004,
3#    2005, 2006, 2007 Free Software Foundation, Inc.
4#
5#  GNU Emacs is free software; you can redistribute it and/or modify
6#  it under the terms of the GNU General Public License as published by
7#  the Free Software Foundation; either version 2, or (at your option)
8#  any later version.
9#
10#  GNU Emacs is distributed in the hope that it will be useful,
11#  but WITHOUT ANY WARRANTY; without even the implied warranty of
12#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#  GNU General Public License for more details.
14#
15#  You should have received a copy of the GNU General Public License
16#  along with GNU Emacs; see the file COPYING.  If not, write to
17#  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18#  Boston, MA 02110-1301, USA.
19
20# Ensure 'all' is the default target
21all:
22
23# NOTES
24#
25# I tried to force gmake to use the native shell for simplicity, by
26# setting SHELL as below, but this didn't work reliably because of
27# various case sensitivity niggles.  Specifically, COMSPEC (which is in
28# fact usually spelled ComSpec on NT, to make life difficult) typically
29# references "cmd.exe" (on NT) when the file is actually called
30# "CMD.EXE" on disk for hysterical raisons.  As a result, GNU make
31# thinks it doesn't exist (unless compiled with a switch to ignore
32# case), and so doesn't change which shell it will invoke to execute
33# commands.
34#
35# It would be possible, though very tedious using just gmake facilities,
36# to convert the COMSPEC value to uppercase to solve this problem, but
37# it isn't worth it.  That is partly because, even when using the native
38# shell, gmake tends to not be happy with backslashes in command
39# strings.  The obvious solution is to use forward slashes as much as
40# possible, which can be made to work most of the time (putting
41# filenames in quotes often helps), but there are still some internal
42# cmd.exe commands like `del' and `copy' that won't work with them.
43# Although it is possible to convert slashes to backslashes when
44# necessary, gmake requires explicitly calling its subst function, which
45# nmake does not understand).  For this reason, it is simplest to
46# mandate that rm and cp be available, so we can use Unix-format file
47# names everywhere.  (Fortunately both MS and GNU make, and the
48# respective compilers, are happy with Unix-format names.)
49#
50# Since we cannot easily force the choice of a particular shell, we must
51# make the effort to cope with whichever shell is being used.
52# Fortunately, the only command we need to use that is shell specific is
53# the testing of a file's existence for the purpose of working out when
54# we are copying files to their original location.  That particular
55# requirement is abstracted easily enough.
56#
57# The only other problem area was the change of directory when running
58# temacs to dump emacs.exe (where gmake doesn't support cd foo in any
59# useful way), but that has been resolved by modifying the Windows
60# unexec function slightly to not require the directory change while
61# still allowing objects and binaries to be in subdirectories.
62
63# This doesn't work.
64#SHELL:=$(COMSPEC)
65
66# Determine whether make is using sh or cmd/command as shell; cmd.exe
67# will output "ECHO is on" when echo is given by itself, while sh will
68# not produce any output.
69sh_output := $(shell echo)
70ifeq "$(findstring ECHO, $(sh_output))" "ECHO"
71THE_SHELL = $(COMSPEC)$(ComSpec)
72SHELLTYPE=CMD
73else
74USING_SH = 1
75THE_SHELL = $(SHELL)
76SHELLTYPE=SH
77endif
78
79MAKETYPE=gmake
80
81# The following "ifeq" does not appear to DTRT, and therefore breaks
82# the build on mingw32. Also the -m option does not exist in many
83# (reasonably recent even) versions of Cygwin. These issues need to be
84# remedied before putting this cygpath kludge back in.
85
86# Convert CURDIR to native file name, if in Cygwin format
87#ifeq "$(shell cygpath $(CURDIR))" "$(CURDIR)"
88#CURDIR	        := $(shell cygpath -m $(CURDIR))
89#endif
90
91THISDIR		= .
92
93# Cygwin has changed quoting rules somewhat since b20, in a way that
94# affects makefiles using sh as the command processor, so we need to
95# detect which rules to use.
96ifdef USING_SH
97sh_output := $(shell echo [Please ignore a syntax error on the next line - it is intentional] 1>&2)
98sh_output := $(shell echo foo")
99ifeq "$(sh_output)" ""
100NEW_CYGWIN = 1
101endif
102endif
103
104ALL_DEPS	= $^
105EMPTY =
106SPACE = $(EMPTY) $(EMPTY)
107
108SUBSYSTEM_WINDOWS=-Wl,-subsystem,windows
109SUBSYSTEM_CONSOLE=-Wl,-subsystem,console
110
111# INSTALL_DIR is the directory into which emacs will be installed.
112#
113ifndef INSTALL_DIR
114INSTALL_DIR     = $(CURDIR)/..
115endif
116
117export EMACSLOADPATH
118
119# Determine the architecture we're running on.
120# Define ARCH for our purposes;
121# Define CPU for use by ntwin32.mak;
122# Define CONFIG_H to the appropriate config.h for the system;
123#
124ifdef PROCESSOR_ARCHITECTURE
125# We're on Windows NT
126CPU		= $(PROCESSOR_ARCHITECTURE)
127CONFIG_H	= config.nt
128OS_TYPE		= windowsnt
129 ifeq "$(PROCESSOR_ARCHITECTURE)" "x86"
130ARCH		= i386
131CPU		= i386
132 else
133  ifeq "$(PROCESSOR_ARCHITECTURE)" "MIPS"
134ARCH		= mips
135  else
136   ifeq "$(PROCESSOR_ARCHITECTURE)" "ALPHA"
137ARCH		= alpha
138   else
139    ifeq "$(PROCESSOR_ARCHITECTURE)" "PPC"
140ARCH		= ppc
141    else
142error Unknown architecture type "$(PROCESSOR_ARCHITECTURE)"
143    endif
144   endif
145  endif
146 endif
147else
148# We're on Windows 95
149ARCH		= i386
150CPU		= i386
151CONFIG_H	= config.nt
152OS_TYPE		= windows95
153endif
154
155AR		= ar -rsc
156AR_OUT		=
157CC		= gcc
158CC_OUT		= -o$(SPACE)
159LINK		= gcc
160LINK_OUT	= -o$(SPACE)
161RC		= windres -O coff
162RC_OUT		= -o$(SPACE)
163RC_INCLUDE	= --include-dir$(SPACE)
164
165libc		=
166baselibs	=
167O		= o
168A		= a
169
170BASE_LIBS	= $(libc) $(baselibs)
171
172ADVAPI32	= -ladvapi32
173COMDLG32	= -lcomdlg32
174GDI32		= -lgdi32
175MPR		= -lmpr
176SHELL32		= -lshell32
177USER32		= -luser32
178WSOCK32		= -lwsock32
179WINMM     = -lwinmm
180WINSPOOL	= -lwinspool
181
182ifdef NOOPT
183DEBUG_CFLAGS	= -DEMACSDEBUG
184else
185DEBUG_CFLAGS	=
186endif
187CFLAGS          = -I. -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0400 $(ARCH_CFLAGS) -D$(ARCH) \
188		  -D_CRTAPI1=_cdecl \
189		  $(DEBUG_CFLAGS) $(USER_CFLAGS) $(LOCAL_FLAGS)
190EMACS_EXTRA_C_FLAGS = -DUSE_CRT_DLL=1
191
192# see comments in allocate_heap in w32heap.c before changing any of the
193# -stack, -heap, or -image-base settings.
194TEMACS_EXTRA_LINK = -Wl,-stack,0x00800000 -Wl,-heap,0x00100000 -Wl,-image-base,0x01000000 $(SUBSYSTEM_CONSOLE) -Wl,-entry,__start -Wl,-Map,$(BLD)/temacs.map
195
196ifdef NOOPT
197OBJDIR          = oo
198else
199OBJDIR          = oo-spd
200endif
201$(OBJDIR):;	-mkdir "$(OBJDIR)"
202BLD             = $(OBJDIR)/$(ARCH)
203stamp_BLD:      $(OBJDIR)
204		-mkdir "$(BLD)"
205		echo $(BLD) > $@
206
207COMPILER_TEMP_FILES =
208
209CP		= cp -f
210CP_DIR		= cp -rf
211DEL		= rm
212DEL_TREE	= rm -r
213
214ifdef USING_SH
215
216IFNOTSAMEDIR	= if [ ! -s ../same-dir.tst ] ; then
217FOREACH		= for f in
218FORVAR		= $${f}
219FORDO		= ; do
220ENDFOR		= ; done
221ENDIF		= ; fi
222ARGQUOTE	= '
223ifdef NEW_CYGWIN
224DQUOTE		= "
225else
226DQUOTE		= ""
227endif
228
229else
230
231IFNOTSAMEDIR	= if not exist ../same-dir.tst
232FOREACH		= for %%f in (
233FORVAR		= %%f
234FORDO		= ) do
235ENDFOR		=
236ENDIF		=
237ARGQUOTE	= "
238DQUOTE		= \"
239
240endif
241
242ifdef NODEBUG
243DEBUG_FLAG =
244DEBUG_LINK =
245else
246DEBUG_FLAG = -gstabs+ -g3
247DEBUG_LINK = -gstabs+ -g3
248endif
249
250ifdef NOCYGWIN
251NOCYGWIN = -mno-cygwin
252endif
253
254ifeq "$(ARCH)" "i386"
255ifdef NOOPT
256ARCH_CFLAGS     = -D_X86_=1 -c $(DEBUG_FLAG) $(NOCYGWIN)
257else
258ARCH_CFLAGS     = -D_X86_=1 -c $(DEBUG_FLAG) $(NOCYGWIN) $(MCPU_FLAG) -O2 \
259		  # -fbuiltin \
260		  # -finline-functions \
261		  # -fomit-frame-pointer
262endif
263ARCH_LDFLAGS	= $(SYS_LDFLAGS)
264else
265ERROR Unknown architecture type "$(ARCH)".
266endif
267
268LINK_FLAGS	= $(ARCH_LDFLAGS) $(DEBUG_LINK) $(NOCYGWIN) $(USER_LDFLAGS)
269
270export XMFLAGS
271
272.DEFAULT:
273
274$(BLD)/%.o: %.c
275		$(CC) $(CFLAGS) $(CC_OUT)$@ $<
276
277# arch-tag: 35eb9662-8534-4bcf-b891-0730a09d657f
278