Makefile (25932B)
1 # Shortcut to enable common debug flags and verbose echo of Makefile steps 2 # better just use `make DEBUG=1` 3 #DEBUG=1 4 VERSION:=$(shell git describe 2> /dev/null || cat ../.version) 5 6 ################################################################################ 7 # The C ABI to be compatible with. Legal values are 5.1/5.2/5.3 8 # 9 # Note that this switch does not influence the version reported, nor how 10 # Lua actually behaves - it is only for C API binary compatibility 11 # (as in "drop in DLL replacement"). This way, you can still have 5.3 lua 12 # in something expecting Lua 5.1 on binary level. 13 # 14 # Additionaly, C API features of all Lua versions are still available despite 15 # having lower version ABI (though inevitably, those will be compatible on 16 # source level only). It is also possible to do the opposite thing - use 5.3 ABI, 17 # and compile modules expecting 5.1-like header. 18 # 19 # See ENABLE_LUA5XCOMPAT to actually enforce particular version of the language. 20 # can be passed by parent makefile 21 ABIVER ?= 5.2 22 APIVER ?= $(ABIVER) 23 NODOTABIVER:=$(subst .,,$(ABIVER)) 24 ################################################################################ 25 26 XCFLAGS= #This variable collects varios options below 27 28 ################################################################################ 29 # By default, LJX behaves mostly as Lua 5.2, and also reports as that version. 30 # 31 # Where there is no direct conflict, 5.1 and 5.2 features are mixed. For 32 # example setfenv() and _ENV are fully cross-compatible. In case of conflicting 33 # semantics, 5.2 is favored over 5.1. 34 # 35 # This is not always desirable, though. If you enable LUA51COMPAT, it will 36 # unconditionally disable 5.2/5.3 features (such as _ENV, __pairs and __gc) 37 # which can conflict with Lua 5.1 code. It will also report _VERSION as Lua 5.1. 38 # 39 # This will make LJX behave pretty much like stock LuaJIT. 40 ifeq (5.1,$(APIVER)) 41 XCFLAGS+= -DLUAJIT_ENABLE_LUA51COMPAT 42 endif 43 ################################################################################ 44 45 ################################################################################ 46 # Enable Lua 5.3 features. Bitwise operators and some parts of standard 47 # library. Will report _VERSION as 5.3 48 ifeq (5.3,$(APIVER)) 49 XCFLAGS+= -DLUAJIT_ENABLE_LUA53COMPAT 50 endif 51 ################################################################################ 52 53 ################################################################################ 54 # WIP, NOT WORKING, DONT USE 55 # Support (up to) 4GB memory. This is accomplished by using OS-supplied 56 # malloc(), instead of custom allocators. Note that the host process must 57 # reside at low address, as heap which grows upwards directly follows it. 58 # 59 # This means disabling ASLR on windows and linux. If no suitable memory layout 60 # is detected, LJX will switch to the original, more controllable 2GB allocator. 61 # You can disable ASLR on windows with: 62 # $ make TARGET_LDFLAGS=-fno-pie 63 #XCFLAGS+=-DLUAJIT_ENABLE_4GB 64 ################################################################################ 65 66 ############################################################################## 67 ############################# COMPILER OPTIONS ############################# 68 ############################################################################## 69 # These options mainly affect the speed of the JIT compiler itself, not the 70 # speed of the JIT-compiled code. Turn any of the optional settings on by 71 # removing the '#' in front of them. Make sure you force a full recompile 72 # with "make clean", followed by "make" if you change any options. 73 # 74 DEFAULT_CC = gcc 75 # 76 # LuaJIT builds as a native 32 or 64 bit binary by default. 77 CC= $(DEFAULT_CC) 78 # 79 # Use this if you want to force a 32 bit build on a 64 bit multilib OS. 80 #CC= $(DEFAULT_CC) -m32 81 # 82 # Since the assembler part does NOT maintain a frame pointer, it's pointless 83 # to slow down the C part by not omitting it. Debugging, tracebacks and 84 # unwinding are not affected -- the assembler part has frame unwind 85 # information and GCC emits it where needed (x64) or with -g (see CCDEBUG). 86 CCOPT= -fomit-frame-pointer 87 ifeq (,$(DEBUG)) 88 #CCOPT+= -Os 89 CCOPT+= -O2 90 endif 91 # Use this if you want to generate a smaller binary (but it's slower): 92 #CCOPT= -Os -fomit-frame-pointer 93 # Note: it's no longer recommended to use -O3 with GCC 4.x. 94 # The I-Cache bloat usually outweighs the benefits from aggressive inlining. 95 # 96 # Target-specific compiler options: 97 # 98 # x86/x64 only: For GCC 4.2 or higher and if you don't intend to distribute 99 # the binaries to a different machine you could also use: -march=native 100 # 101 CCOPT_x86= -march=i686 -msse -msse2 -mfpmath=sse 102 CCOPT_x64= 103 CCOPT_arm= 104 CCOPT_arm64= 105 CCOPT_ppc= 106 CCOPT_mips= 107 # 108 ifneq (,$(DEBUG)) 109 CCDEBUG= -g -ggdb 110 else 111 CCDEBUG= 112 endif 113 # 114 CCWARN= -Wall 115 # Uncomment the next line to enable more warnings: 116 #CCWARN+= -Wextra -Wdeclaration-after-statement -Wredundant-decls -Wshadow -Wpointer-arith 117 # 118 ############################################################################## 119 120 ############################################################################## 121 ################################ BUILD MODE ################################ 122 ############################################################################## 123 # The default build mode is mixed mode on POSIX. On Windows this is the same 124 # as dynamic mode. 125 # 126 # Mixed mode creates a static + dynamic library and a statically linked luajit. 127 BUILDMODE= mixed 128 # 129 # Static mode creates a static library and a statically linked luajit. 130 #BUILDMODE= static 131 # 132 # Dynamic mode creates a dynamic library and a dynamically linked luajit. 133 # Note: this executable will only run when the library is installed! 134 #BUILDMODE= dynamic 135 # 136 ############################################################################## 137 138 ############################################################################## 139 ################################# FEATURES ################################# 140 ############################################################################## 141 # Enable/disable these features as needed, but make sure you force a full 142 # recompile with "make clean", followed by "make". 143 # 144 # Permanently disable the FFI extension to reduce the size of the LuaJIT 145 # executable. But please consider that the FFI library is compiled-in, 146 # but NOT loaded by default. It only allocates any memory, if you actually 147 # make use of it. 148 #XCFLAGS+= -DLUAJIT_DISABLE_FFI 149 # 150 # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter. 151 #XCFLAGS+= -DLUAJIT_DISABLE_JIT 152 # 153 # Superficially pretend to be stock Lua (supress ljx/luajit banners). 154 # XCFLAGS+= -DLUAJIT_PRETEND_RIO 155 # 156 # Some architectures (e.g. PPC) can use either single-number (1) or 157 # dual-number (2) mode. Uncomment one of these lines to override the 158 # default mode. Please see LJ_ARCH_NUMMODE in lj_arch.h for details. 159 #XCFLAGS+= -DLUAJIT_NUMMODE=1 160 #XCFLAGS+= -DLUAJIT_NUMMODE=2 161 # 162 ############################################################################## 163 164 ############################################################################## 165 ############################ DEBUGGING SUPPORT ############################# 166 ############################################################################## 167 # Enable these options as needed, but make sure you force a full recompile 168 # with "make clean", followed by "make". 169 # Note that most of these are NOT suitable for benchmarking or release mode! 170 # 171 # Use the system provided memory allocator (realloc) instead of the 172 # bundled memory allocator. This is slower, but sometimes helpful for 173 # debugging. This option cannot be enabled on x64 without GC64, since 174 # realloc usually doesn't return addresses in the right address range. 175 # OTOH this option is mandatory for Valgrind's memcheck tool on x64 and 176 # the only way to get useful results from it for all other architectures. 177 # XCFLAGS+= -DLUAJIT_USE_SYSMALLOC 178 # 179 # This define is required to run LuaJIT under Valgrind. The Valgrind 180 # header files must be installed. You should enable debug information, too. 181 # Use --suppressions=lj.supp to avoid some false positives. 182 #XCFLAGS+= -DLUAJIT_USE_VALGRIND 183 # 184 # This is the client for the GDB JIT API. GDB 7.0 or higher is required 185 # to make use of it. See lj_gdbjit.c for details. Enabling this causes 186 # a non-negligible overhead, even when not running under GDB. 187 #XCFLAGS+= -DLUAJIT_USE_GDBJIT 188 # 189 # Turn on assertions for the Lua/C API to debug problems with lua_* calls. 190 # This is rather slow -- use only while developing C libraries/embeddings. 191 #XCFLAGS+= -DLUA_USE_APICHECK 192 # 193 # Turn on assertions for the whole LuaJIT VM. This significantly slows down 194 # everything. Use only if you suspect a problem with LuaJIT itself. 195 # XCFLAGS+= -DLUA_USE_ASSERT 196 ifneq (,$(DEBUG)) 197 # Those are always useful without affecting runtime too much. 198 XCFLAGS+= -DLUA_USE_ASSERT -DLUA_USE_APICHECK 199 endif 200 # 201 ############################################################################## 202 # You probably don't need to change anything below this line! 203 ############################################################################## 204 205 ############################################################################## 206 # Host system detection. 207 ############################################################################## 208 209 ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM)) 210 HOST_SYS= Windows 211 HOST_RM= del 212 else 213 HOST_SYS:= $(shell uname -s) 214 ifneq (,$(findstring MINGW,$(HOST_SYS))) 215 HOST_SYS= Windows 216 HOST_MSYS= mingw 217 endif 218 ifneq (,$(findstring CYGWIN,$(HOST_SYS))) 219 HOST_SYS= Windows 220 HOST_MSYS= cygwin 221 endif 222 ifneq (,$(findstring MSYS,$(HOST_SYS))) 223 HOST_SYS= Windows 224 HOST_MSYS= msys 225 endif 226 # Use Clang for OSX host. 227 ifeq (Darwin,$(HOST_SYS)) 228 DEFAULT_CC= clang 229 endif 230 endif 231 232 ############################################################################## 233 # Flags and options for host and target. 234 ############################################################################## 235 236 # You can override the following variables at the make command line: 237 # CC HOST_CC STATIC_CC DYNAMIC_CC 238 # CFLAGS HOST_CFLAGS TARGET_CFLAGS 239 # LDFLAGS HOST_LDFLAGS TARGET_LDFLAGS TARGET_SHLDFLAGS 240 # LIBS HOST_LIBS TARGET_LIBS 241 # CROSS HOST_SYS TARGET_SYS TARGET_FLAGS 242 # 243 # Cross-compilation examples: 244 # make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows 245 # make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu- 246 XCFLAGS+=-DLJX_VERSION=\"$(VERSION)\" 247 248 ASOPTIONS= $(CCOPT) $(CCWARN) $(XCFLAGS) $(CFLAGS) 249 CCOPTIONS= $(CCDEBUG) $(ASOPTIONS) 250 LDOPTIONS= $(CCDEBUG) $(LDFLAGS) 251 252 HOST_CC= $(CC) 253 HOST_RM= rm -f 254 # If left blank, minilua is built and used. You can supply an installed 255 # copy of (plain) Lua 5.1 or 5.2, plus Lua BitOp. E.g. with: HOST_LUA=lua 256 HOST_LUA= 257 258 HOST_XCFLAGS= -I. 259 HOST_XLDFLAGS= 260 HOST_XLIBS= 261 HOST_ACFLAGS= $(CCOPTIONS) $(HOST_XCFLAGS) $(TARGET_ARCH) $(HOST_CFLAGS) 262 HOST_ALDFLAGS= $(LDOPTIONS) $(HOST_XLDFLAGS) $(HOST_LDFLAGS) 263 HOST_ALIBS= $(HOST_XLIBS) $(LIBS) $(HOST_LIBS) 264 265 STATIC_CC = $(CROSS)$(CC) 266 DYNAMIC_CC = $(CROSS)$(CC) -fPIC 267 TARGET_CC= $(STATIC_CC) 268 TARGET_STCC= $(STATIC_CC) 269 TARGET_DYNCC= $(DYNAMIC_CC) 270 TARGET_LD= $(CROSS)$(CC) 271 TARGET_AR= $(CROSS)ar rcus 272 TARGET_STRIP= $(CROSS)strip 273 274 TARGET_LIBPATH= $(or $(PREFIX),/usr/local)/$(or $(MULTILIB),lib) 275 TARGET_SONAME= libluajit-ljx-$(ABIVER).so.$(VERSION) 276 TARGET_DYLIBNAME= libluajit-ljx-$(ABIVER).$(VERSION).dylib 277 TARGET_DYLIBPATH= $(TARGET_LIBPATH)/$(TARGET_DYLIBNAME) 278 TARGET_DLLNAME := lua$(NODOTABIVER).dll 279 TARGET_XSHLDFLAGS= -shared -fPIC -Wl,-soname,$(TARGET_SONAME) 280 TARGET_DYNXLDOPTS= 281 282 TARGET_LFSFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 283 TARGET_XCFLAGS= $(TARGET_LFSFLAGS) -DLJ_ABIVER=$(NODOTABIVER) -U_FORTIFY_SOURCE 284 TARGET_XLDFLAGS= 285 TARGET_XLIBS= -lm 286 TARGET_XTLIBS= 287 TARGET_TCFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS) 288 TARGET_ACFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS) 289 TARGET_ASFLAGS= $(ASOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS) 290 TARGET_ALDFLAGS= $(LDOPTIONS) $(TARGET_XLDFLAGS) $(TARGET_FLAGS) $(TARGET_LDFLAGS) 291 TARGET_ASHLDFLAGS= $(LDOPTIONS) $(TARGET_XSHLDFLAGS) $(TARGET_FLAGS) $(TARGET_SHLDFLAGS) 292 TARGET_ALIBS= $(TARGET_XLIBS) $(LIBS) $(TARGET_LIBS) 293 294 TARGET_TESTARCH=$(shell $(TARGET_CC) $(TARGET_TCFLAGS) -E lj_arch.h -dM) 295 ifneq (,$(findstring LJ_TARGET_X64 ,$(TARGET_TESTARCH))) 296 TARGET_LJARCH= x64 297 else 298 ifneq (,$(findstring LJ_TARGET_X86 ,$(TARGET_TESTARCH))) 299 TARGET_LJARCH= x86 300 else 301 ifneq (,$(findstring LJ_TARGET_ARM ,$(TARGET_TESTARCH))) 302 TARGET_LJARCH= arm 303 else 304 ifneq (,$(findstring LJ_TARGET_ARM64 ,$(TARGET_TESTARCH))) 305 TARGET_LJARCH= arm64 306 else 307 ifneq (,$(findstring LJ_TARGET_PPC ,$(TARGET_TESTARCH))) 308 ifneq (,$(findstring LJ_LE 1,$(TARGET_TESTARCH))) 309 TARGET_ARCH= -DLJ_ARCH_ENDIAN=LUAJIT_LE 310 else 311 TARGET_ARCH= -DLJ_ARCH_ENDIAN=LUAJIT_BE 312 endif 313 TARGET_LJARCH= ppc 314 else 315 ifneq (,$(findstring LJ_TARGET_MIPS ,$(TARGET_TESTARCH))) 316 ifneq (,$(findstring MIPSEL ,$(TARGET_TESTARCH))) 317 TARGET_ARCH= -D__MIPSEL__=1 318 endif 319 ifneq (,$(findstring LJ_TARGET_MIPS64 ,$(TARGET_TESTARCH))) 320 TARGET_LJARCH= mips64 321 else 322 TARGET_LJARCH= mips 323 endif 324 else 325 $(error Unsupported target architecture) 326 endif 327 endif 328 endif 329 endif 330 endif 331 endif 332 333 ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH))) 334 TARGET_SYS= PS3 335 TARGET_ARCH+= -D__CELLOS_LV2__ 336 TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC 337 TARGET_XLIBS+= -lpthread 338 endif 339 340 TARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH)) 341 TARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH)) 342 343 ifneq (,$(PREFIX)) 344 ifneq (/usr/local,$(PREFIX)) 345 TARGET_XCFLAGS+= -DLUA_ROOT=\"$(PREFIX)\" 346 ifneq (/usr,$(PREFIX)) 347 TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH) 348 endif 349 endif 350 endif 351 ifneq (,$(MULTILIB)) 352 TARGET_XCFLAGS+= -DLUA_MULTILIB=\"$(MULTILIB)\" 353 endif 354 ifneq (,$(LMULTILIB)) 355 TARGET_XCFLAGS+= -DLUA_LMULTILIB=\"$(LMULTILIB)\" 356 endif 357 358 ############################################################################## 359 # Target system detection. 360 ############################################################################## 361 362 TARGET_SYS?= $(HOST_SYS) 363 ifeq (Windows,$(TARGET_SYS)) 364 TARGET_STRIP+= --strip-unneeded 365 TARGET_XSHLDFLAGS= -shared 366 TARGET_DYNXLDOPTS= 367 else 368 ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1)) 369 TARGET_XCFLAGS+= -fno-stack-protector 370 endif 371 ifeq (Darwin,$(TARGET_SYS)) 372 ifeq (,$(MACOSX_DEPLOYMENT_TARGET)) 373 export MACOSX_DEPLOYMENT_TARGET=10.4 374 endif 375 TARGET_STRIP+= -x 376 TARGET_AR+= 2>/dev/null 377 TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC 378 TARGET_DYNXLDOPTS= 379 TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version LJX -current_version $(VERSION) 380 ifeq (x64,$(TARGET_LJARCH)) 381 TARGET_XLDFLAGS+= -pagezero_size 10000 -image_base 100000000 382 TARGET_XSHLDFLAGS+= -image_base 7fff04c4a000 383 endif 384 else 385 ifeq (iOS,$(TARGET_SYS)) 386 TARGET_STRIP+= -x 387 TARGET_AR+= 2>/dev/null 388 TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC 389 TARGET_DYNXLDOPTS= 390 TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version LJX -current_version $(VERSION) 391 ifeq (arm64,$(TARGET_LJARCH)) 392 TARGET_XCFLAGS+= -fno-omit-frame-pointer 393 endif 394 else 395 ifneq (SunOS,$(TARGET_SYS)) 396 ifneq (PS3,$(TARGET_SYS)) 397 TARGET_XLDFLAGS+= -Wl,-E 398 endif 399 endif 400 ifeq (Linux,$(TARGET_SYS)) 401 TARGET_XLIBS+= -ldl -lreadline 402 endif 403 ifeq (GNU/kFreeBSD,$(TARGET_SYS)) 404 TARGET_XLIBS+= -ldl -lreadline 405 endif 406 endif 407 endif 408 endif 409 410 ifneq ($(HOST_SYS),$(TARGET_SYS)) 411 ifeq (Windows,$(TARGET_SYS)) 412 HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS 413 else 414 ifeq (Linux,$(TARGET_SYS)) 415 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX 416 else 417 ifeq (Darwin,$(TARGET_SYS)) 418 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX 419 else 420 ifeq (iOS,$(TARGET_SYS)) 421 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX 422 else 423 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER 424 endif 425 endif 426 endif 427 endif 428 endif 429 430 ifneq (,$(CCDEBUG)) 431 TARGET_STRIP= @: 432 endif 433 434 ############################################################################## 435 # Files and pathnames. 436 ############################################################################## 437 438 MINILUA_O= host/minilua.o 439 MINILUA_LIBS= -lm 440 MINILUA_T= host/minilua 441 MINILUA_X= $(MINILUA_T) 442 443 ifeq (,$(HOST_LUA)) 444 HOST_LUA= $(MINILUA_X) 445 DASM_DEP= $(MINILUA_T) 446 endif 447 448 DASM_DIR= ../dynasm 449 DASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua 450 DASM_XFLAGS= 451 DASM_AFLAGS= 452 DASM_ARCH= $(TARGET_LJARCH) 453 454 ifneq (,$(findstring LJ_LE 1,$(TARGET_TESTARCH))) 455 DASM_AFLAGS+= -D ENDIAN_LE 456 else 457 DASM_AFLAGS+= -D ENDIAN_BE 458 endif 459 ifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH))) 460 DASM_AFLAGS+= -D P64 461 endif 462 ifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH))) 463 DASM_AFLAGS+= -D JIT 464 endif 465 ifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH))) 466 DASM_AFLAGS+= -D FFI 467 endif 468 ifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH))) 469 DASM_AFLAGS+= -D DUALNUM 470 endif 471 ifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH))) 472 DASM_AFLAGS+= -D FPU 473 TARGET_ARCH+= -DLJ_ARCH_HASFPU=1 474 else 475 TARGET_ARCH+= -DLJ_ARCH_HASFPU=0 476 endif 477 ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH))) 478 DASM_AFLAGS+= -D HFABI 479 TARGET_ARCH+= -DLJ_ABI_SOFTFP=0 480 else 481 TARGET_ARCH+= -DLJ_ABI_SOFTFP=1 482 endif 483 ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH))) 484 DASM_AFLAGS+= -D NO_UNWIND 485 TARGET_ARCH+= -DLUAJIT_NO_UNWIND 486 endif 487 DASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH)))) 488 ifeq (Windows,$(TARGET_SYS)) 489 DASM_AFLAGS+= -D WIN 490 endif 491 ifeq (x64,$(TARGET_LJARCH)) 492 ifeq (,$(findstring LJ_FR2 1,$(TARGET_TESTARCH))) 493 DASM_ARCH= x86 494 endif 495 else 496 ifeq (arm,$(TARGET_LJARCH)) 497 ifeq (iOS,$(TARGET_SYS)) 498 DASM_AFLAGS+= -D IOS 499 endif 500 else 501 ifeq (ppc,$(TARGET_LJARCH)) 502 ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH))) 503 DASM_AFLAGS+= -D SQRT 504 endif 505 ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH))) 506 DASM_AFLAGS+= -D ROUND 507 endif 508 ifneq (,$(findstring LJ_ARCH_PPC32ON64 1,$(TARGET_TESTARCH))) 509 DASM_AFLAGS+= -D GPR64 510 endif 511 ifeq (PS3,$(TARGET_SYS)) 512 DASM_AFLAGS+= -D PPE -D TOC 513 endif 514 ifneq (,$(findstring LJ_ARCH_PPC64 ,$(TARGET_TESTARCH))) 515 DASM_ARCH= ppc64 516 endif 517 endif 518 endif 519 endif 520 521 DASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS) 522 DASM_DASC= vm_$(DASM_ARCH).dasc 523 524 BUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \ 525 host/buildvm_lib.o host/buildvm_fold.o 526 BUILDVM_T= host/buildvm 527 BUILDVM_X= $(BUILDVM_T) 528 529 HOST_O= $(MINILUA_O) $(BUILDVM_O) 530 HOST_T= $(MINILUA_T) $(BUILDVM_T) 531 532 LJVM_S= lj_vm.S 533 LJVM_O= lj_vm.o 534 LJVM_BOUT= $(LJVM_S) 535 LJVM_MODE= elfasm 536 537 LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_utf8.o lib_table.o \ 538 lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o 539 LJLIB_C= $(LJLIB_O:.o=.c) 540 541 LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o lj_buf.o \ 542 lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \ 543 lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o lj_strscan.o \ 544 lj_strfmt.o lj_strfmt_num.o lj_api.o lj_profile.o \ 545 lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \ 546 lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \ 547 lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \ 548 lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \ 549 lj_asm.o lj_trace.o lj_gdbjit.o \ 550 lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \ 551 lj_carith.o ljx_bitwise.o lj_clib.o lj_cparse.o \ 552 lj_lib.o lj_alloc.o lib_aux.o \ 553 $(LJLIB_O) lib_init.o 554 555 LJVMCORE_O= $(LJVM_O) $(LJCORE_O) 556 LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o) 557 558 LIB_VMDEF= jit/vmdef.lua 559 LIB_VMDEFP= $(LIB_VMDEF) 560 561 LUAJIT_O= luajit.o 562 LUAJIT_A= libluajit-ljx.a 563 LUAJIT_SO= libluajit-ljx.so 564 LUAJIT_T= luajit-ljx 565 566 ALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T) 567 ALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \ 568 host/buildvm_arch.h lj_arch.h.dist 569 ALL_GEN= $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP) 570 WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk 571 ALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM) 572 573 ############################################################################## 574 # Build mode handling. 575 ############################################################################## 576 577 # Mixed mode defaults. 578 TARGET_O= $(LUAJIT_A) 579 TARGET_T= $(LUAJIT_T) $(LUAJIT_SO) 580 TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO) 581 582 ifeq (Windows,$(TARGET_SYS)) 583 TARGET_DYNCC= $(STATIC_CC) 584 LJVM_MODE= peobj 585 LJVM_BOUT= $(LJVM_O) 586 LUAJIT_T= luajit.exe 587 ifeq (cygwin,$(HOST_MSYS)) 588 LUAJIT_SO= cyg$(TARGET_DLLNAME) 589 endif 590 ifeq (msys,$(HOST_MSYS)) 591 TARGET_XTLIBS+= -lreadline 592 LUAJIT_SO= $(TARGET_DLLNAME) 593 endif 594 ifeq (mingw,$(HOST_MSYS)) 595 TARGET_XTLIBS+= -Wl,-Bstatic -lreadline -ltermcap 596 LUAJIT_SO= $(TARGET_DLLNAME) 597 endif 598 # Mixed mode is not supported on Windows. And static mode doesn't work well. 599 # C modules cannot be loaded, because they bind to lua51.dll. 600 ifneq (static,$(BUILDMODE)) 601 BUILDMODE= dynamic 602 TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL 603 endif 604 endif 605 ifeq (Darwin,$(TARGET_SYS)) 606 LJVM_MODE= machasm 607 endif 608 ifeq (iOS,$(TARGET_SYS)) 609 LJVM_MODE= machasm 610 endif 611 ifeq (SunOS,$(TARGET_SYS)) 612 BUILDMODE= static 613 endif 614 ifeq (PS3,$(TARGET_SYS)) 615 BUILDMODE= static 616 endif 617 618 ifeq (Windows,$(HOST_SYS)) 619 MINILUA_T= host/minilua.exe 620 BUILDVM_T= host/buildvm.exe 621 ifeq (,$(HOST_MSYS)) 622 MINILUA_X= host\minilua 623 BUILDVM_X= host\buildvm 624 ALL_RM:= $(subst /,\,$(ALL_RM)) 625 endif 626 endif 627 628 ifeq (static,$(BUILDMODE)) 629 TARGET_DYNCC= @: 630 TARGET_T= $(LUAJIT_T) 631 TARGET_DEP= $(LIB_VMDEF) 632 else 633 ifeq (dynamic,$(BUILDMODE)) 634 ifneq (Windows,$(TARGET_SYS)) 635 TARGET_CC= $(DYNAMIC_CC) 636 endif 637 TARGET_DYNCC= @: 638 LJVMCORE_DYNO= $(LJVMCORE_O) 639 TARGET_O= $(LUAJIT_SO) 640 TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS) 641 else 642 ifeq (Darwin,$(TARGET_SYS)) 643 TARGET_DYNCC= @: 644 LJVMCORE_DYNO= $(LJVMCORE_O) 645 endif 646 ifeq (iOS,$(TARGET_SYS)) 647 TARGET_DYNCC= @: 648 LJVMCORE_DYNO= $(LJVMCORE_O) 649 endif 650 endif 651 endif 652 653 ifeq (,$(DEBUG)) 654 Q= @ 655 E= @echo 656 else 657 Q= 658 E= @: 659 endif 660 661 ############################################################################## 662 # Make targets. 663 ############################################################################## 664 665 default all: $(TARGET_T) lj_arch.h.dist 666 667 amalg: 668 @grep "^[+|]" ljamalg.c 669 $(MAKE) all "LJCORE_O=ljamalg.o" 670 671 clean: 672 $(HOST_RM) $(ALL_RM) 673 674 libbc: 675 ./$(LUAJIT_T) host/genlibbc.lua -o host/buildvm_libbc.h $(LJLIB_C) 676 $(MAKE) all 677 678 depend: 679 @for file in $(ALL_HDRGEN); do \ 680 test -f $$file || touch $$file; \ 681 done 682 @$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \ 683 sed -e "s| [^ ]*/dasm_\S*\.h||g" \ 684 -e "s|^\([^l ]\)|host/\1|" \ 685 -e "s| lj_target_\S*\.h| lj_target_*.h|g" \ 686 -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \ 687 -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep 688 @for file in $(ALL_HDRGEN); do \ 689 test -s $$file || $(HOST_RM) $$file; \ 690 done 691 692 .PHONY: default all amalg clean libbc depend 693 694 ############################################################################## 695 # Rules for generated files. 696 ############################################################################## 697 698 $(MINILUA_T): $(MINILUA_O) 699 $(E) "HOSTLINK $@" 700 $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS) 701 702 host/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP) $(DASM_DIR)/*.lua 703 $(E) "DYNASM $@" 704 $(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC) 705 706 host/buildvm.o: $(DASM_DIR)/dasm_*.h 707 708 $(BUILDVM_T): $(BUILDVM_O) 709 $(E) "HOSTLINK $@" 710 $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS) 711 712 $(LJVM_BOUT): $(BUILDVM_T) 713 $(E) "BUILDVM $@" 714 $(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@ 715 716 lj_bcdef.h: $(BUILDVM_T) $(LJLIB_C) 717 $(E) "BUILDVM $@" 718 $(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C) 719 720 lj_ffdef.h: $(BUILDVM_T) $(LJLIB_C) 721 $(E) "BUILDVM $@" 722 $(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C) 723 724 lj_libdef.h: $(BUILDVM_T) $(LJLIB_C) 725 $(E) "BUILDVM $@" 726 $(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C) 727 728 lj_recdef.h: $(BUILDVM_T) $(LJLIB_C) 729 $(E) "BUILDVM $@" 730 $(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C) 731 732 $(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C) 733 $(E) "BUILDVM $@" 734 $(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C) 735 736 lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c 737 $(E) "BUILDVM $@" 738 $(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c 739 740 lj_arch.h.dist: lj_arch.h 741 $(E) "ARCH $@" 742 $(Q)$(CC) -dM -E lj_arch.h $(TARGET_ACFLAGS) | egrep '#define (LUAJIT_|LJ_)' > lj_arch.h.dist 743 744 ############################################################################## 745 # Object file rules. 746 ############################################################################## 747 748 %.o: %.c 749 $(E) "CC $@" 750 $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $< 751 $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $< 752 753 %.o: %.S 754 $(E) "ASM $@" 755 $(Q)$(TARGET_DYNCC) $(TARGET_ASFLAGS) -c -o $(@:.o=_dyn.o) $< 756 $(Q)$(TARGET_CC) $(TARGET_ASFLAGS) -c -o $@ $< 757 758 $(LUAJIT_O): 759 $(E) "CC $@" 760 $(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -DLUA_CREDITS="\"$(shell cat ../CREDITS | sed -e 's/$$/\\n/g' | tr -d '\n')\"" -c -o $@ $< 761 762 $(HOST_O): %.o: %.c 763 $(E) "HOSTCC $@" 764 $(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $< 765 766 include Makefile.dep 767 768 ############################################################################## 769 # Target file rules. 770 ############################################################################## 771 772 $(LUAJIT_A): $(LJVMCORE_O) 773 $(E) "AR $@" 774 $(Q)$(TARGET_AR) $@ $(LJVMCORE_O) 775 776 # The dependency on _O, but linking with _DYNO is intentional. 777 $(LUAJIT_SO): $(LJVMCORE_O) 778 $(E) "DYNLINK $@" 779 $(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS) 780 $(Q)$(TARGET_STRIP) $@ 781 782 $(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP) 783 $(E) "LINK $@" 784 $(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS) $(TARGET_XTLIBS) 785 $(Q)$(TARGET_STRIP) $@ 786 $(E) "OK Successfully built LuaJIT/$(VERSION)" 787 788 ##############################################################################