Skip to content

Commit 4bf0103

Browse files
author
H. Peter Anvin
committed
Makefiles: try to fix compiling with MSVC/nmake
Try to address Makefile portability bugs affecting MSVC/nmake. Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 309990f commit 4bf0103

File tree

3 files changed

+149
-135
lines changed

3 files changed

+149
-135
lines changed

Makefile.in

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ PERL = perl
4343
PERLFLAGS = -I$(top_srcdir)/perllib -I$(srcdir)
4444
RUNPERL = $(PERL) $(PERLFLAGS)
4545

46+
EMPTY = : >
47+
4648
PYTHON3 = python3
4749

4850
INSTALL = @INSTALL@
@@ -157,6 +159,7 @@ LIBOBJ_NW = stdlib/snprintf.$(O) stdlib/vsnprintf.$(O) stdlib/strlcpy.$(O) \
157159

158160
# Warnings depend on all source files, so handle them separately
159161
WARNOBJ = asm/warnings.$(O)
162+
WARNFILES = asm/warnings_c.h include/warnings.h doc/warnings.src
160163

161164
LIBOBJ = $(LIBOBJ_NW) $(WARNOBJ)
162165
ALLOBJ_NW = $(PROGOBJ) $(LIBOBJ_NW)
@@ -186,6 +189,10 @@ nasm$(X): $(NASM) $(MANIFEST) $(NASMLIB)
186189
ndisasm$(X): $(NDISASM) $(MANIFEST) $(NASMLIB)
187190
$(CC) $(ALL_LDFLAGS) -o ndisasm$(X) $^ $(LIBS)
188191

192+
# These are specific to certain Makefile syntaxes...
193+
WARNTIMES = $(WARNFILES:=.time)
194+
WARNSRCS = $(LIBOBJ_NW:.$(O)=.c)
195+
189196
#-- Begin Generated File Rules --#
190197

191198
# These source files are automagically generated from data files using
@@ -279,33 +286,31 @@ x86/regs.h: x86/regs.dat x86/regs.pl
279286
# reasonable, but doesn't update the time stamp if the files aren't
280287
# changed, to avoid rebuilding everything every time. Track the actual
281288
# dependency by the empty file asm/warnings.time.
282-
WARNFILES = asm/warnings_c.h include/warnings.h doc/warnings.src
283-
284289
warnings:
285-
$(RM_F) $(WARNFILES) $(WARNFILES:=.time)
290+
$(RM_F) $(WARNFILES) $(WARNTIMES)
286291
$(MAKE) asm/warnings.time
287292

288293
asm/warnings.time: $(ALLOBJ_NW:.$(O)=.c)
289-
: > asm/warnings.time
290-
$(MAKE) $(WARNFILES:=.time)
294+
$(EMPTY) asm/warnings.time
295+
$(MAKE) $(WARNTIMES)
291296

292297
asm/warnings_c.h.time: asm/warnings.pl asm/warnings.time
293298
$(RUNPERL) $(srcdir)/asm/warnings.pl c asm/warnings_c.h $(srcdir)
294-
: > asm/warnings_c.h.time
299+
$(EMPTY) asm/warnings_c.h.time
295300

296301
asm/warnings_c.h: asm/warnings_c.h.time
297302
@: Side effect
298303

299304
include/warnings.h.time: asm/warnings.pl asm/warnings.time
300305
$(RUNPERL) $(srcdir)/asm/warnings.pl h include/warnings.h $(srcdir)
301-
: > include/warnings.h.time
306+
$(EMPTY) include/warnings.h.time
302307

303308
include/warnings.h: include/warnings.h.time
304309
@: Side effect
305310

306311
doc/warnings.src.time: asm/warnings.pl asm/warnings.time
307312
$(RUNPERL) $(srcdir)/asm/warnings.pl doc doc/warnings.src $(srcdir)
308-
: > doc/warnings.src.time
313+
$(EMPTY) doc/warnings.src.time
309314

310315
doc/warnings.src : doc/warnings.src.time
311316
@: Side effect

Mkfiles/msvc.mak

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ MANIFEST_FLAGS = /MANIFEST:EMBED /MANIFESTFILE:$(MANIFEST)
2222

