OSX/iOS: Fix SDK incompatibility.
[luajit-2.0.git] / src / Makefile
blob224d21e70373c76153d54f1937d70adeed8ee963
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-2023 Mike Pall. See Copyright Notice in luajit.h
11 ##############################################################################
13 MAJVER= 2
14 MINVER= 1
15 ABIVER= 5.1
16 NODOTABIVER= 51
18 ##############################################################################
19 ############################# COMPILER OPTIONS #############################
20 ##############################################################################
21 # These options mainly affect the speed of the JIT compiler itself, not the
22 # speed of the JIT-compiled code. Turn any of the optional settings on by
23 # removing the '#' in front of them. Make sure you force a full recompile
24 # with "make clean", followed by "make" if you change any options.
26 DEFAULT_CC = gcc
28 # LuaJIT builds as a native 32 or 64 bit binary by default.
29 CC= $(DEFAULT_CC)
31 # Use this if you want to force a 32 bit build on a 64 bit multilib OS.
32 #CC= $(DEFAULT_CC) -m32
34 # Since the assembler part does NOT maintain a frame pointer, it's pointless
35 # to slow down the C part by not omitting it. Debugging, tracebacks and
36 # unwinding are not affected -- the assembler part has frame unwind
37 # information and GCC emits it where needed (x64) or with -g (see CCDEBUG).
38 CCOPT= -O2 -fomit-frame-pointer
39 # Use this if you want to generate a smaller binary (but it's slower):
40 #CCOPT= -Os -fomit-frame-pointer
41 # Note: it's no longer recommended to use -O3 with GCC 4.x.
42 # The I-Cache bloat usually outweighs the benefits from aggressive inlining.
44 # Target-specific compiler options:
46 # x86/x64 only: For GCC 4.2 or higher and if you don't intend to distribute
47 # the binaries to a different machine you could also use: -march=native
49 CCOPT_x86= -march=i686 -msse -msse2 -mfpmath=sse
50 CCOPT_x64=
51 CCOPT_arm=
52 CCOPT_arm64=
53 CCOPT_ppc=
54 CCOPT_mips=
56 CCDEBUG=
57 # Uncomment the next line to generate debug information:
58 #CCDEBUG= -g
60 CCWARN= -Wall
61 # Uncomment the next line to enable more warnings:
62 #CCWARN+= -Wextra -Wdeclaration-after-statement -Wredundant-decls -Wshadow -Wpointer-arith
64 ##############################################################################
66 ##############################################################################
67 ################################ BUILD MODE ################################
68 ##############################################################################
69 # The default build mode is mixed mode on POSIX. On Windows this is the same
70 # as dynamic mode.
72 # Mixed mode creates a static + dynamic library and a statically linked luajit.
73 BUILDMODE= mixed
75 # Static mode creates a static library and a statically linked luajit.
76 #BUILDMODE= static
78 # Dynamic mode creates a dynamic library and a dynamically linked luajit.
79 # Note: this executable will only run when the library is installed!
80 #BUILDMODE= dynamic
82 ##############################################################################
84 ##############################################################################
85 ################################# FEATURES #################################
86 ##############################################################################
87 # Enable/disable these features as needed, but make sure you force a full
88 # recompile with "make clean", followed by "make".
89 XCFLAGS=
91 # Permanently disable the FFI extension to reduce the size of the LuaJIT
92 # executable. But please consider that the FFI library is compiled-in,
93 # but NOT loaded by default. It only allocates any memory, if you actually
94 # make use of it.
95 #XCFLAGS+= -DLUAJIT_DISABLE_FFI
97 # Features from Lua 5.2 that are unlikely to break existing code are
98 # enabled by default. Some other features that *might* break some existing
99 # code (e.g. __pairs or os.execute() return values) can be enabled here.
100 # Note: this does not provide full compatibility with Lua 5.2 at this time.
101 #XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
103 # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.
104 #XCFLAGS+= -DLUAJIT_DISABLE_JIT
106 # Some architectures (e.g. PPC) can use either single-number (1) or
107 # dual-number (2) mode. Uncomment one of these lines to override the
108 # default mode. Please see LJ_ARCH_NUMMODE in lj_arch.h for details.
109 #XCFLAGS+= -DLUAJIT_NUMMODE=1
110 #XCFLAGS+= -DLUAJIT_NUMMODE=2
112 # Disable LJ_GC64 mode for x64.
113 #XCFLAGS+= -DLUAJIT_DISABLE_GC64
115 ##############################################################################
117 ##############################################################################
118 ############################ DEBUGGING SUPPORT #############################
119 ##############################################################################
120 # Enable these options as needed, but make sure you force a full recompile
121 # with "make clean", followed by "make".
122 # Note that most of these are NOT suitable for benchmarking or release mode!
124 # Use the system provided memory allocator (realloc) instead of the
125 # bundled memory allocator. This is slower, but sometimes helpful for
126 # debugging. This option cannot be enabled on x64 without GC64, since
127 # realloc usually doesn't return addresses in the right address range.
128 # OTOH this option is mandatory for Valgrind's memcheck tool on x64 and
129 # the only way to get useful results from it for all other architectures.
130 #XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
132 # This define is required to run LuaJIT under Valgrind. The Valgrind
133 # header files must be installed. You should enable debug information, too.
134 #XCFLAGS+= -DLUAJIT_USE_VALGRIND
136 # This is the client for the GDB JIT API. GDB 7.0 or higher is required
137 # to make use of it. See lj_gdbjit.c for details. Enabling this causes
138 # a non-negligible overhead, even when not running under GDB.
139 #XCFLAGS+= -DLUAJIT_USE_GDBJIT
141 # Turn on assertions for the Lua/C API to debug problems with lua_* calls.
142 # This is rather slow -- use only while developing C libraries/embeddings.
143 #XCFLAGS+= -DLUA_USE_APICHECK
145 # Turn on assertions for the whole LuaJIT VM. This significantly slows down
146 # everything. Use only if you suspect a problem with LuaJIT itself.
147 #XCFLAGS+= -DLUA_USE_ASSERT
149 ##############################################################################
150 # You probably don't need to change anything below this line!
151 ##############################################################################
153 ##############################################################################
154 # Host system detection.
155 ##############################################################################
157 ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM))
158 HOST_SYS= Windows
159 else
160 HOST_SYS:= $(shell uname -s)
161 ifneq (,$(findstring MINGW,$(HOST_SYS)))
162 HOST_SYS= Windows
163 HOST_MSYS= mingw
164 endif
165 ifneq (,$(findstring MSYS,$(HOST_SYS)))
166 HOST_SYS= Windows
167 HOST_MSYS= mingw
168 endif
169 ifneq (,$(findstring CYGWIN,$(HOST_SYS)))
170 HOST_SYS= Windows
171 HOST_MSYS= cygwin
172 endif
173 endif
175 ##############################################################################
176 # Flags and options for host and target.
177 ##############################################################################
179 # You can override the following variables at the make command line:
180 # CC HOST_CC STATIC_CC DYNAMIC_CC
181 # CFLAGS HOST_CFLAGS TARGET_CFLAGS
182 # LDFLAGS HOST_LDFLAGS TARGET_LDFLAGS TARGET_SHLDFLAGS
183 # LIBS HOST_LIBS TARGET_LIBS
184 # CROSS HOST_SYS TARGET_SYS TARGET_FLAGS
186 # Cross-compilation examples:
187 # make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
188 # make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu-
190 ASOPTIONS= $(CCOPT) $(CCWARN) $(XCFLAGS) $(CFLAGS)
191 CCOPTIONS= $(CCDEBUG) $(ASOPTIONS)
192 LDOPTIONS= $(CCDEBUG) $(LDFLAGS)
194 HOST_CC= $(CC)
195 HOST_RM?= rm -f
196 # If left blank, minilua is built and used. You can supply an installed
197 # copy of (plain) Lua 5.1 or 5.2, plus Lua BitOp. E.g. with: HOST_LUA=lua
198 HOST_LUA=
200 HOST_XCFLAGS= -I.
201 HOST_XLDFLAGS=
202 HOST_XLIBS=
203 HOST_ACFLAGS= $(CCOPTIONS) $(HOST_XCFLAGS) $(TARGET_ARCH) $(HOST_CFLAGS)
204 HOST_ALDFLAGS= $(LDOPTIONS) $(HOST_XLDFLAGS) $(HOST_LDFLAGS)
205 HOST_ALIBS= $(HOST_XLIBS) $(LIBS) $(HOST_LIBS)
207 STATIC_CC = $(CROSS)$(CC)
208 DYNAMIC_CC = $(CROSS)$(CC) -fPIC
209 TARGET_CC= $(STATIC_CC)
210 TARGET_STCC= $(STATIC_CC)
211 TARGET_DYNCC= $(DYNAMIC_CC)
212 TARGET_LD= $(CROSS)$(CC)
213 TARGET_AR= $(CROSS)ar rcus
214 TARGET_STRIP= $(CROSS)strip
216 TARGET_LIBPATH= $(or $(PREFIX),/usr/local)/$(or $(MULTILIB),lib)
217 TARGET_SONAME= libluajit-$(ABIVER).so.$(MAJVER)
218 TARGET_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).dylib
219 TARGET_DYLIBPATH= $(TARGET_LIBPATH)/$(TARGET_DYLIBNAME)
220 TARGET_DLLNAME= lua$(NODOTABIVER).dll
221 TARGET_DLLDOTANAME= libluajit-$(ABIVER).dll.a
222 TARGET_XSHLDFLAGS= -shared -fPIC -Wl,-soname,$(TARGET_SONAME)
223 TARGET_DYNXLDOPTS=
225 TARGET_LFSFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
226 TARGET_XCFLAGS= $(TARGET_LFSFLAGS) -U_FORTIFY_SOURCE
227 TARGET_XLDFLAGS=
228 TARGET_XLIBS= -lm
229 TARGET_TCFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
230 TARGET_ACFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
231 TARGET_ASFLAGS= $(ASOPTIONS) $(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_ARM64 ,$(TARGET_TESTARCH)))
247 ifneq (,$(findstring __AARCH64EB__ ,$(TARGET_TESTARCH)))
248 TARGET_ARCH= -D__AARCH64EB__=1
249 endif
250 TARGET_LJARCH= arm64
251 else
252 ifneq (,$(findstring LJ_TARGET_PPC ,$(TARGET_TESTARCH)))
253 ifneq (,$(findstring LJ_LE 1,$(TARGET_TESTARCH)))
254 TARGET_ARCH= -DLJ_ARCH_ENDIAN=LUAJIT_LE
255 else
256 TARGET_ARCH= -DLJ_ARCH_ENDIAN=LUAJIT_BE
257 endif
258 TARGET_LJARCH= ppc
259 else
260 ifneq (,$(findstring LJ_TARGET_MIPS ,$(TARGET_TESTARCH)))
261 ifneq (,$(findstring MIPSEL ,$(TARGET_TESTARCH)))
262 TARGET_ARCH= -D__MIPSEL__=1
263 endif
264 ifneq (,$(findstring LJ_TARGET_MIPS64 ,$(TARGET_TESTARCH)))
265 TARGET_LJARCH= mips64
266 else
267 TARGET_LJARCH= mips
268 endif
269 else
270 $(error Unsupported target architecture)
271 endif
272 endif
273 endif
274 endif
275 endif
276 endif
278 ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH)))
279 TARGET_SYS= PS3
280 TARGET_ARCH+= -D__CELLOS_LV2__
281 TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
282 TARGET_XLIBS+= -lpthread
283 endif
285 TARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH))
286 TARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH))
288 ifneq (,$(PREFIX))
289 ifneq (/usr/local,$(PREFIX))
290 TARGET_XCFLAGS+= -DLUA_ROOT=\"$(PREFIX)\"
291 ifneq (/usr,$(PREFIX))
292 TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH)
293 endif
294 endif
295 endif
296 ifneq (,$(MULTILIB))
297 TARGET_XCFLAGS+= -DLUA_MULTILIB=\"$(MULTILIB)\"
298 endif
299 ifneq (,$(LMULTILIB))
300 TARGET_XCFLAGS+= -DLUA_LMULTILIB=\"$(LMULTILIB)\"
301 endif
303 ##############################################################################
304 # Target system detection.
305 ##############################################################################
307 TARGET_SYS?= $(HOST_SYS)
308 ifeq (Windows,$(TARGET_SYS))
309 TARGET_STRIP+= --strip-unneeded
310 TARGET_XSHLDFLAGS= -shared -Wl,--out-implib,$(TARGET_DLLDOTANAME)
311 TARGET_DYNXLDOPTS=
312 else
313 TARGET_AR+= 2>/dev/null
314 ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1))
315 TARGET_XCFLAGS+= -fno-stack-protector
316 endif
317 ifeq (Darwin,$(TARGET_SYS))
318 ifeq (,$(MACOSX_DEPLOYMENT_TARGET))
319 $(error missing: export MACOSX_DEPLOYMENT_TARGET=XX.YY)
320 endif
321 TARGET_STRIP+= -x
322 TARGET_XCFLAGS+= -DLUAJIT_UNWIND_EXTERNAL
323 TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
324 TARGET_DYNXLDOPTS=
325 TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).255
326 else
327 ifeq (iOS,$(TARGET_SYS))
328 TARGET_STRIP+= -x
329 TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
330 TARGET_DYNXLDOPTS=
331 TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).255
332 ifeq (arm64,$(TARGET_LJARCH))
333 TARGET_XCFLAGS+= -fno-omit-frame-pointer
334 endif
335 else
336 ifeq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))
337 # Find out whether the target toolchain always generates unwind tables.
338 TARGET_TESTUNWIND=$(shell exec 2>/dev/null; echo 'extern void b(void);int a(void){b();return 0;}' | $(TARGET_CC) -c -x c - -o tmpunwind.o && { grep -qa -e eh_frame -e __unwind_info tmpunwind.o || grep -qU -e eh_frame -e __unwind_info tmpunwind.o; } && echo E; rm -f tmpunwind.o)
339 ifneq (,$(findstring E,$(TARGET_TESTUNWIND)))
340 TARGET_XCFLAGS+= -DLUAJIT_UNWIND_EXTERNAL
341 endif
342 endif
343 ifneq (SunOS,$(TARGET_SYS))
344 ifneq (PS3,$(TARGET_SYS))
345 TARGET_XLDFLAGS+= -Wl,-E
346 endif
347 endif
348 ifeq (Linux,$(TARGET_SYS))
349 TARGET_XLIBS+= -ldl
350 endif
351 ifeq (GNU/kFreeBSD,$(TARGET_SYS))
352 TARGET_XLIBS+= -ldl
353 endif
354 endif
355 endif
356 endif
358 ifneq ($(HOST_SYS),$(TARGET_SYS))
359 ifeq (Windows,$(TARGET_SYS))
360 HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS
361 else
362 ifeq (Linux,$(TARGET_SYS))
363 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX
364 else
365 ifeq (Darwin,$(TARGET_SYS))
366 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
367 else
368 ifeq (iOS,$(TARGET_SYS))
369 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX -DTARGET_OS_IPHONE=1
370 else
371 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER
372 endif
373 endif
374 endif
375 endif
376 endif
378 ifneq (,$(CCDEBUG))
379 TARGET_STRIP= @:
380 endif
382 ##############################################################################
383 # Files and pathnames.
384 ##############################################################################
386 MINILUA_O= host/minilua.o
387 MINILUA_LIBS= -lm
388 MINILUA_T= host/minilua
389 MINILUA_X= $(MINILUA_T)
390 MINILUA_DEP=
392 ifeq (,$(HOST_LUA))
393 HOST_LUA= $(MINILUA_X)
394 MINILUA_DEP= $(MINILUA_T)
395 endif
397 DASM_DIR= ../dynasm
398 DASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua
399 DASM_XFLAGS=
400 DASM_AFLAGS=
401 DASM_ARCH= $(TARGET_LJARCH)
403 ifneq (,$(findstring LJ_LE 1,$(TARGET_TESTARCH)))
404 DASM_AFLAGS+= -D ENDIAN_LE
405 else
406 DASM_AFLAGS+= -D ENDIAN_BE
407 endif
408 ifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH)))
409 DASM_AFLAGS+= -D P64
410 endif
411 ifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH)))
412 DASM_AFLAGS+= -D JIT
413 endif
414 ifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH)))
415 DASM_AFLAGS+= -D FFI
416 endif
417 ifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH)))
418 DASM_AFLAGS+= -D DUALNUM
419 endif
420 ifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH)))
421 DASM_AFLAGS+= -D FPU
422 TARGET_ARCH+= -DLJ_ARCH_HASFPU=1
423 else
424 TARGET_ARCH+= -DLJ_ARCH_HASFPU=0
425 endif
426 ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH)))
427 DASM_AFLAGS+= -D HFABI
428 TARGET_ARCH+= -DLJ_ABI_SOFTFP=0
429 else
430 TARGET_ARCH+= -DLJ_ABI_SOFTFP=1
431 endif
432 ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))
433 DASM_AFLAGS+= -D NO_UNWIND
434 TARGET_ARCH+= -DLUAJIT_NO_UNWIND
435 endif
436 ifneq (,$(findstring LJ_ABI_PAUTH 1,$(TARGET_TESTARCH)))
437 DASM_AFLAGS+= -D PAUTH
438 TARGET_ARCH+= -DLJ_ABI_PAUTH=1
439 endif
440 DASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH))))
441 ifeq (Windows,$(TARGET_SYS))
442 DASM_AFLAGS+= -D WIN
443 endif
444 ifeq (x64,$(TARGET_LJARCH))
445 ifeq (,$(findstring LJ_FR2 1,$(TARGET_TESTARCH)))
446 DASM_ARCH= x86
447 endif
448 else
449 ifeq (arm,$(TARGET_LJARCH))
450 ifeq (iOS,$(TARGET_SYS))
451 DASM_AFLAGS+= -D IOS
452 endif
453 else
454 ifneq (,$(findstring LJ_TARGET_MIPSR6 ,$(TARGET_TESTARCH)))
455 DASM_AFLAGS+= -D MIPSR6
456 endif
457 ifeq (ppc,$(TARGET_LJARCH))
458 ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH)))
459 DASM_AFLAGS+= -D SQRT
460 endif
461 ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH)))
462 DASM_AFLAGS+= -D ROUND
463 endif
464 ifneq (,$(findstring LJ_ARCH_PPC32ON64 1,$(TARGET_TESTARCH)))
465 DASM_AFLAGS+= -D GPR64
466 endif
467 ifeq (PS3,$(TARGET_SYS))
468 DASM_AFLAGS+= -D PPE -D TOC
469 endif
470 endif
471 endif
472 endif
474 DASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS)
475 DASM_DASC= vm_$(DASM_ARCH).dasc
477 GIT= git
478 ifeq (Windows,$(HOST_SYS)$(HOST_MSYS))
479 GIT_RELVER= if exist ..\.git ( $(GIT) show -s --format=%%ct >luajit_relver.txt ) else ( type ..\.relver >luajit_relver.txt )
480 else
481 GIT_RELVER= [ -e ../.git ] && $(GIT) show -s --format=%ct >luajit_relver.txt 2>/dev/null || cat ../.relver >luajit_relver.txt 2>/dev/null || :
482 endif
483 GIT_DEP= $(wildcard ../.git/HEAD ../.git/refs/heads/*)
485 BUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \
486 host/buildvm_lib.o host/buildvm_fold.o
487 BUILDVM_T= host/buildvm
488 BUILDVM_X= $(BUILDVM_T)
490 HOST_O= $(MINILUA_O) $(BUILDVM_O)
491 HOST_T= $(MINILUA_T) $(BUILDVM_T)
493 LJVM_S= lj_vm.S
494 LJVM_O= lj_vm.o
495 LJVM_BOUT= $(LJVM_S)
496 LJVM_MODE= elfasm
498 LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
499 lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o \
500 lib_buffer.o
501 LJLIB_C= $(LJLIB_O:.o=.c)
503 LJCORE_O= lj_assert.o lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o lj_buf.o \
504 lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \
505 lj_prng.o lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o \
506 lj_strscan.o lj_strfmt.o lj_strfmt_num.o lj_serialize.o \
507 lj_api.o lj_profile.o \
508 lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \
509 lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
510 lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \
511 lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \
512 lj_asm.o lj_trace.o lj_gdbjit.o \
513 lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \
514 lj_carith.o lj_clib.o lj_cparse.o \
515 lj_lib.o lj_alloc.o lib_aux.o \
516 $(LJLIB_O) lib_init.o
518 LJVMCORE_O= $(LJVM_O) $(LJCORE_O)
519 LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o)
521 LIB_VMDEF= jit/vmdef.lua
522 LIB_VMDEFP= $(LIB_VMDEF)
524 LUAJIT_O= luajit.o
525 LUAJIT_A= libluajit.a
526 LUAJIT_SO= libluajit.so
527 LUAJIT_T= luajit
529 ALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T)
530 ALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \
531 host/buildvm_arch.h luajit.h
532 ALL_GEN= $(LJVM_S) $(ALL_HDRGEN) luajit_relver.txt $(LIB_VMDEFP)
533 WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk
534 ALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM)
536 ##############################################################################
537 # Build mode handling.
538 ##############################################################################
540 # Mixed mode defaults.
541 TARGET_O= $(LUAJIT_A)
542 TARGET_T= $(LUAJIT_T) $(LUAJIT_SO)
543 TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO)
545 ifeq (Windows,$(TARGET_SYS))
546 TARGET_DYNCC= $(STATIC_CC)
547 LJVM_MODE= peobj
548 LJVM_BOUT= $(LJVM_O)
549 LUAJIT_T= luajit.exe
550 ifeq (cygwin,$(HOST_MSYS))
551 LUAJIT_SO= cyg$(TARGET_DLLNAME)
552 else
553 LUAJIT_SO= $(TARGET_DLLNAME)
554 endif
555 # Mixed mode is not supported on Windows. And static mode doesn't work well.
556 # C modules cannot be loaded, because they bind to lua51.dll.
557 ifneq (static,$(BUILDMODE))
558 BUILDMODE= dynamic
559 TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL
560 endif
561 endif
562 ifeq (Darwin,$(TARGET_SYS))
563 LJVM_MODE= machasm
564 endif
565 ifeq (iOS,$(TARGET_SYS))
566 LJVM_MODE= machasm
567 endif
568 ifeq (SunOS,$(TARGET_SYS))
569 BUILDMODE= static
570 endif
571 ifeq (PS3,$(TARGET_SYS))
572 BUILDMODE= static
573 endif
575 ifeq (Windows,$(HOST_SYS))
576 MINILUA_T= host/minilua.exe
577 BUILDVM_T= host/buildvm.exe
578 ifeq (,$(HOST_MSYS))
579 MINILUA_X= host\minilua
580 BUILDVM_X= host\buildvm
581 ALL_RM:= $(subst /,\,$(ALL_RM))
582 HOST_RM= del
583 endif
584 endif
586 ifeq (static,$(BUILDMODE))
587 TARGET_DYNCC= @:
588 TARGET_T= $(LUAJIT_T)
589 TARGET_DEP= $(LIB_VMDEF)
590 else
591 ifeq (dynamic,$(BUILDMODE))
592 ifneq (Windows,$(TARGET_SYS))
593 TARGET_CC= $(DYNAMIC_CC)
594 endif
595 TARGET_DYNCC= @:
596 LJVMCORE_DYNO= $(LJVMCORE_O)
597 TARGET_O= $(LUAJIT_SO)
598 TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS)
599 else
600 ifeq (Darwin,$(TARGET_SYS))
601 TARGET_DYNCC= @:
602 LJVMCORE_DYNO= $(LJVMCORE_O)
603 endif
604 ifeq (iOS,$(TARGET_SYS))
605 TARGET_DYNCC= @:
606 LJVMCORE_DYNO= $(LJVMCORE_O)
607 endif
608 endif
609 endif
611 Q= @
612 E= @echo
614 #E= @:
616 ##############################################################################
617 # Make targets.
618 ##############################################################################
620 default all: $(TARGET_T)
622 amalg:
623 $(MAKE) all "LJCORE_O=ljamalg.o"
625 clean:
626 $(HOST_RM) $(ALL_RM)
628 libbc:
629 ./$(LUAJIT_T) host/genlibbc.lua -o host/buildvm_libbc.h $(LJLIB_C)
630 $(MAKE) all
632 depend:
633 @for file in $(ALL_HDRGEN); do \
634 test -f $$file || touch $$file; \
635 done
636 @$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \
637 sed -e "s| [^ ]*/dasm_\S*\.h||g" \
638 -e "s|^\([^l ]\)|host/\1|" \
639 -e "s| lj_target_\S*\.h| lj_target_*.h|g" \
640 -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \
641 -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep
642 @for file in $(ALL_HDRGEN); do \
643 test -s $$file || $(HOST_RM) $$file; \
644 done
646 .PHONY: default all amalg clean libbc depend
648 ##############################################################################
649 # Rules for generated files.
650 ##############################################################################
652 $(MINILUA_T): $(MINILUA_O)
653 $(E) "HOSTLINK $@"
654 $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS)
656 luajit.h: $(MINILUA_DEP) $(GIT_DEP) luajit_rolling.h
657 $(E) "VERSION $@"
658 $(Q)$(GIT_RELVER)
659 $(Q)$(HOST_LUA) host/genversion.lua
661 host/buildvm_arch.h: $(DASM_DASC) $(MINILUA_DEP) lj_arch.h lua.h luaconf.h
662 $(E) "DYNASM $@"
663 $(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC)
665 host/buildvm.o: $(DASM_DIR)/dasm_*.h
667 $(BUILDVM_T): $(BUILDVM_O)
668 $(E) "HOSTLINK $@"
669 $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS)
671 $(LJVM_BOUT): $(BUILDVM_T)
672 $(E) "BUILDVM $@"
673 $(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@
675 lj_bcdef.h: $(BUILDVM_T) $(LJLIB_C)
676 $(E) "BUILDVM $@"
677 $(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C)
679 lj_ffdef.h: $(BUILDVM_T) $(LJLIB_C)
680 $(E) "BUILDVM $@"
681 $(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C)
683 lj_libdef.h: $(BUILDVM_T) $(LJLIB_C)
684 $(E) "BUILDVM $@"
685 $(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C)
687 lj_recdef.h: $(BUILDVM_T) $(LJLIB_C)
688 $(E) "BUILDVM $@"
689 $(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C)
691 $(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C)
692 $(E) "BUILDVM $@"
693 $(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C)
695 lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c
696 $(E) "BUILDVM $@"
697 $(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c
699 ##############################################################################
700 # Object file rules.
701 ##############################################################################
703 %.o: %.c
704 $(E) "CC $@"
705 $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<
706 $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<
708 %.o: %.S
709 $(E) "ASM $@"
710 $(Q)$(TARGET_DYNCC) $(TARGET_ASFLAGS) -c -o $(@:.o=_dyn.o) $<
711 $(Q)$(TARGET_CC) $(TARGET_ASFLAGS) -c -o $@ $<
713 $(LUAJIT_O):
714 $(E) "CC $@"
715 $(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -c -o $@ $<
717 $(HOST_O): %.o: %.c
718 $(E) "HOSTCC $@"
719 $(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<
721 include Makefile.dep
723 ##############################################################################
724 # Target file rules.
725 ##############################################################################
727 $(LUAJIT_A): $(LJVMCORE_O)
728 $(E) "AR $@"
729 $(Q)$(TARGET_AR) $@ $(LJVMCORE_O)
731 # The dependency on _O, but linking with _DYNO is intentional.
732 $(LUAJIT_SO): $(LJVMCORE_O)
733 $(E) "DYNLINK $@"
734 $(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS)
735 $(Q)$(TARGET_STRIP) $@
737 $(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP)
738 $(E) "LINK $@"
739 $(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS)
740 $(Q)$(TARGET_STRIP) $@
741 $(E) "OK Successfully built LuaJIT"
743 ##############################################################################