Drop unused function wrapper.
[luajit-2.0.git] / src / Makefile
blob43238912ab3a542d9162d20dfa924c137bc3364e
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
302 ifneq (,$(INSTALL_LJLIBD))
303 TARGET_XCFLAGS+= -DLUA_LJDIR=\"$(INSTALL_LJLIBD)\"
304 endif
306 ##############################################################################
307 # Target system detection.
308 ##############################################################################
310 TARGET_SYS?= $(HOST_SYS)
311 ifeq (Windows,$(TARGET_SYS))
312 TARGET_STRIP+= --strip-unneeded
313 TARGET_XSHLDFLAGS= -shared -Wl,--out-implib,$(TARGET_DLLDOTANAME)
314 TARGET_DYNXLDOPTS=
315 else
316 TARGET_AR+= 2>/dev/null
317 ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1))
318 TARGET_XCFLAGS+= -fno-stack-protector
319 endif
320 ifeq (Darwin,$(TARGET_SYS))
321 ifeq (,$(MACOSX_DEPLOYMENT_TARGET))
322 $(error missing: export MACOSX_DEPLOYMENT_TARGET=XX.YY)
323 endif
324 TARGET_STRIP+= -x
325 TARGET_XCFLAGS+= -DLUAJIT_UNWIND_EXTERNAL
326 TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
327 TARGET_DYNXLDOPTS=
328 TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).255
329 else
330 ifeq (iOS,$(TARGET_SYS))
331 TARGET_STRIP+= -x
332 TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
333 TARGET_DYNXLDOPTS=
334 TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).255
335 ifeq (arm64,$(TARGET_LJARCH))
336 TARGET_XCFLAGS+= -fno-omit-frame-pointer
337 endif
338 else
339 ifeq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))
340 # Find out whether the target toolchain always generates unwind tables.
341 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)
342 ifneq (,$(findstring E,$(TARGET_TESTUNWIND)))
343 TARGET_XCFLAGS+= -DLUAJIT_UNWIND_EXTERNAL
344 endif
345 endif
346 ifneq (SunOS,$(TARGET_SYS))
347 ifneq (PS3,$(TARGET_SYS))
348 TARGET_XLDFLAGS+= -Wl,-E
349 endif
350 endif
351 ifeq (Linux,$(TARGET_SYS))
352 TARGET_XLIBS+= -ldl
353 endif
354 ifeq (GNU/kFreeBSD,$(TARGET_SYS))
355 TARGET_XLIBS+= -ldl
356 endif
357 endif
358 endif
359 endif
361 ifneq ($(HOST_SYS),$(TARGET_SYS))
362 ifeq (Windows,$(TARGET_SYS))
363 HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS
364 else
365 ifeq (Linux,$(TARGET_SYS))
366 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX
367 else
368 ifeq (Darwin,$(TARGET_SYS))
369 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
370 else
371 ifeq (iOS,$(TARGET_SYS))
372 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX -DTARGET_OS_IPHONE=1
373 else
374 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER
375 endif
376 endif
377 endif
378 endif
379 endif
381 ifneq (,$(CCDEBUG))
382 TARGET_STRIP= @:
383 endif
385 ##############################################################################
386 # Files and pathnames.
387 ##############################################################################
389 MINILUA_O= host/minilua.o
390 MINILUA_LIBS= -lm
391 MINILUA_T= host/minilua
392 MINILUA_X= $(MINILUA_T)
393 MINILUA_DEP=
395 ifeq (,$(HOST_LUA))
396 HOST_LUA= $(MINILUA_X)
397 MINILUA_DEP= $(MINILUA_T)
398 endif
400 DASM_DIR= ../dynasm
401 DASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua
402 DASM_XFLAGS=
403 DASM_AFLAGS=
404 DASM_ARCH= $(TARGET_LJARCH)
406 ifneq (,$(findstring LJ_LE 1,$(TARGET_TESTARCH)))
407 DASM_AFLAGS+= -D ENDIAN_LE
408 else
409 DASM_AFLAGS+= -D ENDIAN_BE
410 endif
411 ifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH)))
412 DASM_AFLAGS+= -D P64
413 endif
414 ifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH)))
415 DASM_AFLAGS+= -D JIT
416 endif
417 ifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH)))
418 DASM_AFLAGS+= -D FFI
419 endif
420 ifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH)))
421 DASM_AFLAGS+= -D DUALNUM
422 endif
423 ifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH)))
424 DASM_AFLAGS+= -D FPU
425 TARGET_ARCH+= -DLJ_ARCH_HASFPU=1
426 else
427 TARGET_ARCH+= -DLJ_ARCH_HASFPU=0
428 endif
429 ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH)))
430 DASM_AFLAGS+= -D HFABI
431 TARGET_ARCH+= -DLJ_ABI_SOFTFP=0
432 else
433 TARGET_ARCH+= -DLJ_ABI_SOFTFP=1
434 endif
435 ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))
436 DASM_AFLAGS+= -D NO_UNWIND
437 TARGET_ARCH+= -DLUAJIT_NO_UNWIND
438 endif
439 ifneq (,$(findstring LJ_ABI_PAUTH 1,$(TARGET_TESTARCH)))
440 DASM_AFLAGS+= -D PAUTH
441 TARGET_ARCH+= -DLJ_ABI_PAUTH=1
442 endif
443 DASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH))))
444 ifeq (Windows,$(TARGET_SYS))
445 DASM_AFLAGS+= -D WIN
446 endif
447 ifeq (x64,$(TARGET_LJARCH))
448 ifeq (,$(findstring LJ_FR2 1,$(TARGET_TESTARCH)))
449 DASM_ARCH= x86
450 endif
451 else
452 ifeq (arm,$(TARGET_LJARCH))
453 ifeq (iOS,$(TARGET_SYS))
454 DASM_AFLAGS+= -D IOS
455 endif
456 else
457 ifneq (,$(findstring LJ_TARGET_MIPSR6 ,$(TARGET_TESTARCH)))
458 DASM_AFLAGS+= -D MIPSR6
459 endif
460 ifeq (ppc,$(TARGET_LJARCH))
461 ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH)))
462 DASM_AFLAGS+= -D SQRT
463 endif
464 ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH)))
465 DASM_AFLAGS+= -D ROUND
466 endif
467 ifneq (,$(findstring LJ_ARCH_PPC32ON64 1,$(TARGET_TESTARCH)))
468 DASM_AFLAGS+= -D GPR64
469 endif
470 ifeq (PS3,$(TARGET_SYS))
471 DASM_AFLAGS+= -D PPE -D TOC
472 endif
473 endif
474 endif
475 endif
477 DASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS)
478 DASM_DASC= vm_$(DASM_ARCH).dasc
480 GIT= git
481 ifeq (Windows,$(HOST_SYS)$(HOST_MSYS))
482 GIT_RELVER= if exist ..\.git ( $(GIT) show -s --format=%%ct >luajit_relver.txt ) else ( type ..\.relver >luajit_relver.txt )
483 else
484 GIT_RELVER= [ -e ../.git ] && $(GIT) show -s --format=%ct >luajit_relver.txt 2>/dev/null || cat ../.relver >luajit_relver.txt 2>/dev/null || :
485 endif
486 GIT_DEP= $(wildcard ../.git/HEAD ../.git/refs/heads/*)
488 BUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \
489 host/buildvm_lib.o host/buildvm_fold.o
490 BUILDVM_T= host/buildvm
491 BUILDVM_X= $(BUILDVM_T)
493 HOST_O= $(MINILUA_O) $(BUILDVM_O)
494 HOST_T= $(MINILUA_T) $(BUILDVM_T)
496 LJVM_S= lj_vm.S
497 LJVM_O= lj_vm.o
498 LJVM_BOUT= $(LJVM_S)
499 LJVM_MODE= elfasm
501 LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
502 lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o \
503 lib_buffer.o
504 LJLIB_C= $(LJLIB_O:.o=.c)
506 LJCORE_O= lj_assert.o lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o lj_buf.o \
507 lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \
508 lj_prng.o lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o \
509 lj_strscan.o lj_strfmt.o lj_strfmt_num.o lj_serialize.o \
510 lj_api.o lj_profile.o \
511 lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \
512 lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
513 lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \
514 lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \
515 lj_asm.o lj_trace.o lj_gdbjit.o \
516 lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \
517 lj_carith.o lj_clib.o lj_cparse.o \
518 lj_lib.o lj_alloc.o lib_aux.o \
519 $(LJLIB_O) lib_init.o
521 LJVMCORE_O= $(LJVM_O) $(LJCORE_O)
522 LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o)
524 LIB_VMDEF= jit/vmdef.lua
525 LIB_VMDEFP= $(LIB_VMDEF)
527 LUAJIT_O= luajit.o
528 LUAJIT_A= libluajit.a
529 LUAJIT_SO= libluajit.so
530 LUAJIT_T= luajit
532 ALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T)
533 ALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \
534 host/buildvm_arch.h luajit.h
535 ALL_GEN= $(LJVM_S) $(ALL_HDRGEN) luajit_relver.txt $(LIB_VMDEFP)
536 WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk
537 ALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM)
539 ##############################################################################
540 # Build mode handling.
541 ##############################################################################
543 # Mixed mode defaults.
544 TARGET_O= $(LUAJIT_A)
545 TARGET_T= $(LUAJIT_T) $(LUAJIT_SO)
546 TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO)
548 ifeq (Windows,$(TARGET_SYS))
549 TARGET_DYNCC= $(STATIC_CC)
550 LJVM_MODE= peobj
551 LJVM_BOUT= $(LJVM_O)
552 LUAJIT_T= luajit.exe
553 ifeq (cygwin,$(HOST_MSYS))
554 LUAJIT_SO= cyg$(TARGET_DLLNAME)
555 else
556 LUAJIT_SO= $(TARGET_DLLNAME)
557 endif
558 # Mixed mode is not supported on Windows. And static mode doesn't work well.
559 # C modules cannot be loaded, because they bind to lua51.dll.
560 ifneq (static,$(BUILDMODE))
561 BUILDMODE= dynamic
562 TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL
563 endif
564 endif
565 ifeq (Darwin,$(TARGET_SYS))
566 LJVM_MODE= machasm
567 endif
568 ifeq (iOS,$(TARGET_SYS))
569 LJVM_MODE= machasm
570 endif
571 ifeq (SunOS,$(TARGET_SYS))
572 BUILDMODE= static
573 endif
574 ifeq (PS3,$(TARGET_SYS))
575 BUILDMODE= static
576 endif
578 ifeq (Windows,$(HOST_SYS))
579 MINILUA_T= host/minilua.exe
580 BUILDVM_T= host/buildvm.exe
581 ifeq (,$(HOST_MSYS))
582 MINILUA_X= host\minilua
583 BUILDVM_X= host\buildvm
584 ALL_RM:= $(subst /,\,$(ALL_RM))
585 HOST_RM= del
586 endif
587 endif
589 ifeq (static,$(BUILDMODE))
590 TARGET_DYNCC= @:
591 TARGET_T= $(LUAJIT_T)
592 TARGET_DEP= $(LIB_VMDEF)
593 else
594 ifeq (dynamic,$(BUILDMODE))
595 ifneq (Windows,$(TARGET_SYS))
596 TARGET_CC= $(DYNAMIC_CC)
597 endif
598 TARGET_DYNCC= @:
599 LJVMCORE_DYNO= $(LJVMCORE_O)
600 TARGET_O= $(LUAJIT_SO)
601 TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS)
602 else
603 ifeq (Darwin,$(TARGET_SYS))
604 TARGET_DYNCC= @:
605 LJVMCORE_DYNO= $(LJVMCORE_O)
606 endif
607 ifeq (iOS,$(TARGET_SYS))
608 TARGET_DYNCC= @:
609 LJVMCORE_DYNO= $(LJVMCORE_O)
610 endif
611 endif
612 endif
614 Q= @
615 E= @echo
617 #E= @:
619 ##############################################################################
620 # Make targets.
621 ##############################################################################
623 default all: $(TARGET_T)
625 amalg:
626 $(MAKE) all "LJCORE_O=ljamalg.o"
628 clean:
629 $(HOST_RM) $(ALL_RM)
631 libbc:
632 ./$(LUAJIT_T) host/genlibbc.lua -o host/buildvm_libbc.h $(LJLIB_C)
633 $(MAKE) all
635 depend:
636 @for file in $(ALL_HDRGEN); do \
637 test -f $$file || touch $$file; \
638 done
639 @$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \
640 sed -e "s| [^ ]*/dasm_\S*\.h||g" \
641 -e "s|^\([^l ]\)|host/\1|" \
642 -e "s| lj_target_\S*\.h| lj_target_*.h|g" \
643 -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \
644 -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep
645 @for file in $(ALL_HDRGEN); do \
646 test -s $$file || $(HOST_RM) $$file; \
647 done
649 .PHONY: default all amalg clean libbc depend
651 ##############################################################################
652 # Rules for generated files.
653 ##############################################################################
655 $(MINILUA_T): $(MINILUA_O)
656 $(E) "HOSTLINK $@"
657 $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS)
659 luajit.h: $(MINILUA_DEP) $(GIT_DEP) luajit_rolling.h
660 $(E) "VERSION $@"
661 $(Q)$(GIT_RELVER)
662 $(Q)$(HOST_LUA) host/genversion.lua
664 host/buildvm_arch.h: $(DASM_DASC) $(MINILUA_DEP) lj_arch.h lua.h luaconf.h
665 $(E) "DYNASM $@"
666 $(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC)
668 host/buildvm.o: $(DASM_DIR)/dasm_*.h
670 $(BUILDVM_T): $(BUILDVM_O)
671 $(E) "HOSTLINK $@"
672 $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS)
674 $(LJVM_BOUT): $(BUILDVM_T)
675 $(E) "BUILDVM $@"
676 $(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@
678 lj_bcdef.h: $(BUILDVM_T) $(LJLIB_C)
679 $(E) "BUILDVM $@"
680 $(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C)
682 lj_ffdef.h: $(BUILDVM_T) $(LJLIB_C)
683 $(E) "BUILDVM $@"
684 $(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C)
686 lj_libdef.h: $(BUILDVM_T) $(LJLIB_C)
687 $(E) "BUILDVM $@"
688 $(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C)
690 lj_recdef.h: $(BUILDVM_T) $(LJLIB_C)
691 $(E) "BUILDVM $@"
692 $(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C)
694 $(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C)
695 $(E) "BUILDVM $@"
696 $(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C)
698 lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c
699 $(E) "BUILDVM $@"
700 $(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c
702 ##############################################################################
703 # Object file rules.
704 ##############################################################################
706 %.o: %.c
707 $(E) "CC $@"
708 $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<
709 $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<
711 %.o: %.S
712 $(E) "ASM $@"
713 $(Q)$(TARGET_DYNCC) $(TARGET_ASFLAGS) -c -o $(@:.o=_dyn.o) $<
714 $(Q)$(TARGET_CC) $(TARGET_ASFLAGS) -c -o $@ $<
716 $(LUAJIT_O):
717 $(E) "CC $@"
718 $(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -c -o $@ $<
720 $(HOST_O): %.o: %.c
721 $(E) "HOSTCC $@"
722 $(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<
724 include Makefile.dep
726 ##############################################################################
727 # Target file rules.
728 ##############################################################################
730 $(LUAJIT_A): $(LJVMCORE_O)
731 $(E) "AR $@"
732 $(Q)$(TARGET_AR) $@ $(LJVMCORE_O)
734 # The dependency on _O, but linking with _DYNO is intentional.
735 $(LUAJIT_SO): $(LJVMCORE_O)
736 $(E) "DYNLINK $@"
737 $(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS)
738 $(Q)$(TARGET_STRIP) $@
740 $(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP)
741 $(E) "LINK $@"
742 $(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS)
743 $(Q)$(TARGET_STRIP) $@
744 $(E) "OK Successfully built LuaJIT"
746 ##############################################################################