2323
!IF "$(DEBUG)" == "1"
2424
CFLAGS = /Od /Zi
25-
LDFLAGS = /DEBUG $(MANIFEST_FLAGS)
25+
LDFLAGS = /DEBUG
2626
!ELSE
2727
CFLAGS = /O2 /Zi
2828
# /OPT:REF and /OPT:ICF two undo /DEBUG harm
29-
LDFLAGS = /DEBUG /OPT:REF /OPT:ICF $(MANIFEST_FLAGS)
29+
LDFLAGS = /DEBUG /OPT:REF /OPT:ICF
3030
!ENDIF
3131

3232
CC = cl
3333
AR = lib
34-
CFLAGS = $(CFLAGS) /W2
35-
BUILD_CFLAGS = $(CFLAGS)
34+
BUILD_CFLAGS = $(CFLAGS) /W2
3635
INTERNAL_CFLAGS = /I$(srcdir) /I. \
3736
/I$(srcdir)/include /I./include \
3837
/I$(srcdir)/x86 /I./x86 \
3938
/I$(srcdir)/asm /I./asm \
4039
/I$(srcdir)/disasm /I./disasm \
4140
/I$(srcdir)/output /I./output
4241
ALL_CFLAGS = $(BUILD_CFLAGS) $(INTERNAL_CFLAGS)
43-
LDFLAGS = /link $(LINKFLAGS) /SUBSYSTEM:CONSOLE /RELEASE
42+
MANIFEST_FLAGS = /MANIFEST:EMBED /MANIFESTINPUT:$(MANIFEST)
43+
ALL_LDFLAGS = /link $(LDFLAGS) $(MANIFEST_FLAGS) /SUBSYSTEM:CONSOLE /RELEASE
4444
LIBS =
4545

4646
PERL = perl
@@ -57,7 +57,7 @@ O = obj
5757
A = lib
5858
X = .exe
5959
.SUFFIXES:
60-
.SUFFIXES: $(X) .$(A) .$(O) .c .i .s .1 .man
60+
.SUFFIXES: $(X) .$(A) .obj .c .i .s .1 .man
6161

6262
.c.obj:
6363
$(CC) /c $(ALL_CFLAGS) /Fo$@ $<
@@ -66,61 +66,62 @@ MANIFEST = win/manifest.xml
6666

6767
#-- Begin File Lists --#
6868
# Edit in Makefile.in, not here!
69-
NASM = asm\nasm.$(O)
70-
NDISASM = disasm\ndisasm.$(O)
69+
NASM = asm\nasm.obj
70+
NDISASM = disasm\ndisasm.obj
7171

7272
PROGOBJ = $(NASM) $(NDISASM)
7373
PROGS = nasm$(X) ndisasm$(X)
7474

