NT_MAKEFILE raw
1 # Makefile for Windows (Win32/64). Assumes Microsoft compiler.
2
3 # Should be invoked as `nmake -f NT_MAKEFILE [<args>]`; the optional arguments
4 # are:
5 # - `cpu=AMD64` to target x64;
6 # - `cpu=i386` to target x86;
7 # - `enable_static=1` to build it as a static library;
8 # - `nodebug=1` to produce the release variant of the library;
9 # - `disable_threads=1` to build the library without threads support.
10
11 cc = cl
12 link = link
13 rc = rc
14
15 !IF !DEFINED(CPU) || "$(CPU)" == ""
16 CPU = $(PROCESSOR_ARCHITECTURE)
17 !ENDIF
18 !IF "$(CPU)" == "I386" || "$(CPU)" == "X86" || "$(CPU)" == "x86"
19 CPU = i386
20 !ELSEIF "$(CPU)" == "X64" || "$(CPU)" == "x64" || "$(CPU)" == "amd64"
21 CPU = AMD64
22 !ENDIF
23
24 !IF !DEFINED(NMAKE_WINVER)
25 NMAKE_WINVER = 0x0600
26 !ENDIF
27
28 cflags = $(cflags) -c -DCRTAPI1=_cdecl -DCRTAPI2=_cdecl -GS -D_WINNT -W4
29 !IF "$(CPU)" == "i386"
30 cflags = $(cflags) -D_X86_=1 -DWIN32 -D_WIN32
31 !ELSEIF "$(CPU)" == "AMD64"
32 cflags = $(cflags) -D_AMD64_=1 -DWIN64 -D_WIN64 -DWIN32 -D_WIN32
33 !ENDIF
34 cflags = $(cflags) -D_WIN32_WINNT=$(NMAKE_WINVER) -DWINVER=$(NMAKE_WINVER)
35
36 !IFDEF NODEBUG
37 cvarsmt = -D_MT -MT
38 cdebug = -Ox -DNDEBUG
39 rcvars = -DWIN32 -D_WIN32 -DWINVER=$(NMAKE_WINVER)
40 ldebug = /RELEASE
41 !ELSE
42 cvarsmt = -D_MT -MTd
43 cdebug = -Zi -Od -DDEBUG
44 rcvars = -DWIN32 -D_WIN32 -DWINVER=$(NMAKE_WINVER) -DDEBUG -D_DEBUG
45 ldebug = /DEBUG /DEBUGTYPE:cv
46 !ENDIF
47
48 !IF "$(CPU)" == "i386"
49 CVTRES_CPU=X86
50 !ELSEIF "$(CPU)" == "AMD64"
51 CVTRES_CPU=X64
52 !ENDIF
53
54 !IFNDEF NODEBUG
55 CFLAGS_DEBUG=-DGC_ASSERTIONS
56 !ENDIF
57
58 !IFDEF ENABLE_STATIC
59 CFLAGS_GCDLL=-DGC_NOT_DLL
60 CORDFLAG=
61 !ELSE
62 CFLAGS_GCDLL=-DGC_DLL
63 # `cord.dll` file and its clients should not link C library statically
64 # otherwise `FILE`-related functions might not work (because own set of
65 # opened `FILE` instances is maintained by each copy of the C library thus
66 # making impossible to pass `FILE` pointer from `.exe` code to `.dll` code).
67 cvarsmt=
68 !IFDEF NODEBUG
69 CORDFLAG=-MD
70 !ELSE
71 CORDFLAG=-MDd
72 !ENDIF
73 !ENDIF
74
75 !IFNDEF DISABLE_THREADS
76 CFLAGS_MT=$(cvarsmt) -DGC_THREADS -DTHREAD_LOCAL_ALLOC -DPARALLEL_MARK
77 !ENDIF
78
79 # Extra user-defined flags to pass both to C and C++ compilers.
80 CFLAGS_EXTRA=
81
82 CFLAGS_SPECIFIC=$(CFLAGS_DEBUG) $(CFLAGS_GCDLL) $(CFLAGS_MT)
83
84 CFLAGS_DEFAULT=-DALL_INTERIOR_POINTERS -DENABLE_DISCLAIM -DGC_ATOMIC_UNCOLLECTABLE -DGC_GCJ_SUPPORT -DJAVA_FINALIZATION -DNO_EXECUTE_PERMISSION -DGC_REQUIRE_WCSDUP -DUSE_MUNMAP
85
86 CXXFLAGS_SPECIFIC=/EHsc
87
88 # Make sure that `.cc` is not viewed as a suffix. It is for VC++2005, but
89 # not earlier versions. We can deal with either, but not inconsistency.
90 .SUFFIXES:
91 .SUFFIXES: .obj .cpp .c
92
93 # Atomic_ops installation directory. For Win32, the source directory
94 # should do, since we only need the headers.
95 # We assume this was manually unpacked.
96 AO_SRC_DIR=libatomic_ops/src
97 AO_INCLUDE_DIR=$(AO_SRC_DIR)
98
99 !IFDEF ENABLE_STATIC
100 # `pthread_start.obj` file is needed just in case client defines
101 # `GC_WIN32_PTHREADS` macro.
102 OBJS= allchblk.obj alloc.obj blacklst.obj dbg_mlc.obj dyn_load.obj finalize.obj fnlz_mlc.obj gcj_mlc.obj headers.obj mach_dep.obj malloc.obj mallocx.obj mark.obj mark_rts.obj misc.obj new_hblk.obj os_dep.obj pthread_start.obj pthread_support.obj ptr_chck.obj reclaim.obj thread_local_alloc.obj typd_mlc.obj win32_threads.obj extra\msvc_dbg.obj
103 !ELSE
104 OBJS= extra\gc.obj extra\msvc_dbg.obj
105 !ENDIF
106
107 COBJS= cord\cordbscs.obj cord\cordprnt.obj cord\cordxtra.obj
108
109 all: gc.lib cord.lib gccpp.lib gctba.lib
110
111 check-deps: gctest.exe cpptest.exe treetest.exe cordtest.exe de.exe
112
113 check: check-deps
114 gctest.exe
115 cordtest.exe
116 cpptest.exe
117 treetest.exe
118
119 .c.obj:
120 $(cc) $(cdebug) $(cflags) $(CFLAGS_SPECIFIC) $(CORDFLAG) -Iinclude -I$(AO_INCLUDE_DIR) $(CFLAGS_DEFAULT) -D_CRT_SECURE_NO_DEPRECATE $(CFLAGS_EXTRA) $*.c /Fo$*.obj /wd4127 /wd4701
121 # Disable `crt` security warnings, since unfortunately they warn about all
122 # sorts of safe uses of `strncpy`. It would be nice to leave the rest enabled.
123
124 .cpp.obj:
125 $(cc) $(cdebug) $(cflags) $(CFLAGS_SPECIFIC) -Iinclude $(CFLAGS_DEFAULT) $(CXXFLAGS_SPECIFIC) -D_CRT_SECURE_NO_DEPRECATE $(CFLAGS_EXTRA) $*.cpp /Fo$*.obj
126
127 $(OBJS) tests\gctest.obj: include\private\gc_priv.h include\private\gc_hdrs.h include\gc\gc.h include\private\gcconfig.h include\private\gc_locks.h include\private\gc_pmark.h include\gc\gc_mark.h include\gc\gc_disclaim.h
128
129 !IFDEF ENABLE_STATIC
130
131 gc.lib: $(OBJS)
132 lib /out:gc.lib /MACHINE:$(CPU) $(OBJS)
133
134 cord.lib: $(COBJS)
135 lib /out:cord.lib /MACHINE:$(CPU) $(COBJS)
136
137 gccpp.lib: gc_badalc.obj gc_cpp.obj
138 lib /out:gccpp.lib /MACHINE:$(CPU) gc_badalc.obj gc_cpp.obj
139
140 # The same as `gccpp.lib` file but contains only `gc_badalc.obj` file.
141 gctba.lib: gc_badalc.obj
142 lib /out:gctba.lib /MACHINE:$(CPU) gc_badalc.obj
143
144 !ELSE
145
146 gc.lib: $(OBJS)
147 $(link) $(ldebug) kernel32.lib user32.lib /subsystem:windows /dll /INCREMENTAL:NO /pdb:"gc.pdb" /out:gc.dll /implib:gc.lib /MACHINE:$(CPU) $(OBJS)
148
149 cord.lib: $(COBJS) gc.lib
150 $(link) $(ldebug) gc.lib /subsystem:windows /dll /INCREMENTAL:NO /pdb:"cord.pdb" /out:cord.dll /implib:cord.lib /MACHINE:$(CPU) $(COBJS)
151
152 gccpp.lib: gc_badalc.obj gc_cpp.obj gc.lib
153 $(link) $(ldebug) gc.lib /subsystem:windows /dll /INCREMENTAL:NO /pdb:"gccpp.pdb" /out:gccpp.dll /implib:gccpp.lib /MACHINE:$(CPU) gc_badalc.obj gc_cpp.obj
154
155 gctba.lib: gc_badalc.obj gc.lib
156 $(link) $(ldebug) gc.lib /subsystem:windows /dll /INCREMENTAL:NO /pdb:"gctba.pdb" /out:gctba.dll /implib:gctba.lib /MACHINE:$(CPU) gc_badalc.obj
157
158 !ENDIF
159
160 gctest.exe: gc.lib tests\gctest.obj
161 $(link) /MACHINE:$(CPU) /INCREMENTAL:NO $(ldebug) $(lflags) user32.lib -out:$*.exe tests\gctest.obj gc.lib
162 # `mapsympe -n -o gctest.sym gctest.exe`
163 # This produces a GUI application that opens no window and writes
164 # to `gctest.gc.log` file.
165
166 cord\tests\de_win.rbj: cord\tests\de_win.res
167 cvtres /MACHINE:$(CVTRES_CPU) /OUT:cord\tests\de_win.rbj cord\tests\de_win.res
168
169 cord\tests\de.obj cord\tests\de_win.obj: include\gc\cord.h include\gc\cord_pos.h cord\tests\de_win.h cord\tests\de_cmds.h
170
171 cord\tests\de_win.res: cord\tests\de_win.rc cord\tests\de_win.h cord\tests\de_cmds.h
172 $(rc) $(rcvars) -r -fo cord\tests\de_win.res cord\tests\de_win.rc
173
174 # `cord/de` is a real Windows GUI application.
175 de.exe: cord\tests\de.obj cord\tests\de_win.obj cord\tests\de_win.rbj gc.lib cord.lib
176 $(link) /MACHINE:$(CPU) /INCREMENTAL:NO $(ldebug) $(lflags) -out:de.exe cord\tests\de.obj cord\tests\de_win.obj cord\tests\de_win.rbj gc.lib cord.lib gdi32.lib user32.lib
177
178 cordtest.exe: cord\tests\cordtest.obj gc.lib cord.lib
179 $(link) /subsystem:console /MACHINE:$(CPU) /INCREMENTAL:NO $(ldebug) $(lflags) -out:cordtest.exe cord\tests\cordtest.obj gc.lib cord.lib user32.lib
180
181 gc_badalc.obj: gc_badalc.cc include\gc\gc_cpp.h include\gc\gc.h
182
183 gc_cpp.obj: gc_cpp.cc include\gc\gc_cpp.h include\gc\gc.h
184
185 test_cpp.cpp: tests\cpp.cc
186 copy tests\cpp.cc test_cpp.cpp
187
188 # This generates the C++ test executable. The executable expects
189 # a single numeric argument, which is the number of iterations.
190 # The output appears in `cpptest.gc.log` file.
191 cpptest.exe: test_cpp.obj include\gc\gc_cpp.h include\gc\gc_allocator.h include\gc\gc.h gc.lib gccpp.lib
192 $(link) /MACHINE:$(CPU) /INCREMENTAL:NO $(ldebug) $(lflags) user32.lib -out:cpptest.exe test_cpp.obj gc.lib gccpp.lib
193
194 test_tree.cpp: tests\tree.cc
195 copy tests\tree.cc test_tree.cpp
196
197 treetest.exe: test_tree.obj include\gc\gc_cpp.h include\gc\gc.h gc.lib gctba.lib
198 $(link) /MACHINE:$(CPU) /INCREMENTAL:NO $(ldebug) $(lflags) user32.lib -out:treetest.exe test_tree.obj gc.lib gctba.lib
199
200 $(AO_SRC_DIR):
201 tar xvfz $(AO_SRC_DIR).tar.gz
202
203 clean:
204 del *.dll *.exe *.exp *.lib *.log *.obj *.pdb cordtst*.tmp cord\*.obj cord\tests\*.rbj cord\tests\*.res cord\tests\*.obj extra\*.obj test_cpp.cpp test_tree.cpp tests\*.obj 2> nul
205