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