75-
LIBOBJ_NW = stdlib\snprintf.$(O) stdlib\vsnprintf.$(O) stdlib\strlcpy.$(O) \
76-
stdlib\strnlen.$(O) stdlib\strrchrnul.$(O) \
75+
LIBOBJ_NW = stdlib\snprintf.obj stdlib\vsnprintf.obj stdlib\strlcpy.obj \
76+
stdlib\strnlen.obj stdlib\strrchrnul.obj \
7777
\
78-
nasmlib\ver.$(O) \
79-
nasmlib\alloc.$(O) nasmlib\asprintf.$(O) nasmlib\errfile.$(O) \
80-
nasmlib\crc32.$(O) nasmlib\crc64.$(O) nasmlib\md5c.$(O) \
81-
nasmlib\string.$(O) nasmlib\nctype.$(O) \
82-
nasmlib\file.$(O) nasmlib\mmap.$(O) nasmlib\ilog2.$(O) \
83-
nasmlib\realpath.$(O) nasmlib\path.$(O) \
84-
nasmlib\filename.$(O) nasmlib\rlimit.$(O) \
85-
nasmlib\readnum.$(O) nasmlib\numstr.$(O) \
86-
nasmlib\zerobuf.$(O) nasmlib\bsi.$(O) \
87-
nasmlib\rbtree.$(O) nasmlib\hashtbl.$(O) \
88-
nasmlib\raa.$(O) nasmlib\saa.$(O) \
89-
nasmlib\strlist.$(O) \
90-
nasmlib\perfhash.$(O) nasmlib\badenum.$(O) \
78+
nasmlib\ver.obj \
79+
nasmlib\alloc.obj nasmlib\asprintf.obj nasmlib\errfile.obj \
80+
nasmlib\crc32.obj nasmlib\crc64.obj nasmlib\md5c.obj \
81+
nasmlib\string.obj nasmlib\nctype.obj \
82+
nasmlib\file.obj nasmlib\mmap.obj nasmlib\ilog2.obj \
83+
nasmlib\realpath.obj nasmlib\path.obj \
84+
nasmlib\filename.obj nasmlib\rlimit.obj \
85+
nasmlib\readnum.obj nasmlib\numstr.obj \
86+
nasmlib\zerobuf.obj nasmlib\bsi.obj \
87+
nasmlib\rbtree.obj nasmlib\hashtbl.obj \
88+
nasmlib\raa.obj nasmlib\saa.obj \
89+
nasmlib\strlist.obj \
90+
nasmlib\perfhash.obj nasmlib\badenum.obj \
9191
\
92-
common\common.$(O) \
92+
common\common.obj \
9393
\
94-
x86\insnsa.$(O) x86\insnsb.$(O) x86\insnsd.$(O) x86\insnsn.$(O) \
95-
x86\regs.$(O) x86\regvals.$(O) x86\regflags.$(O) x86\regdis.$(O) \
96-
x86\disp8.$(O) x86\iflag.$(O) \
94+
x86\insnsa.obj x86\insnsb.obj x86\insnsd.obj x86\insnsn.obj \
95+
x86\regs.obj x86\regvals.obj x86\regflags.obj x86\regdis.obj \
96+
x86\disp8.obj x86\iflag.obj \
9797
\
98-
asm\error.$(O) \
99-
asm\floats.$(O) \
100-
asm\directiv.$(O) asm\directbl.$(O) \
101-
asm\pragma.$(O) \
102-
asm\assemble.$(O) asm\labels.$(O) asm\parser.$(O) \
103-
asm\preproc.$(O) asm\quote.$(O) asm\pptok.$(O) \
104-
asm\listing.$(O) asm\eval.$(O) asm\exprlib.$(O) asm\exprdump.$(O) \
105-
asm\stdscan.$(O) \
106-
asm\strfunc.$(O) asm\tokhash.$(O) \
107-
asm\segalloc.$(O) \
108-
asm\rdstrnum.$(O) \
109-
asm\srcfile.$(O) \
110-
macros\macros.$(O) \
98+
asm\error.obj \
99+
asm\floats.obj \
100+
asm\directiv.obj asm\directbl.obj \
101+
asm\pragma.obj \
102+
asm\assemble.obj asm\labels.obj asm\parser.obj \
103+
asm\preproc.obj asm\quote.obj asm\pptok.obj \
104+
asm\listing.obj asm\eval.obj asm\exprlib.obj asm\exprdump.obj \
105+
asm\stdscan.obj \
106+
asm\strfunc.obj asm\tokhash.obj \
107+
asm\segalloc.obj \
108+
asm\rdstrnum.obj \
109+
asm\srcfile.obj \
110+
macros\macros.obj \
111111
\
112-
output\outform.$(O) output\outlib.$(O) output\legacy.$(O) \
113-
output\nulldbg.$(O) output\nullout.$(O) \
114-
output\outbin.$(O) output\outaout.$(O) output\outcoff.$(O) \
115-
output\outelf.$(O) \
116-
output\outobj.$(O) output\outas86.$(O) \
117-
output\outdbg.$(O) output\outieee.$(O) output\outmacho.$(O) \
118-
output\codeview.$(O) \
112+
output\outform.obj output\outlib.obj output\legacy.obj \
113+
output\nulldbg.obj output\nullout.obj \
114+
output\outbin.obj output\outaout.obj output\outcoff.obj \
115+
output\outelf.obj \
116+
output\outobj.obj output\outas86.obj \
117+
output\outdbg.obj output\outieee.obj output\outmacho.obj \
118+
output\codeview.obj \
119119
\
120-
disasm\disasm.$(O) disasm\sync.$(O)
120+
disasm\disasm.obj disasm\sync.obj
121121

122122
# Warnings depend on all source files, so handle them separately
123-
WARNOBJ = asm\warnings.$(O)
123+
WARNOBJ = asm\warnings.obj
124+
WARNFILES = asm\warnings_c.h include\warnings.h doc\warnings.src
124125

125126
LIBOBJ = $(LIBOBJ_NW) $(WARNOBJ)
126127
ALLOBJ_NW = $(PROGOBJ) $(LIBOBJ_NW)
@@ -136,14 +137,18 @@ NASMLIB = libnasm.$(A)
136137
all: nasm$(X) ndisasm$(X)
137138

