From Lua 5.2: Add package.loadlib(libname, "*").
[luajit-2.0.git] / src / Makefile
blob278324a18b76c4a8c11152e03252af17ce5a613c
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-2012 Mike Pall. See Copyright Notice in luajit.h
11 ##############################################################################
13 MAJVER= 2
14 MINVER= 0
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 only: it's recommended to compile at least for i686. Better yet,
46 # compile for an architecture that has SSE2, too (-msse -msse2).
48 # x86/x64 only: For GCC 4.2 or higher and if you don't intend to distribute
49 # the binaries to a different machine you could also use: -march=native
51 CCOPT_x86= -march=i686
52 CCOPT_x64=
53 CCOPT_arm=
54 CCOPT_ppc=
55 CCOPT_ppcspe=
56 CCOPT_mips=
58 CCDEBUG=
59 # Uncomment the next line to generate debug information:
60 #CCDEBUG= -g
62 CCWARN= -Wall
63 # Uncomment the next line to enable more warnings:
64 #CCWARN+= -Wextra -Wdeclaration-after-statement -Wredundant-decls -Wshadow -Wpointer-arith
66 ##############################################################################
68 ##############################################################################
69 ################################ BUILD MODE ################################
70 ##############################################################################
71 # The default build mode is mixed mode on POSIX. On Windows this is the same
72 # as dynamic mode.
74 # Mixed mode creates a static + dynamic library and a statically linked luajit.
75 BUILDMODE= mixed
77 # Static mode creates a static library and a statically linked luajit.
78 #BUILDMODE= static
80 # Dynamic mode creates a dynamic library and a dynamically linked luajit.
81 # Note: this executable will only run when the library is installed!
82 #BUILDMODE= dynamic
84 ##############################################################################
86 ##############################################################################
87 ################################# FEATURES #################################
88 ##############################################################################
89 # Enable/disable these features as needed, but make sure you force a full
90 # recompile with "make clean", followed by "make".
91 XCFLAGS=
93 # Permanently disable the FFI extension to reduce the size of the LuaJIT
94 # executable. But please consider that the FFI library is compiled-in,
95 # but NOT loaded by default. It only allocates any memory, if you actually
96 # make use of it.
97 #XCFLAGS+= -DLUAJIT_DISABLE_FFI
99 # Features from Lua 5.2 that are unlikely to break existing code are
100 # enabled by default. Some other features that *might* break some existing
101 # code (e.g. __pairs or os.execute() return values) can be enabled here.
102 # Note: this does not provide full compatibility with Lua 5.2 at this time.
103 #XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
105 # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.
106 #XCFLAGS+= -DLUAJIT_DISABLE_JIT
108 # Some architectures (e.g. PPC) can use either single-number (1) or
109 # dual-number (2) mode. Uncomment one of these lines to override the
110 # default mode. Please see LJ_ARCH_NUMMODE in lj_arch.h for details.
111 #XCFLAGS+= -DLUAJIT_NUMMODE=1
112 #XCFLAGS+= -DLUAJIT_NUMMODE=2
114 ##############################################################################
116 ##############################################################################
117 ############################ DEBUGGING SUPPORT #############################
118 ##############################################################################
119 # Enable these options as needed, but make sure you force a full recompile
120 # with "make clean", followed by "make".
121 # Note that most of these are NOT suitable for benchmarking or release mode!
123 # Use the system provided memory allocator (realloc) instead of the
124 # bundled memory allocator. This is slower, but sometimes helpful for
125 # debugging. It's helpful for Valgrind's memcheck tool, too. This option
126 # cannot be enabled on x64, since the built-in allocator is mandatory.
127 #XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
129 # This define is required to run LuaJIT under Valgrind. The Valgrind
130 # header files must be installed. You should enable debug information, too.
131 # Use --suppressions=lj.supp to avoid some false positives.
132 #XCFLAGS+= -DLUAJIT_USE_VALGRIND
134 # This is the client for the GDB JIT API. GDB 7.0 or higher is required
135 # to make use of it. See lj_gdbjit.c for details. Enabling this causes
136 # a non-negligible overhead, even when not running under GDB.
137 #XCFLAGS+= -DLUAJIT_USE_GDBJIT
139 # Turn on assertions for the Lua/C API to debug problems with lua_* calls.
140 # This is rather slow -- use only while developing C libraries/embeddings.
141 #XCFLAGS+= -DLUA_USE_APICHECK
143 # Turn on assertions for the whole LuaJIT VM. This significantly slows down
144 # everything. Use only if you suspect a problem with LuaJIT itself.
145 #XCFLAGS+= -DLUA_USE_ASSERT
147 ##############################################################################
148 # You probably don't need to change anything below this line!
149 ##############################################################################
151 ##############################################################################
152 # Flags and options for host and target.
153 ##############################################################################
155 # You can override the following variables at the make command line:
156 # CC HOST_CC STATIC_CC DYNAMIC_CC
157 # CFLAGS HOST_CFLAGS TARGET_CFLAGS
158 # LDFLAGS HOST_LDFLAGS TARGET_LDFLAGS TARGET_SHLDFLAGS
159 # LIBS HOST_LIBS TARGET_LIBS
160 # CROSS HOST_SYS TARGET_SYS TARGET_FLAGS
162 # Cross-compilation examples:
163 # make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
164 # make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu-
166 CCOPTIONS= $(CCDEBUG) $(CCOPT) $(CCWARN) $(XCFLAGS) $(CFLAGS)
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_SONAME= libluajit-$(ABIVER).so.$(MAJVER)
192 TARGET_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).dylib
193 TARGET_DYLIBPATH= $(or $(PREFIX),/usr/local)/lib/$(TARGET_DYLIBNAME)
194 TARGET_DLLNAME= lua$(NODOTABIVER).dll
195 TARGET_XSHLDFLAGS= -shared -fPIC -Wl,-soname,$(TARGET_SONAME)
196 TARGET_DYNXLDOPTS=
198 TARGET_LFSFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
199 TARGET_XCFLAGS= $(TARGET_LFSFLAGS) -U_FORTIFY_SOURCE
200 TARGET_XLDFLAGS=
201 TARGET_XLIBS= -lm
202 TARGET_TCFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
203 TARGET_ACFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
204 TARGET_ALDFLAGS= $(LDOPTIONS) $(TARGET_XLDFLAGS) $(TARGET_FLAGS) $(TARGET_LDFLAGS)
205 TARGET_ASHLDFLAGS= $(LDOPTIONS) $(TARGET_XSHLDFLAGS) $(TARGET_FLAGS) $(TARGET_SHLDFLAGS)
206 TARGET_ALIBS= $(TARGET_XLIBS) $(LIBS) $(TARGET_LIBS)
208 TARGET_TESTARCH=$(shell $(TARGET_CC) $(TARGET_TCFLAGS) -E lj_arch.h -dM)
209 ifneq (,$(findstring LJ_TARGET_X64 ,$(TARGET_TESTARCH)))
210 TARGET_LJARCH= x64
211 else
212 ifneq (,$(findstring LJ_TARGET_X86 ,$(TARGET_TESTARCH)))
213 TARGET_LJARCH= x86
214 else
215 ifneq (,$(findstring LJ_TARGET_ARM ,$(TARGET_TESTARCH)))
216 TARGET_LJARCH= arm
217 else
218 ifneq (,$(findstring LJ_TARGET_PPC ,$(TARGET_TESTARCH)))
219 TARGET_LJARCH= ppc
220 else
221 ifneq (,$(findstring LJ_TARGET_PPCSPE ,$(TARGET_TESTARCH)))
222 TARGET_LJARCH= ppcspe
223 else
224 ifneq (,$(findstring LJ_TARGET_MIPS ,$(TARGET_TESTARCH)))
225 ifneq (,$(findstring MIPSEL ,$(TARGET_TESTARCH)))
226 TARGET_ARCH= -D__MIPSEL__=1
227 endif
228 TARGET_LJARCH= mips
229 else
230 $(error Unsupported target architecture)
231 endif
232 endif
233 endif
234 endif
235 endif
236 endif
238 ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH)))
239 TARGET_SYS= PS3
240 TARGET_ARCH+= -D__CELLOS_LV2__
241 TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
242 endif
243 ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))
244 TARGET_ARCH+= -DLUAJIT_NO_UNWIND
245 endif
247 TARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH))
248 TARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH))
250 ifneq (,$(PREFIX))
251 ifneq (/usr/local,$(PREFIX))
252 TARGET_XCFLAGS+= -DLUA_XROOT=\"$(PREFIX)/\"
253 ifneq (/usr,$(PREFIX))
254 TARGET_DYNXLDOPTS= -Wl,-rpath,$(PREFIX)/lib
255 endif
256 endif
257 endif
259 ##############################################################################
260 # System detection.
261 ##############################################################################
263 ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM))
264 HOST_SYS= Windows
265 HOST_RM= del
266 else
267 HOST_SYS:= $(shell uname -s)
268 ifneq (,$(findstring MINGW,$(HOST_SYS)))
269 HOST_SYS= Windows
270 HOST_MSYS= mingw
271 endif
272 ifneq (,$(findstring CYGWIN,$(HOST_SYS)))
273 HOST_SYS= Windows
274 HOST_MSYS= cygwin
275 endif
276 endif
278 TARGET_SYS?= $(HOST_SYS)
279 ifeq (Windows,$(TARGET_SYS))
280 TARGET_STRIP+= --strip-unneeded
281 TARGET_XSHLDFLAGS= -shared
282 TARGET_DYNXLDOPTS=
283 else
284 ifeq (Darwin,$(TARGET_SYS))
285 ifeq (,$(MACOSX_DEPLOYMENT_TARGET))
286 export MACOSX_DEPLOYMENT_TARGET=10.4
287 endif
288 TARGET_STRIP+= -x
289 TARGET_AR+= 2>/dev/null
290 TARGET_XCFLAGS+= -fno-stack-protector
291 TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
292 TARGET_DYNXLDOPTS=
293 TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
294 ifeq (x64,$(TARGET_LJARCH))
295 TARGET_XLDFLAGS+= -pagezero_size 10000 -image_base 100000000
296 TARGET_XSHLDFLAGS+= -image_base 7fff04c4a000
297 endif
298 else
299 ifeq (iOS,$(TARGET_SYS))
300 TARGET_STRIP+= -x
301 TARGET_AR+= 2>/dev/null
302 TARGET_XCFLAGS+= -fno-stack-protector
303 TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
304 TARGET_DYNXLDOPTS=
305 TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
306 else
307 ifneq (,$(findstring stack-protector,$(shell $(TARGET_CC) -dumpspecs)))
308 TARGET_XCFLAGS+= -fno-stack-protector
309 endif
310 ifneq (SunOS,$(TARGET_SYS))
311 ifneq (PS3,$(TARGET_SYS))
312 TARGET_XLDFLAGS+= -Wl,-E
313 endif
314 endif
315 ifeq (Linux,$(TARGET_SYS))
316 TARGET_XLIBS+= -ldl
317 endif
318 ifeq (GNU/kFreeBSD,$(TARGET_SYS))
319 TARGET_XLIBS+= -ldl
320 endif
321 endif
322 endif
323 endif
325 ifneq ($(HOST_SYS),$(TARGET_SYS))
326 ifeq (Windows,$(TARGET_SYS))
327 HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS
328 else
329 ifeq (Linux,$(TARGET_SYS))
330 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX
331 else
332 ifeq (Darwin,$(TARGET_SYS))
333 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
334 else
335 ifeq (iOS,$(TARGET_SYS))
336 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
337 else
338 HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER
339 endif
340 endif
341 endif
342 endif
343 endif
345 ifneq (,$(CCDEBUG))
346 TARGET_STRIP= @:
347 endif
349 ##############################################################################
350 # Files and pathnames.
351 ##############################################################################
353 MINILUA_O= host/minilua.o
354 MINILUA_LIBS= -lm
355 MINILUA_T= host/minilua
356 MINILUA_X= $(MINILUA_T)
358 ifeq (,$(HOST_LUA))
359 HOST_LUA= $(MINILUA_X)
360 DASM_DEP= $(MINILUA_T)
361 endif
363 DASM_DIR= ../dynasm
364 DASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua
365 DASM_XFLAGS=
366 DASM_AFLAGS=
367 DASM_ARCH= $(TARGET_LJARCH)
369 ifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH)))
370 DASM_AFLAGS+= -D P64
371 endif
372 ifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH)))
373 DASM_AFLAGS+= -D JIT
374 endif
375 ifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH)))
376 DASM_AFLAGS+= -D FFI
377 endif
378 ifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH)))
379 DASM_AFLAGS+= -D DUALNUM
380 endif
381 ifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH)))
382 DASM_AFLAGS+= -D FPU
383 TARGET_ARCH+= -DLJ_ARCH_HASFPU=1
384 else
385 TARGET_ARCH+= -DLJ_ARCH_HASFPU=0
386 endif
387 ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH)))
388 DASM_AFLAGS+= -D HFABI
389 TARGET_ARCH+= -DLJ_ABI_SOFTFP=0
390 else
391 TARGET_ARCH+= -DLJ_ABI_SOFTFP=1
392 endif
393 DASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH))))
394 ifeq (Windows,$(TARGET_SYS))
395 DASM_AFLAGS+= -D WIN
396 endif
397 ifeq (x86,$(TARGET_LJARCH))
398 ifneq (,$(findstring __SSE2__ 1,$(TARGET_TESTARCH)))
399 DASM_AFLAGS+= -D SSE
400 endif
401 else
402 ifeq (x64,$(TARGET_LJARCH))
403 DASM_ARCH= x86
404 else
405 ifeq (arm,$(TARGET_LJARCH))
406 ifeq (iOS,$(TARGET_SYS))
407 DASM_AFLAGS+= -D IOS
408 endif
409 else
410 ifeq (ppc,$(TARGET_LJARCH))
411 ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH)))
412 DASM_AFLAGS+= -D SQRT
413 endif
414 ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH)))
415 DASM_AFLAGS+= -D ROUND
416 endif
417 ifneq (,$(findstring LJ_ARCH_PPC64 1,$(TARGET_TESTARCH)))
418 DASM_AFLAGS+= -D GPR64
419 endif
420 ifeq (PS3,$(TARGET_SYS))
421 DASM_AFLAGS+= -D PPE -D TOC
422 endif
423 endif
424 endif
425 endif
426 endif
428 DASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS)
429 DASM_DASC= vm_$(DASM_ARCH).dasc
431 BUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \
432 host/buildvm_lib.o host/buildvm_fold.o
433 BUILDVM_T= host/buildvm
434 BUILDVM_X= $(BUILDVM_T)
436 HOST_O= $(MINILUA_O) $(BUILDVM_O)
437 HOST_T= $(MINILUA_T) $(BUILDVM_T)
439 LJVM_S= lj_vm.s
440 LJVM_O= lj_vm.o
441 LJVM_BOUT= $(LJVM_S)
442 LJVM_MODE= elfasm
444 LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
445 lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o
446 LJLIB_C= $(LJLIB_O:.o=.c)
448 LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o \
449 lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \
450 lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o lj_strscan.o \
451 lj_api.o lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \
452 lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
453 lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \
454 lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \
455 lj_asm.o lj_trace.o lj_gdbjit.o \
456 lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \
457 lj_carith.o lj_clib.o lj_cparse.o \
458 lj_lib.o lj_alloc.o lib_aux.o \
459 $(LJLIB_O) lib_init.o
461 LJVMCORE_O= $(LJVM_O) $(LJCORE_O)
462 LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o)
464 LIB_VMDEF= jit/vmdef.lua
465 LIB_VMDEFP= $(LIB_VMDEF)
467 LUAJIT_O= luajit.o
468 LUAJIT_A= libluajit.a
469 LUAJIT_SO= libluajit.so
470 LUAJIT_T= luajit
472 ALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T)
473 ALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \
474 host/buildvm_arch.h
475 ALL_GEN= $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP)
476 WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk
477 ALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM)
479 ##############################################################################
480 # Build mode handling.
481 ##############################################################################
483 # Mixed mode defaults.
484 TARGET_O= $(LUAJIT_A)
485 TARGET_T= $(LUAJIT_T) $(LUAJIT_SO)
486 TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO)
488 ifeq (Windows,$(TARGET_SYS))
489 TARGET_DYNCC= $(STATIC_CC)
490 LJVM_MODE= coffasm
491 LUAJIT_T= luajit.exe
492 ifeq (cygwin,$(HOST_MSYS))
493 LUAJIT_SO= cyg$(TARGET_DLLNAME)
494 else
495 LUAJIT_SO= $(TARGET_DLLNAME)
496 endif
497 # Mixed mode is not supported on Windows. And static mode doesn't work well.
498 # C modules cannot be loaded, because they bind to lua51.dll.
499 ifneq (static,$(BUILDMODE))
500 BUILDMODE= dynamic
501 TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL
502 endif
503 endif
504 ifeq (Darwin,$(TARGET_SYS))
505 LJVM_MODE= machasm
506 endif
507 ifeq (iOS,$(TARGET_SYS))
508 LJVM_MODE= machasm
509 endif
510 ifeq (SunOS,$(TARGET_SYS))
511 BUILDMODE= static
512 endif
513 ifeq (PS3,$(TARGET_SYS))
514 BUILDMODE= static
515 endif
517 ifeq (Windows,$(HOST_SYS))
518 MINILUA_T= host/minilua.exe
519 BUILDVM_T= host/buildvm.exe
520 ifeq (,$(HOST_MSYS))
521 MINILUA_X= host\minilua
522 BUILDVM_X= host\buildvm
523 ALL_RM:= $(subst /,\,$(ALL_RM))
524 endif
525 endif
527 ifeq (static,$(BUILDMODE))
528 TARGET_DYNCC= @:
529 TARGET_T= $(LUAJIT_T)
530 TARGET_DEP= $(LIB_VMDEF)
531 else
532 ifeq (dynamic,$(BUILDMODE))
533 ifneq (Windows,$(TARGET_SYS))
534 TARGET_CC= $(DYNAMIC_CC)
535 endif
536 TARGET_DYNCC= @:
537 LJVMCORE_DYNO= $(LJVMCORE_O)
538 TARGET_O= $(LUAJIT_SO)
539 TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS)
540 else
541 ifeq (Darwin,$(TARGET_SYS))
542 TARGET_DYNCC= @:
543 LJVMCORE_DYNO= $(LJVMCORE_O)
544 endif
545 ifeq (iOS,$(TARGET_SYS))
546 TARGET_DYNCC= @:
547 LJVMCORE_DYNO= $(LJVMCORE_O)
548 endif
549 endif
550 endif
552 Q= @
553 E= @echo
555 #E= @:
557 ##############################################################################
558 # Make targets.
559 ##############################################################################
561 default all: $(TARGET_T)
563 amalg:
564 @grep "^[+|]" ljamalg.c
565 $(MAKE) all "LJCORE_O=ljamalg.o"
567 clean:
568 $(HOST_RM) $(ALL_RM)
570 depend:
571 @for file in $(ALL_HDRGEN); do \
572 test -f $$file || touch $$file; \
573 done
574 @$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \
575 sed -e "s| [^ ]*/dasm_\S*\.h||g" \
576 -e "s|^\([^l ]\)|host/\1|" \
577 -e "s| lj_target_\S*\.h| lj_target_*.h|g" \
578 -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \
579 -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep
580 @for file in $(ALL_HDRGEN); do \
581 test -s $$file || $(HOST_RM) $$file; \
582 done
584 .PHONY: default all amalg clean depend
586 ##############################################################################
587 # Rules for generated files.
588 ##############################################################################
590 $(MINILUA_T): $(MINILUA_O)
591 $(E) "HOSTLINK $@"
592 $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS)
594 host/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP)
595 $(E) "DYNASM $@"
596 $(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC)
598 host/buildvm.o: $(DASM_DIR)/dasm_*.h
600 $(BUILDVM_T): $(BUILDVM_O)
601 $(E) "HOSTLINK $@"
602 $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS)
604 $(LJVM_BOUT): $(BUILDVM_T)
605 $(E) "BUILDVM $@"
606 $(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@
608 lj_bcdef.h: $(BUILDVM_T) $(LJLIB_C)
609 $(E) "BUILDVM $@"
610 $(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C)
612 lj_ffdef.h: $(BUILDVM_T) $(LJLIB_C)
613 $(E) "BUILDVM $@"
614 $(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C)
616 lj_libdef.h: $(BUILDVM_T) $(LJLIB_C)
617 $(E) "BUILDVM $@"
618 $(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C)
620 lj_recdef.h: $(BUILDVM_T) $(LJLIB_C)
621 $(E) "BUILDVM $@"
622 $(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C)
624 $(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C)
625 $(E) "BUILDVM $@"
626 $(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C)
628 lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c
629 $(E) "BUILDVM $@"
630 $(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c
632 ##############################################################################
633 # Object file rules.
634 ##############################################################################
636 %.o: %.c
637 $(E) "CC $@"
638 $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<
639 $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<
641 %.o: %.s
642 $(E) "ASM $@"
643 $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<
644 $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<
646 $(LUAJIT_O):
647 $(E) "CC $@"
648 $(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -c -o $@ $<
650 $(HOST_O): %.o: %.c
651 $(E) "HOSTCC $@"
652 $(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<
654 include Makefile.dep
656 ##############################################################################
657 # Target file rules.
658 ##############################################################################
660 $(LUAJIT_A): $(LJVMCORE_O)
661 $(E) "AR $@"
662 $(Q)$(TARGET_AR) $@ $(LJVMCORE_O)
664 # The dependency on _O, but linking with _DYNO is intentional.
665 $(LUAJIT_SO): $(LJVMCORE_O)
666 $(E) "DYNLINK $@"
667 $(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS)
668 $(Q)$(TARGET_STRIP) $@
670 $(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP)
671 $(E) "LINK $@"
672 $(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS)
673 $(Q)$(TARGET_STRIP) $@
674 $(E) "OK Successfully built LuaJIT"
676 ##############################################################################