output: macho -- Add support for N_PEXT in macho output
[nasm.git] / Mkfiles / msvc.mak
blob430fa2d37a0dfdb8bc288a32e7f6410d09bc14b3
1 # -*- makefile -*-
3 # Makefile for building NASM using Microsoft Visual C++ and NMAKE.
4 # Tested on Microsoft Visual C++ 2005 Express Edition.
6 # Make sure to put the appropriate directories in your PATH, in
7 # the case of MSVC++ 2005, they are ...\VC\bin and ...\Common7\IDE.
9 # This is typically done by opening the Visual Studio Command Prompt.
12 top_srcdir = .
13 srcdir = .
14 objdir = .
15 VPATH = .
16 prefix = "C:\Program Files\NASM"
17 exec_prefix = $(prefix)
18 bindir = $(prefix)/bin
19 mandir = $(prefix)/man
21 !IF "$(DEBUG)" == "1"
22 CFLAGS = /Od /Zi
23 LDFLAGS = /DEBUG
24 !ELSE
25 CFLAGS = /O2 /Zi
26 LDFLAGS = /DEBUG /OPT:REF /OPT:ICF # (latter two undoes /DEBUG harm)
27 !ENDIF
29 CC = cl
30 AR = lib
31 CFLAGS = $(CFLAGS) /W2
32 BUILD_CFLAGS = $(CFLAGS)
33 INTERNAL_CFLAGS = /I$(srcdir) /I. \
34 /I$(srcdir)/include /I./include \
35 /I$(srcdir)/x86 /I./x86 \
36 /I$(srcdir)/asm /I./asm \
37 /I$(srcdir)/disasm /I./disasm \
38 /I$(srcdir)/output /I./output
39 ALL_CFLAGS = $(BUILD_CFLAGS) $(INTERNAL_CFLAGS)
40 LDFLAGS = /link $(LINKFLAGS) /SUBSYSTEM:CONSOLE /RELEASE
41 LIBS =
43 PERL = perl
44 PERLFLAGS = -I$(srcdir)/perllib -I$(srcdir)
45 RUNPERL = $(PERL) $(PERLFLAGS)
47 MAKENSIS = makensis
49 RM_F = del /f
50 LN_S = copy
52 # Binary suffixes
53 O = obj
54 A = lib
55 X = .exe
56 .SUFFIXES:
57 .SUFFIXES: .c .i .s .$(O) .$(A) .exe .1 .man
59 .c.obj:
60 $(CC) /c $(ALL_CFLAGS) /Fo$@ $<
62 # This rule is only used for rdoff
63 .obj.exe:
64 $(CC) $(ALL_CFLAGS) /Fe$@ $< $(LDFLAGS) $(RDFLIB) $(NASMLIB) $(LIBS)
66 #-- Begin File Lists --#
67 # Edit in Makefile.in, not here!
68 NASM = asm\nasm.$(O)
69 NDISASM = disasm\ndisasm.$(O)
71 LIBOBJ = stdlib\snprintf.$(O) stdlib\vsnprintf.$(O) stdlib\strlcpy.$(O) \
72 stdlib\strnlen.$(O) stdlib\strrchrnul.$(O) \
74 nasmlib\ver.$(O) \
75 nasmlib\crc64.$(O) nasmlib\malloc.$(O) \
76 nasmlib\md5c.$(O) nasmlib\string.$(O) \
77 nasmlib\file.$(O) nasmlib\mmap.$(O) nasmlib\ilog2.$(O) \
78 nasmlib\realpath.$(O) nasmlib\path.$(O) \
79 nasmlib\filename.$(O) nasmlib\srcfile.$(O) \
80 nasmlib\zerobuf.$(O) nasmlib\readnum.$(O) nasmlib\bsi.$(O) \
81 nasmlib\rbtree.$(O) nasmlib\hashtbl.$(O) \
82 nasmlib\raa.$(O) nasmlib\saa.$(O) \
83 nasmlib\strlist.$(O) \
84 nasmlib\perfhash.$(O) nasmlib\badenum.$(O) \
86 common\common.$(O) \
88 x86\insnsa.$(O) x86\insnsb.$(O) x86\insnsd.$(O) x86\insnsn.$(O) \
89 x86\regs.$(O) x86\regvals.$(O) x86\regflags.$(O) x86\regdis.$(O) \
90 x86\disp8.$(O) x86\iflag.$(O) \
92 asm\error.$(O) \
93 asm\float.$(O) \
94 asm\directiv.$(O) asm\directbl.$(O) \
95 asm\pragma.$(O) \
96 asm\assemble.$(O) asm\labels.$(O) asm\parser.$(O) \
97 asm\preproc.$(O) asm\quote.$(O) asm\pptok.$(O) \
98 asm\listing.$(O) asm\eval.$(O) asm\exprlib.$(O) asm\exprdump.$(O) \
99 asm\stdscan.$(O) \
100 asm\strfunc.$(O) asm\tokhash.$(O) \
101 asm\segalloc.$(O) \
102 asm\preproc-nop.$(O) \
103 asm\rdstrnum.$(O) \
105 macros\macros.$(O) \
107 output\outform.$(O) output\outlib.$(O) output\legacy.$(O) \
108 output\strtbl.$(O) \
109 output\nulldbg.$(O) output\nullout.$(O) \
110 output\outbin.$(O) output\outaout.$(O) output\outcoff.$(O) \
111 output\outelf.$(O) \
112 output\outobj.$(O) output\outas86.$(O) output\outrdf2.$(O) \
113 output\outdbg.$(O) output\outieee.$(O) output\outmacho.$(O) \
114 output\codeview.$(O) \
116 disasm\disasm.$(O) disasm\sync.$(O)
118 SUBDIRS = stdlib nasmlib output asm disasm x86 common macros
119 XSUBDIRS = test doc nsis rdoff
120 DEPDIRS = . include config x86 rdoff $(SUBDIRS)
121 #-- End File Lists --#
123 NASMLIB = libnasm.$(A)
125 all: nasm$(X) ndisasm$(X) rdf
127 nasm$(X): $(NASM) $(NASMLIB)
128 $(CC) /Fe$@ $(NASM) $(LDFLAGS) $(NASMLIB) $(LIBS)
130 ndisasm$(X): $(NDISASM) $(NASMLIB)
131 $(CC) /Fe$@ $(NDISASM) $(LDFLAGS) $(NASMLIB) $(LIBS)
133 $(NASMLIB): $(LIBOBJ)
134 $(AR) $(ARFLAGS) /OUT:$@ $**
136 #-- Begin Generated File Rules --#
137 # Edit in Makefile.in, not here!
139 # These source files are automagically generated from data files using
140 # Perl scripts. They're distributed, though, so it isn't necessary to
141 # have Perl just to recompile NASM from the distribution.
143 # Perl-generated source files
144 PERLREQ = x86\insnsb.c x86\insnsa.c x86\insnsd.c x86\insnsi.h x86\insnsn.c \
145 x86\regs.c x86\regs.h x86\regflags.c x86\regdis.c x86\regdis.h \
146 x86\regvals.c asm\tokhash.c asm\tokens.h asm\pptok.h asm\pptok.c \
147 x86\iflag.c x86\iflaggen.h \
148 macros\macros.c \
149 asm\pptok.ph asm\directbl.c asm\directiv.h \
150 version.h version.mac version.mak nsis\version.nsh
152 INSDEP = x86\insns.dat x86\insns.pl x86\insns-iflags.ph
154 x86\iflag.c: $(INSDEP)
155 $(RUNPERL) $(srcdir)\x86\insns.pl -fc \
156 $(srcdir)\x86\insns.dat x86\iflag.c
157 x86\iflaggen.h: $(INSDEP)
158 $(RUNPERL) $(srcdir)\x86\insns.pl -fh \
159 $(srcdir)\x86\insns.dat x86\iflaggen.h
160 x86\insnsb.c: $(INSDEP)
161 $(RUNPERL) $(srcdir)\x86\insns.pl -b \
162 $(srcdir)\x86\insns.dat x86\insnsb.c
163 x86\insnsa.c: $(INSDEP)
164 $(RUNPERL) $(srcdir)\x86\insns.pl -a \
165 $(srcdir)\x86\insns.dat x86\insnsa.c
166 x86\insnsd.c: $(INSDEP)
167 $(RUNPERL) $(srcdir)\x86\insns.pl -d \
168 $(srcdir)\x86\insns.dat x86\insnsd.c
169 x86\insnsi.h: $(INSDEP)
170 $(RUNPERL) $(srcdir)\x86\insns.pl -i \
171 $(srcdir)\x86\insns.dat x86\insnsi.h
172 x86\insnsn.c: $(INSDEP)
173 $(RUNPERL) $(srcdir)\x86\insns.pl -n \
174 $(srcdir)\x86\insns.dat x86\insnsn.c
176 # These files contains all the standard macros that are derived from
177 # the version number.
178 version.h: version version.pl
179 $(RUNPERL) $(srcdir)\version.pl h < $(srcdir)\version > version.h
180 version.mac: version version.pl
181 $(RUNPERL) $(srcdir)\version.pl mac < $(srcdir)\version > version.mac
182 version.sed: version version.pl
183 $(RUNPERL) $(srcdir)\version.pl sed < $(srcdir)\version > version.sed
184 version.mak: version version.pl
185 $(RUNPERL) $(srcdir)\version.pl make < $(srcdir)\version > version.mak
186 nsis\version.nsh: version version.pl
187 $(RUNPERL) $(srcdir)\version.pl nsis < $(srcdir)\version > nsis\version.nsh
189 # This source file is generated from the standard macros file
190 # `standard.mac' by another Perl script. Again, it's part of the
191 # standard distribution.
192 macros\macros.c: macros\macros.pl asm\pptok.ph version.mac \
193 $(srcdir)\macros\*.mac $(srcdir)\output\*.mac
194 $(RUNPERL) $(srcdir)\macros\macros.pl version.mac \
195 $(srcdir)\macros\*.mac $(srcdir)\output\*.mac
197 # These source files are generated from regs.dat by yet another
198 # perl script.
199 x86\regs.c: x86\regs.dat x86\regs.pl
200 $(RUNPERL) $(srcdir)\x86\regs.pl c \
201 $(srcdir)\x86\regs.dat > x86\regs.c
202 x86\regflags.c: x86\regs.dat x86\regs.pl
203 $(RUNPERL) $(srcdir)\x86\regs.pl fc \
204 $(srcdir)\x86\regs.dat > x86\regflags.c
205 x86\regdis.c: x86\regs.dat x86\regs.pl
206 $(RUNPERL) $(srcdir)\x86\regs.pl dc \
207 $(srcdir)\x86\regs.dat > x86\regdis.c
208 x86\regdis.h: x86\regs.dat x86\regs.pl
209 $(RUNPERL) $(srcdir)\x86\regs.pl dh \
210 $(srcdir)\x86\regs.dat > x86\regdis.h
211 x86\regvals.c: x86\regs.dat x86\regs.pl
212 $(RUNPERL) $(srcdir)\x86\regs.pl vc \
213 $(srcdir)\x86\regs.dat > x86\regvals.c
214 x86\regs.h: x86\regs.dat x86\regs.pl
215 $(RUNPERL) $(srcdir)\x86\regs.pl h \
216 $(srcdir)\x86\regs.dat > x86\regs.h
218 # Assembler token hash
219 asm\tokhash.c: x86\insns.dat x86\regs.dat asm\tokens.dat asm\tokhash.pl \
220 perllib\phash.ph
221 $(RUNPERL) $(srcdir)\asm\tokhash.pl c \
222 $(srcdir)\x86\insns.dat $(srcdir)\x86\regs.dat \
223 $(srcdir)\asm\tokens.dat > asm\tokhash.c
225 # Assembler token metadata
226 asm\tokens.h: x86\insns.dat x86\regs.dat asm\tokens.dat asm\tokhash.pl \
227 perllib\phash.ph
228 $(RUNPERL) $(srcdir)\asm\tokhash.pl h \
229 $(srcdir)\x86\insns.dat $(srcdir)\x86\regs.dat \
230 $(srcdir)\asm\tokens.dat > asm\tokens.h
232 # Preprocessor token hash
233 asm\pptok.h: asm\pptok.dat asm\pptok.pl perllib\phash.ph
234 $(RUNPERL) $(srcdir)\asm\pptok.pl h \
235 $(srcdir)\asm\pptok.dat asm\pptok.h
236 asm\pptok.c: asm\pptok.dat asm\pptok.pl perllib\phash.ph
237 $(RUNPERL) $(srcdir)\asm\pptok.pl c \
238 $(srcdir)\asm\pptok.dat asm\pptok.c
239 asm\pptok.ph: asm\pptok.dat asm\pptok.pl perllib\phash.ph
240 $(RUNPERL) $(srcdir)\asm\pptok.pl ph \
241 $(srcdir)\asm\pptok.dat asm\pptok.ph
243 # Directives hash
244 asm\directiv.h: asm\directiv.dat nasmlib\perfhash.pl perllib\phash.ph
245 $(RUNPERL) $(srcdir)\nasmlib\perfhash.pl h \
246 $(srcdir)\asm\directiv.dat asm\directiv.h
247 asm\directbl.c: asm\directiv.dat nasmlib\perfhash.pl perllib\phash.ph
248 $(RUNPERL) $(srcdir)\nasmlib\perfhash.pl c \
249 $(srcdir)\asm\directiv.dat asm\directbl.c
251 #-- End Generated File Rules --#
253 perlreq: $(PERLREQ)
255 #-- Begin RDOFF Shared Rules --#
256 # Edit in Makefile.in, not here!
258 RDFLIBOBJ = rdoff\rdoff.$(O) rdoff\rdfload.$(O) rdoff\symtab.$(O) \
259 rdoff\collectn.$(O) rdoff\rdlib.$(O) rdoff\segtab.$(O) \
260 rdoff\hash.$(O)
262 RDFPROGS = rdoff\rdfdump$(X) rdoff\ldrdf$(X) rdoff\rdx$(X) rdoff\rdflib$(X) \
263 rdoff\rdf2bin$(X)
264 RDF2BINLINKS = rdoff\rdf2com$(X) rdoff\rdf2ith$(X) \
265 rdoff\rdf2ihx$(X) rdoff\rdf2srec$(X)
267 RDFLIB = rdoff\librdoff.$(A)
268 RDFLIBS = $(RDFLIB) $(NASMLIB)
270 # This rule is only used for rdoff, to allow common rules
271 MAKERDF = $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $< $(RDFLIB) $(NASMLIB) $(LIBS)
273 rdoff\rdfdump$(X): rdoff\rdfdump.$(O) $(RDFLIBS)
274 $(MAKERDF)
275 rdoff\ldrdf$(X): rdoff\ldrdf.$(O) $(RDFLIBS)
276 $(MAKERDF)
277 rdoff\rdx$(X): rdoff\rdx.$(O) $(RDFLIBS)
278 $(MAKERDF)
279 rdoff\rdflib$(X): rdoff\rdflib.$(O) $(RDFLIBS)
280 $(MAKERDF)
281 rdoff\rdf2bin$(X): rdoff\rdf2bin.$(O) $(RDFLIBS)
282 $(MAKERDF)
283 rdoff\rdf2com$(X): rdoff\rdf2bin$(X)
284 $(RM_F) rdoff\rdf2com$(X)
285 cd rdoff && $(LN_S) rdf2bin$(X) rdf2com$(X)
286 rdoff\rdf2ith$(X): rdoff\rdf2bin$(X)
287 $(RM_F) rdoff\rdf2ith$(X)
288 cd rdoff && $(LN_S) rdf2bin$(X) rdf2ith$(X)
289 rdoff\rdf2ihx$(X): rdoff\rdf2bin$(X)
290 $(RM_F) rdoff\rdf2ihx$(X)
291 cd rdoff && $(LN_S) rdf2bin$(X) rdf2ihx$(X)
292 rdoff\rdf2srec$(X): rdoff\rdf2bin$(X)
293 $(RM_F) rdoff\rdf2srec$(X)
294 cd rdoff && $(LN_S) rdf2bin$(X) rdf2srec$(X)
296 #-- End RDOFF Shared Rules --#
298 rdf: $(RDFPROGS) $(RDF2BINLINKS)
300 $(RDFLIB): $(RDFLIBOBJ)
301 $(AR) $(ARFLAGS) /OUT:$@ $**
303 #-- Begin NSIS Rules --#
304 # Edit in Makefile.in, not here!
306 # NSIS is not built except by explicit request, as it only applies to
307 # Windows platforms
308 nsis\arch.nsh: nsis\getpearch.pl nasm$(X)
309 $(PERL) $(srcdir)\nsis\getpearch.pl nasm$(X) > nsis\arch.nsh
311 # Should only be done after "make everything".
312 # The use of redirection here keeps makensis from moving the cwd to the
313 # source directory.
314 nsis: nsis\nasm.nsi nsis\arch.nsh nsis\version.nsh
315 $(MAKENSIS) -Dsrcdir="$(srcdir)" -Dobjdir="$(objdir)" - < nsis\nasm.nsi
317 #-- End NSIS Rules --#
319 clean:
320 -del /f /s *.$(O)
321 -del /f /s *.pdb
322 -del /f /s *.s
323 -del /f /s *.i
324 -del /f $(NASMLIB) $(RDFLIB)
325 -del /f nasm$(X)
326 -del /f ndisasm$(X)
327 -del /f rdoff\*$(X)
329 distclean: clean
330 -del /f config.h
331 -del /f config.log
332 -del /f config.status
333 -del /f Makefile
334 -del /f /s *~
335 -del /f /s *.bak
336 -del /f /s *.lst
337 -del /f /s *.bin
338 -del /f /s *.dep
339 -del /f output\*~
340 -del /f output\*.bak
341 -del /f test\*.lst
342 -del /f test\*.bin
343 -del /f test\*.$(O)
344 -del /f test\*.bin
345 -del /f/s autom4te*.cache
346 rem cd rdoff && $(MAKE) distclean
348 cleaner: clean
349 -del /f $(PERLREQ)
350 -del /f *.man
351 -del /f nasm.spec
352 rem cd doc && $(MAKE) clean
354 spotless: distclean cleaner
355 -del /f doc\Makefile
356 -del doc\*~
357 -del doc\*.bak
359 strip:
361 # Abuse doc/Makefile.in to build nasmdoc.pdf only
362 docs:
363 cd doc && $(MAKE) /f Makefile.in srcdir=. top_srcdir=.. \
364 PERL=$(PERL) PDFOPT= nasmdoc.pdf
366 everything: all docs nsis
369 # Does this version of this file have external dependencies? This definition
370 # will be automatically updated by mkdep.pl as needed.
372 EXTERNAL_DEPENDENCIES = 1
375 # Generate dependency information for this Makefile only.
376 # If this Makefile has external dependency information, then
377 # the dependency information will remain external, so it doesn't
378 # pollute the git logs.
380 msvc.dep: $(PERLREQ) tools\mkdep.pl
381 $(RUNPERL) tools\mkdep.pl -M Mkfiles\msvc.mak -- $(DEPDIRS)
383 dep: msvc.dep
385 # Include and/or generate msvc.dep as needed. This is too complex to
386 # use the include-command feature, but we can open-code it here.
387 !IF $(EXTERNAL_DEPENDENCIES) == 1
388 !IFDEF MKDEP
389 !IF EXISTS(msvc.dep)
390 !INCLUDE msvc.dep
391 !ENDIF
392 !ELSEIF [$(MAKE) /c MKDEP=1 /f Mkfiles\msvc.mak msvc.dep] == 0
393 !INCLUDE msvc.dep
394 !ELSE
395 !ERROR Unable to rebuild dependencies file msvc.dep
396 !ENDIF
398 #-- Magic hints to mkdep.pl --#
399 # @object-ending: ".$(O)"
400 # @path-separator: "\"
401 # @exclude: "config/config.h"
402 # @external: "msvc.dep"
403 # @selfrule: "1"
404 #-- Everything below is generated by mkdep.pl - do not edit --#