138139
nasm$(X): $(NASM) $(MANIFEST) $(NASMLIB)
139-
$(CC) /Fe$@ $(NASM) $(LDFLAGS) $(NASMLIB) $(LIBS)
140+
$(CC) /Fe$@ $(NASM) $(ALL_LDFLAGS) $(NASMLIB) $(LIBS)
140141

141142
ndisasm$(X): $(NDISASM) $(MANIFEST) $(NASMLIB)
142-
$(CC) /Fe$@ $(NDISASM) $(LDFLAGS) $(NASMLIB) $(LIBS)
143+
$(CC) /Fe$@ $(NDISASM) $(ALL_LDFLAGS) $(NASMLIB) $(LIBS)
143144

144145
$(NASMLIB): $(LIBOBJ)
145146
$(AR) $(ARFLAGS) /OUT:$@ $**
146147

148+
# These are specific to certain Makefile syntaxes...
149+
WARNTIMES = $(patsubst %,%.time,$(WARNFILES))
150+
WARNSRCS = $(patsubst %.obj,%.c,$(LIBOBJ_NW))
151+
147152
#-- Begin Generated File Rules --#
148153
# Edit in Makefile.in, not here!
149154

@@ -238,33 +243,31 @@ x86\regs.h: x86\regs.dat x86\regs.pl
238243
# reasonable, but doesn't update the time stamp if the files aren't
239244
# changed, to avoid rebuilding everything every time. Track the actual
240245
# dependency by the empty file asm\warnings.time.
241-
WARNFILES = asm\warnings_c.h include\warnings.h doc\warnings.src
242-
243246
warnings:
244-
$(RM_F) $(WARNFILES) $(WARNFILES:=.time)
247+
$(RM_F) $(WARNFILES) $(WARNTIMES)
245248
$(MAKE) asm\warnings.time
246249

247250
asm\warnings.time: $(ALLOBJ_NW:.$(O)=.c)
248-
: > asm\warnings.time
249-
$(MAKE) $(WARNFILES:=.time)
251+
$(EMPTY) asm\warnings.time
252+
$(MAKE) $(WARNTIMES)
250253

251254
asm\warnings_c.h.time: asm\warnings.pl asm\warnings.time
252255
$(RUNPERL) $(srcdir)\asm\warnings.pl c asm\warnings_c.h $(srcdir)
253-
: > asm\warnings_c.h.time
256+
$(EMPTY) asm\warnings_c.h.time
254257

255258
asm\warnings_c.h: asm\warnings_c.h.time
256259
@: Side effect
257260

258261
include\warnings.h.time: asm\warnings.pl asm\warnings.time
259262
$(RUNPERL) $(srcdir)\asm\warnings.pl h include\warnings.h $(srcdir)
260-
: > include\warnings.h.time
263+
$(EMPTY) include\warnings.h.time
261264

262265
include\warnings.h: include\warnings.h.time
263266
@: Side effect
264267

265268
doc\warnings.src.time: asm\warnings.pl asm\warnings.time
266269
$(RUNPERL) $(srcdir)\asm\warnings.pl doc doc\warnings.src $(srcdir)
267-
: > doc\warnings.src.time
270+
$(EMPTY) doc\warnings.src.time
268271

269272
doc\warnings.src : doc\warnings.src.time
270273
@: Side effect
@@ -326,7 +329,7 @@ nsis: nsis\nasm.nsi nsis\arch.nsh nsis\version.nsh
326329
#-- End NSIS Rules --#
327330

328331
clean:
329-
-del /f /s *.$(O)
332+
-del /f /s *.obj
330333
-del /f /s *.pdb
331334
-del /f /s *.s
332335
-del /f /s *.i
@@ -348,7 +351,7 @@ distclean: clean
348351
-del /f output\*.bak
349352
-del /f test\*.lst
350353
-del /f test\*.bin
351-
-del /f test\*.$(O)
354+
-del /f test\*.obj
352355
-del /f test\*.bin
353356
-del /f/s autom4te*.cache
354357

@@ -403,7 +406,7 @@ MKDEP=0
403406
!ENDIF
404407

405408
#-- Magic hints to mkdep.pl --#
406-
# @object-ending: ".$(O)"
409+
# @object-ending: ".obj"
407410
# @path-separator: "\"
408411
# @exclude: "config/config.h"
409412
# @external: "msvc.dep"

0 commit comments

Comments
 (0)