Fix Windows make clean.
[luajit-2.0.git] / src / Makefile
blob5cf1f0be648f25ca005e448b5eee03a99e80bf2d
1 ##############################################################################
2 # LuaJIT Makefile. Requires GNU Make.
4 # Please read doc/install.html before changing any variables!
6 # Suitable for POSIX platforms (Linux, *BSD, OSX etc.).
7 # Also works with MinGW and Cygwin on Windows.
8 # Please check msvcbuild.bat for building with MSVC on Windows.
10 # Copyright (C) 2005-2020 Mike Pall. See Copyright Notice in luajit.h
11 ##############################################################################
13 MAJVER= 2
14 MINVER= 0
15 RELVER= 5
16 ABIVER= 5.1
17 NODOTABIVER= 51
19 ##############################################################################
20 ############################# COMPILER OPTIONS #############################
21 ##############################################################################
22 # These options mainly affect the speed of the JIT compiler itself, not the
23 # speed of the JIT-compiled code. Turn any of the optional settings on by
24 # removing the '#' in front of them. Make sure you force a full recompile
25 # with "make clean", followed by "make" if you change any options.
27 DEFAULT_CC = gcc
29 # LuaJIT builds as a native 32 or 64 bit binary by default.
30 CC= $(DEFAULT_CC)
32 # Use this if you want to force a 32 bit build on a 64 bit multilib OS.
33 #CC= $(DEFAULT_CC) -m32
35 # Since the assembler part does NOT maintain a frame pointer, it's pointless
36 # to slow down the C part by not omitting it. Debugging, tracebacks and
37 # unwinding are not affected -- the assembler part has frame unwind
38 # information and GCC emits it where needed (x64) or with -g (see CCDEBUG).
39 CCOPT= -O2 -fomit-frame-pointer
40 # Use this if you want to generate a smaller binary (but it's slower):
41 #CCOPT= -Os -fomit-frame-pointer
42 # Note: it's no longer recommended to use -O3 with GCC 4.x.
43 # The I-Cache bloat usually outweighs the benefits from aggressive inlining.
45 # Target-specific compiler options:
47 # x86 only: it's recommended to compile at least for i686. Better yet,
48 # compile for an architecture that has SSE2, too (-msse -msse2).
50 # x86/x64 only: For GCC 4.2 or higher and if you don't intend to distribute
51 # the binaries to a different machine you could also use: -march=native
53 CCOPT_x86= -march=i686
54 CCOPT_x64=
55 CCOPT_arm=
56 CCOPT_ppc=
57 CCOPT_ppcspe=
58 CCOPT_mips=
60 CCDEBUG=
61 # Uncomment the next line to generate debug information:
62 #CCDEBUG= -g
64 CCWARN= -Wall
65 # Uncomment the next line to enable more warnings:
66 #CCWARN+= -Wextra -Wdeclaration-after-statement -Wredundant-decls -Wshadow -Wpointer-arith
68 ##############################################################################
70 ##############################################################################
71 ################################ BUILD MODE ################################
72 ##############################################################################
73 # The default build mode is mixed mode on POSIX. On Windows this is the same
74 # as dynamic mode.
76 # Mixed mode creates a static + dynamic library and a statically linked luajit.
77 BUILDMODE= mixed
79 # Static mode creates a static library and a statically linked luajit.
80 #BUILDMODE= static
82 # Dynamic mode creates a dynamic library and a dynamically linked luajit.
83 # Note: this executable will only run when the library is installed!
84 #BUILDMODE= dynamic
86 ##############################################################################
88 ##############################################################################
89 ################################# FEATURES #################################
90 ##############################################################################
91 # Enable/disable these features as needed, but make sure you force a full
92 # recompile with "make clean", followed by "make".
93 XCFLAGS=
95 # Permanently disable the FFI extension to reduce the size of the LuaJIT
96 # executable. But please consider that the FFI library is compiled-in,
97 # but NOT loaded by default. It only allocates any memory, if you actually
98 # make use of it.
99 #XCFLAGS+= -DLUAJIT_DISABLE_FFI
101 # Features from Lua 5.2 that are unlikely to break existing code are
102 # enabled by default. Some other features that *might* break some existing
103 # code (e.g. __pairs or os.execute() return values) can be enabled here.
104 # Note: this does not provide full compatibility with Lua 5.2 at this time.
105 #XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
107 # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.
108 #XCFLAGS+= -DLUAJIT_DISABLE_JIT
110 # Some architectures (e.g. PPC) can use either single-number (1) or
111 # dual-number (2) mode. Uncomment one of these lines to override the
112 # default mode. Please see LJ_ARCH_NUMMODE in lj_arch.h for details.
113 #XCFLAGS+= -DLUAJIT_NUMMODE=1
114 #XCFLAGS+= -DLUAJIT_NUMMODE=2
116 ##############################################################################
118 ##############################################################################
119 ############################ DEBUGGING SUPPORT #############################
120 ##############################################################################
121 # Enable these options as needed, but make sure you force a full recompile
122 # with "make clean", followed by "make".
123 # Note that most of these are NOT suitable for benchmarking or release mode!
125 # Use the system provided memory allocator (realloc) instead of the
126 # bundled memory allocator. This is slower, but sometimes helpful for
127 # debugging. This option cannot be enabled on x64, since realloc usually
128 # doesn't return addresses in the right address range.
129 # OTOH this option is mandatory for Valgrind's memcheck tool on x64 and
130 # the only way to get useful results from it for all other architectures.
131 #XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
133 # This define is required to run LuaJIT under Valgrind. The Valgrind
134 # header files must be installed. You should enable debug information, too.
135 # Use --suppressions=lj.supp to avoid some false positives.
136 #XCFLAGS+= -DLUAJIT_USE_VALGRIND
138 # This is the client for the GDB JIT API. GDB 7.0 or higher is required
139 # to make use of it. See lj_gdbjit.c for details. Enabling this causes
140 # a non-negligible overhead, even when not running under GDB.
141 #XCFLAGS+= -DLUAJIT_USE_GDBJIT
143 # Turn on assertions for the Lua/C API to debug problems with lua_* calls.
144 # This is rather slow -- use only while developing C libraries/embeddings.
145 #XCFLAGS+= -DLUA_USE_APICHECK
147 # Turn on assertions for the whole LuaJIT VM. This significantly slows down
148 # everything. Use only if you suspect a problem with LuaJIT itself.
149 #XCFLAGS+= -DLUA_USE_ASSERT
151 ##############################################################################
152 # You probably don't need to change anything below this line!
153 ##############################################################################
155 ##############################################################################
156 # Host system detection.
157 ##############################################################################
159 ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM))
160 HOST_SYS= Windows
161 else
162 HOST_SYS:= $(shell uname -s)
163 ifneq (,$(findstring MINGW,$(HOST_SYS)))
164 HOST_SYS= Windows
165 HOST_MSYS= mingw
166 endif
167 ifneq (,$(findstring MSYS,$(HOST_SYS)))
168 HOST_SYS= Windows
169 HOST_MSYS= mingw
170 endif
171 ifneq (,$(findstring CYGWIN,$(HOST_SYS)))
172 HOST_SYS= Windows
173 HOST_MSYS= cygwin
174 endif
175 endif
177 ##############################################################################
178 # Flags and options for host and target.
179 ##############################################################################
181 # You can override the following variables at the make command line:
182 # CC HOST_CC STATIC_CC DYNAMIC_CC
183 # CFLAGS HOST_CFLAGS TARGET_CFLAGS
184 # LDFLAGS HOST_LDFLAGS TARGET_LDFLAGS TARGET_SHLDFLAGS
185 # LIBS HOST_LIBS TARGET_LIBS
186 # CROSS HOST_SYS TARGET_SYS TARGET_FLAGS
188 # Cross-compilation examples:
189 # make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
190 # make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu-
192 CCOPTIONS= $(CCDEBUG) $(CCOPT) $(CCWARN) $(XCFLAGS) $(CFLAGS)
193 LDOPTIONS= $(CCDEBUG) $(LDFLAGS)
195 HOST_CC= $(CC)
196 HOST_RM?= rm -f
197 # If left blank, minilua is built and used. You can supply an installed
198 # copy of (plain) Lua 5.1 or 5.2, plus Lua BitOp. E.g. with: HOST_LUA=lua
199 HOST_LUA=
201 HOST_XCFLAGS= -I.
202 HOST_XLDFLAGS=
203 HOST_XLIBS=
204 HOST_ACFLAGS= $(CCOPTIONS) $(HOST_XCFLAGS) $(TARGET_ARCH) $(HOST_CFLAGS)
205 HOST_ALDFLAGS= $(LDOPTIONS) $(HOST_XLDFLAGS) $(HOST_LDFLAGS)
206 HOST_ALIBS= $(HOST_XLIBS) $(LIBS) $(HOST_LIBS)
208 STATIC_CC = $(CROSS)$(CC)
209 DYNAMIC_CC = $(CROSS)$(CC) -fPIC
210 TARGET_CC= $(STATIC_CC)
211 TARGET_STCC= $(STATIC_CC)
212 TARGET_DYNCC= $(DYNAMIC_CC)
213 TARGET_LD= $(CROSS)$(CC)
214 TARGET_AR= $(CROSS)ar rcus
215 TARGET_STRIP= $(CROSS)strip
217 TARGET_LIBPATH= $(or $(PREFIX),/usr/local)/$(or $(MULTILIB),lib)
218 TARGET_SONAME= libluajit-$(ABIVER).so.$(MAJVER)
219 TARGET_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).dylib
220 TARGET_DYLIBPATH= $(TARGET_LIBPATH)/$(TARGET_DYLIBNAME)
221 TARGET_DLLNAME= lua$(NODOTABIVER).dll
222 TARGET_DLLDOTANAME= libluajit-$(ABIVER).dll.a
223 TARGET_XSHLDFLAGS= -shared -fPIC -Wl,-soname,$(TARGET_SONAME)
224 TARGET_DYNXLDOPTS=
226 TARGET_LFSFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
227 TARGET_XCFLAGS= $(TARGET_LFSFLAGS) -U_FORTIFY_SOURCE
228 TARGET_XLDFLAGS=
229 TARGET_XLIBS= -lm
230 TARGET_TCFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
231 TARGET_ACFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
232 TARGET_ALDFLAGS= $(LDOPTIONS) $(TARGET_XLDFLAGS) $(TARGET_FLAGS) $(TARGET_LDFLAGS)
233 TARGET_ASHLDFLAGS= $(LDOPTIONS) $(TARGET_XSHLDFLAGS) $(TARGET_FLAGS) $(TARGET_SHLDFLAGS)
234 TARGET_ALIBS= $(TARGET_XLIBS) $(LIBS) $(TARGET_LIBS)
236 TARGET_TESTARCH=$(shell $(TARGET_CC) $(TARGET_TCFLAGS) -E lj_arch.h -dM)
237 ifneq (,$(findstring LJ_TARGET_X64 ,$(TARGET_TESTARCH)))
238 TARGET_LJARCH= x64
239 else
240 ifneq (,$(findstring LJ_TARGET_X86 ,$(TARGET_TESTARCH)))
241 TARGET_LJARCH= x86
242 else
243 ifneq (,$(findstring LJ_TARGET_ARM ,$(TARGET_TESTARCH)))
244 TARGET_LJARCH= arm
245 else
246 ifneq (,$(findstring LJ_TARGET_PPC ,$(TARGET_TESTARCH)))
247 TARGET_LJARCH= ppc
248 else
249 ifneq (,$(findstring LJ_TARGET_PPCSPE ,$(TARGET_TESTARCH)))
250 TARGET_LJARCH= ppcspe
251 else
252 ifneq (,$(findstring LJ_TARGET_MIPS ,$(TARGET_TESTARCH)))
253 ifneq (,$(findstring MIPSEL ,$(TARGET_TESTARCH)))
254 TARGET_ARCH= -D__MIPSEL__=1
255 endif
256 TARGET_LJARCH= mips
257 else
258 $(error Unsupported target architecture)
259 endif
260 endif
261 endif
262 endif
263 endif
264 endif
266 ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH)))
267 TARGET_SYS= PS3
268 TARGET_ARCH+= -D__CELLOS_LV2__
269 TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
270 endif
272 TARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH))
273 TARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH))
275 ifneq (,$(PREFIX))
276 ifneq (/usr/local,$(PREFIX))
277 TARGET_XCFLAGS+= -DLUA_ROOT=\"$(PREFIX)\"
278 ifneq (/usr,$(PREFIX))
279 TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH)
280 endif
281 endif
282 endif
283 ifneq (,$(MULTILIB))
284 TARGET_XCFLAGS+= -DLUA_MULTILIB=\"$(MULTILIB)\"
285 endif
286 ifneq (,$(LMULTILIB))
287 TARGET_XCFLAGS+= -DLUA_LMULTILIB=\"$(LMULTILIB)\"
288 endif
290 ##############################################################################
291 # Target system detection.
292 ##############################################################################
294 TARGET_SYS?= $(HOST_SYS)
295 ifeq (Windows,$(TARGET_SYS))
296 TARGET_STRIP+= --strip-unneeded
297 TARGET_XSHLDFLAGS= -shared -Wl,--out-implib,$(TARGET_DLLDOTANAME)
298 TARGET_DYNXLDOPTS=
299 else
300 TARGET_AR+= 2>/dev/null
301 ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1))
302 TARGET_XCFLAGS+= -fno-stack-protector
303 endif
304 ifeq (Darwin,$(TARGET_SYS))
305 ifeq (,$(MACOSX_DEPLOYMENT_TARGET))
306 $(error missing: export MACOSX_DEPLOYMENT_TARGET=XX.YY)
307 endif
308 TARGET_STRIP+= -x
309 TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
310 TARGET_DYNXLDOPTS=
311 TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
312 ifeq (x64,$(TARGET_LJARCH))
313 TARGET_XLDFLAGS+= -pagezero_size 10000 -image_base 100000000
314 TARGET_XSHLDFLAGS+= -image_base 7fff04c4a000
315 endif
316 else
317 ifeq (iOS,$(TARGET_SYS))
318 TARGET_STRIP+= -x
319 TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
320 TARGET_DYNXLDOPTS=
321 TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
322 else
323 ifneq (SunOS,$(TARGET_SYS))
324 ifneq (PS3,$(TARGET_SYS))
325 TARGET_XLDFLAGS+= -Wl,-E
326 endif
327 endif
328 ifeq (Linux,$(TARGET_SYS))
329 TARGET_XLIBS+= -ldl
330 endif
331 ifeq (GNU/kFreeBSD,$(TARGET_SYS))
332 TARGET_XLIBS+= -ldl
333 endif
334 endif
335 endif
336 endif
338 ifneq ($(HOST_SYS),$(TARGET_SYS))
339 ifeq (Windows,$(TARGET_SYS))
340 HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS
341 else
342 ifeq (Linux,$(TARGET_SYS))
343 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX
344 else
345 ifeq (Darwin,$(TARGET_SYS))
346 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
347 else
348 ifeq (iOS,$(TARGET_SYS))
349 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
350 else
351 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER
352 endif
353 endif
354 endif
355 endif
356 endif
358 ifneq (,$(CCDEBUG))
359 TARGET_STRIP= @:
360 endif
362 ##############################################################################
363 # Files and pathnames.
364 ##############################################################################
366 MINILUA_O= host/minilua.o
367 MINILUA_LIBS= -lm
368 MINILUA_T= host/minilua
369 MINILUA_X= $(MINILUA_T)
371 ifeq (,$(HOST_LUA))
372 HOST_LUA= $(MINILUA_X)
373 DASM_DEP= $(MINILUA_T)
374 endif
376 DASM_DIR= ../dynasm
377 DASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua
378 DASM_XFLAGS=
379 DASM_AFLAGS=
380 DASM_ARCH= $(TARGET_LJARCH)
382 ifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH)))
383 DASM_AFLAGS+= -D P64
384 endif
385 ifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH)))
386 DASM_AFLAGS+= -D JIT
387 endif
388 ifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH)))
389 DASM_AFLAGS+= -D FFI
390 endif
391 ifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH)))
392 DASM_AFLAGS+= -D DUALNUM
393 endif
394 ifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH)))
395 DASM_AFLAGS+= -D FPU
396 TARGET_ARCH+= -DLJ_ARCH_HASFPU=1
397 else
398 TARGET_ARCH+= -DLJ_ARCH_HASFPU=0
399 endif
400 ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH)))
401 DASM_AFLAGS+= -D HFABI
402 TARGET_ARCH+= -DLJ_ABI_SOFTFP=0
403 else
404 TARGET_ARCH+= -DLJ_ABI_SOFTFP=1
405 endif
406 ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))
407 DASM_AFLAGS+= -D NO_UNWIND
408 TARGET_ARCH+= -DLUAJIT_NO_UNWIND
409 endif
410 DASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH))))
411 ifeq (Windows,$(TARGET_SYS))
412 DASM_AFLAGS+= -D WIN
413 endif
414 ifeq (x86,$(TARGET_LJARCH))
415 ifneq (,$(findstring __SSE2__ 1,$(TARGET_TESTARCH)))
416 DASM_AFLAGS+= -D SSE
417 endif
418 else
419 ifeq (x64,$(TARGET_LJARCH))
420 DASM_ARCH= x86
421 else
422 ifeq (arm,$(TARGET_LJARCH))
423 ifeq (iOS,$(TARGET_SYS))
424 DASM_AFLAGS+= -D IOS
425 endif
426 else
427 ifeq (ppc,$(TARGET_LJARCH))
428 ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH)))
429 DASM_AFLAGS+= -D SQRT
430 endif
431 ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH)))
432 DASM_AFLAGS+= -D ROUND
433 endif
434 ifneq (,$(findstring LJ_ARCH_PPC64 1,$(TARGET_TESTARCH)))
435 DASM_AFLAGS+= -D GPR64
436 endif
437 ifeq (PS3,$(TARGET_SYS))
438 DASM_AFLAGS+= -D PPE -D TOC
439 endif
440 endif
441 endif
442 endif
443 endif
445 DASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS)
446 DASM_DASC= vm_$(DASM_ARCH).dasc
448 BUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \
449 host/buildvm_lib.o host/buildvm_fold.o
450 BUILDVM_T= host/buildvm
451 BUILDVM_X= $(BUILDVM_T)
453 HOST_O= $(MINILUA_O) $(BUILDVM_O)
454 HOST_T= $(MINILUA_T) $(BUILDVM_T)
456 LJVM_S= lj_vm.s
457 LJVM_O= lj_vm.o
458 LJVM_BOUT= $(LJVM_S)
459 LJVM_MODE= elfasm
461 LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
462 lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o
463 LJLIB_C= $(LJLIB_O:.o=.c)
465 LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o \
466 lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \
467 lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o lj_strscan.o \
468 lj_api.o lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \
469 lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
470 lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \
471 lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \
472 lj_asm.o lj_trace.o lj_gdbjit.o \
473 lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \
474 lj_carith.o lj_clib.o lj_cparse.o \
475 lj_lib.o lj_alloc.o lib_aux.o \
476 $(LJLIB_O) lib_init.o
478 LJVMCORE_O= $(LJVM_O) $(LJCORE_O)
479 LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o)
481 LIB_VMDEF= jit/vmdef.lua
482 LIB_VMDEFP= $(LIB_VMDEF)
484 LUAJIT_O= luajit.o
485 LUAJIT_A= libluajit.a
486 LUAJIT_SO= libluajit.so
487 LUAJIT_T= luajit
489 ALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T)
490 ALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \
491 host/buildvm_arch.h
492 ALL_GEN= $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP)
493 WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk
494 ALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM)
496 ##############################################################################
497 # Build mode handling.
498 ##############################################################################
500 # Mixed mode defaults.
501 TARGET_O= $(LUAJIT_A)
502 TARGET_T= $(LUAJIT_T) $(LUAJIT_SO)
503 TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO)
505 ifeq (Windows,$(TARGET_SYS))
506 TARGET_DYNCC= $(STATIC_CC)
507 LJVM_MODE= peobj
508 LJVM_BOUT= $(LJVM_O)
509 LUAJIT_T= luajit.exe
510 ifeq (cygwin,$(HOST_MSYS))
511 LUAJIT_SO= cyg$(TARGET_DLLNAME)
512 else
513 LUAJIT_SO= $(TARGET_DLLNAME)
514 endif
515 # Mixed mode is not supported on Windows. And static mode doesn't work well.
516 # C modules cannot be loaded, because they bind to lua51.dll.
517 ifneq (static,$(BUILDMODE))
518 BUILDMODE= dynamic
519 TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL
520 endif
521 endif
522 ifeq (Darwin,$(TARGET_SYS))
523 LJVM_MODE= machasm
524 endif
525 ifeq (iOS,$(TARGET_SYS))
526 LJVM_MODE= machasm
527 endif
528 ifeq (SunOS,$(TARGET_SYS))
529 BUILDMODE= static
530 endif
531 ifeq (PS3,$(TARGET_SYS))
532 BUILDMODE= static
533 endif
535 ifeq (Windows,$(HOST_SYS))
536 MINILUA_T= host/minilua.exe
537 BUILDVM_T= host/buildvm.exe
538 ifeq (,$(HOST_MSYS))
539 MINILUA_X= host\minilua
540 BUILDVM_X= host\buildvm
541 ALL_RM:= $(subst /,\,$(ALL_RM))
542 HOST_RM= del
543 endif
544 endif
546 ifeq (static,$(BUILDMODE))
547 TARGET_DYNCC= @:
548 TARGET_T= $(LUAJIT_T)
549 TARGET_DEP= $(LIB_VMDEF)
550 else
551 ifeq (dynamic,$(BUILDMODE))
552 ifneq (Windows,$(TARGET_SYS))
553 TARGET_CC= $(DYNAMIC_CC)
554 endif
555 TARGET_DYNCC= @:
556 LJVMCORE_DYNO= $(LJVMCORE_O)
557 TARGET_O= $(LUAJIT_SO)
558 TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS)
559 else
560 ifeq (Darwin,$(TARGET_SYS))
561 TARGET_DYNCC= @:
562 LJVMCORE_DYNO= $(LJVMCORE_O)
563 endif
564 ifeq (iOS,$(TARGET_SYS))
565 TARGET_DYNCC= @:
566 LJVMCORE_DYNO= $(LJVMCORE_O)
567 endif
568 endif
569 endif
571 Q= @
572 E= @echo
574 #E= @:
576 ##############################################################################
577 # Make targets.
578 ##############################################################################
580 default all: $(TARGET_T)
582 amalg:
583 @grep "^[+|]" ljamalg.c
584 $(MAKE) all "LJCORE_O=ljamalg.o"
586 clean:
587 $(HOST_RM) $(ALL_RM)
589 depend:
590 @for file in $(ALL_HDRGEN); do \
591 test -f $$file || touch $$file; \
592 done
593 @$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \
594 sed -e "s| [^ ]*/dasm_\S*\.h||g" \
595 -e "s|^\([^l ]\)|host/\1|" \
596 -e "s| lj_target_\S*\.h| lj_target_*.h|g" \
597 -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \
598 -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep
599 @for file in $(ALL_HDRGEN); do \
600 test -s $$file || $(HOST_RM) $$file; \
601 done
603 .PHONY: default all amalg clean depend
605 ##############################################################################
606 # Rules for generated files.
607 ##############################################################################
609 $(MINILUA_T): $(MINILUA_O)
610 $(E) "HOSTLINK $@"
611 $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS)
613 host/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP)
614 $(E) "DYNASM $@"
615 $(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC)
617 host/buildvm.o: $(DASM_DIR)/dasm_*.h
619 $(BUILDVM_T): $(BUILDVM_O)
620 $(E) "HOSTLINK $@"
621 $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS)
623 $(LJVM_BOUT): $(BUILDVM_T)
624 $(E) "BUILDVM $@"
625 $(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@
627 lj_bcdef.h: $(BUILDVM_T) $(LJLIB_C)
628 $(E) "BUILDVM $@"
629 $(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C)
631 lj_ffdef.h: $(BUILDVM_T) $(LJLIB_C)
632 $(E) "BUILDVM $@"
633 $(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C)
635 lj_libdef.h: $(BUILDVM_T) $(LJLIB_C)
636 $(E) "BUILDVM $@"
637 $(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C)
639 lj_recdef.h: $(BUILDVM_T) $(LJLIB_C)
640 $(E) "BUILDVM $@"
641 $(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C)
643 $(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C)
644 $(E) "BUILDVM $@"
645 $(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C)
647 lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c
648 $(E) "BUILDVM $@"
649 $(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c
651 ##############################################################################
652 # Object file rules.
653 ##############################################################################
655 %.o: %.c
656 $(E) "CC $@"
657 $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<
658 $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<
660 %.o: %.s
661 $(E) "ASM $@"
662 $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<
663 $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<
665 $(LUAJIT_O):
666 $(E) "CC $@"
667 $(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -c -o $@ $<
669 $(HOST_O): %.o: %.c
670 $(E) "HOSTCC $@"
671 $(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<
673 include Makefile.dep
675 ##############################################################################
676 # Target file rules.
677 ##############################################################################
679 $(LUAJIT_A): $(LJVMCORE_O)
680 $(E) "AR $@"
681 $(Q)$(TARGET_AR) $@ $(LJVMCORE_O)
683 # The dependency on _O, but linking with _DYNO is intentional.
684 $(LUAJIT_SO): $(LJVMCORE_O)
685 $(E) "DYNLINK $@"
686 $(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS)
687 $(Q)$(TARGET_STRIP) $@
689 $(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP)
690 $(E) "LINK $@"
691 $(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS)
692 $(Q)$(TARGET_STRIP) $@
693 $(E) "OK Successfully built LuaJIT"
695 ##############################################################################