494be02cc8a4bd8b74c8c59aa04047bd90461150
[platform/upstream/make.git] / mk / Windows32.mk
1 # GNU -*-Makefile-*- to build GNU make on Windows
2 #
3 # Windows overrides for use with Basic.mk.
4 #
5 # Copyright (C) 2017-2020 Free Software Foundation, Inc.
6 # This file is part of GNU Make.
7 #
8 # GNU Make is free software; you can redistribute it and/or modify it under
9 # the terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 3 of the License, or (at your option) any later
11 # version.
12 #
13 # GNU Make is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16 # details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 # TARGET_TYPE can be either "release" or "debug"
22 TARGET_TYPE = release
23
24 # TOOLCHAIN can be either "msvc" or "gcc"
25 TOOLCHAIN = msvc
26
27 # Translate a POSIX path into a Windows path.  Don't bother with drives.
28 # Used only inside recipes, with DOS/CMD tools that require it.
29 P2W = $(subst /,\,$1)
30
31 prog_SOURCES += $(loadavg_SOURCES) $(glob_SOURCES) $(w32_SOURCES)
32
33 BUILT_SOURCES += $(lib)alloca.h $(lib)fnmatch.h $(lib)glob.h
34
35 w32_LIBS = kernel32 user32 gdi32 winspool comdlg32 advapi32 shell32 ole32 \
36            oleaut32 uuid odbc32 odbccp32
37
38 CPPFLAGS =
39 CFLAGS =
40 LDFLAGS =
41
42 # --- Visual Studio
43 msvc_CC = cl.exe
44 msvc_LD = link.exe
45
46 msvc_CPPFLAGS = /DHAVE_CONFIG_H /DWINDOWS32 /DWIN32 /D_CONSOLE
47 msvc_CPPFLAGS += /I$(OUTDIR)src /I$(SRCDIR)/src /I$(SRCDIR)/src/w32/include /I$(OUTDIR)lib /I$(SRCDIR)/lib
48
49 msvc_CFLAGS = /nologo /MT /W4 /EHsc
50 msvc_CFLAGS += /FR$(OUTDIR) /Fp$(BASE_PROG).pch /Fd$(BASE_PROG).pdb
51
52 msvc_LDFLAGS = /nologo /SUBSYSTEM:console /PDB:$(BASE_PROG).pdb
53
54 msvc_LDLIBS = $(addsuffix .lib,$(w32_LIBS))
55
56 msvc_C_SOURCE = /c
57 msvc_OUTPUT_OPTION = /Fo$@
58 msvc_LINK_OUTPUT = /OUT:$@
59
60 release_msvc_OUTDIR = ./WinRel/
61 release_msvc_CPPFLAGS = /D NDEBUG
62 release_msvc_CFLAGS = /O2
63
64 debug_msvc_OUTDIR = ./WinDebug/
65 debug_msvc_CPPFLAGS = /D _DEBUG
66 debug_msvc_CFLAGS = /Zi /Od
67 debug_msvc_LDFLAGS = /DEBUG
68
69 # --- GCC
70 gcc_CC = gcc
71 gcc_LD = $(gcc_CC)
72
73 release_gcc_OUTDIR = ./GccRel/
74 debug_gcc_OUTDIR = ./GccDebug/
75
76 gcc_CPPFLAGS = -DHAVE_CONFIG_H -I$(OUTDIR)src -I$(SRCDIR)/src -I$(SRCDIR)/src/w32/include -I$(OUTDIR)lib -I$(SRCDIR)/lib
77 gcc_CFLAGS = -mthreads -Wall -std=gnu99 -gdwarf-2 -g3
78 gcc_LDFLAGS = -mthreads -gdwarf-2 -g3
79 gcc_LDLIBS = $(addprefix -l,$(w32_libs))
80
81 gcc_C_SOURCE = -c
82 gcc_OUTPUT_OPTION = -o $@
83 gcc_LINK_OUTPUT = -o $@
84
85 debug_gcc_CFLAGS = -O0
86 release_gcc_CFLAGS = -O2
87
88 # ---
89
90 LINK.cmd = $(LD) $(extra_LDFLAGS) $(LDFLAGS) $(TARGET_ARCH) $1 $(LDLIBS) $(LINK_OUTPUT)
91
92 CHECK.cmd = cmd /c cd tests \& .\run_make_tests.bat -make ../$(PROG)
93
94 MKDIR.cmd = cmd /c mkdir $(call P2W,$1)
95 RM.cmd = cmd /c del /F /Q $(call P2W,$1)
96 CP.cmd = cmd /c copy /Y $(call P2W,$1 $2)
97
98 CC = $($(TOOLCHAIN)_CC)
99 LD = $($(TOOLCHAIN)_LD)
100
101 C_SOURCE = $($(TOOLCHAIN)_C_SOURCE)
102 OUTPUT_OPTION = $($(TOOLCHAIN)_OUTPUT_OPTION)
103 LINK_OUTPUT = $($(TOOLCHAIN)_LINK_OUTPUT)
104
105 OUTDIR = $($(TARGET_TYPE)_$(TOOLCHAIN)_OUTDIR)
106
107 OBJEXT  = obj
108 EXEEXT  = .exe
109
110 _CUSTOM = $($(TOOLCHAIN)_$1) $($(TARGET_TYPE)_$1) $($(TARGET_TYPE)_$(TOOLCHAIN)_$1)
111
112 # I'm not sure why this builds gnumake rather than make...?
113 PROG = $(OUTDIR)gnumake$(EXEEXT)
114 BASE_PROG = $(basename $(PROG))
115
116 extra_CPPFLAGS = $(call _CUSTOM,CPPFLAGS)
117 extra_CFLAGS = $(call _CUSTOM,CFLAGS)
118 extra_LDFLAGS = $(call _CUSTOM,LDFLAGS)
119 LDLIBS = $(call _CUSTOM,LDLIBS)
120
121 $(OUTDIR)src/config.h: $(SRCDIR)/src/config.h.W32
122         $(call CP.cmd,$<,$@)