src/Makefile - luajit-2.0-src

  1. ##############################################################################
  2. # LuaJIT Makefile. Requires GNU Make.
  3. #
  4. # Please read doc/install.html before changing any variables!
  5. #
  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.
  9. #
  10. # Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
  11. ##############################################################################

  12. MAJVER=  2
  13. MINVER=  1
  14. RELVER=  0
  15. ABIVER=  5.1
  16. NODOTABIVER= 51

  17. ##############################################################################
  18. #############################  COMPILER OPTIONS  #############################
  19. ##############################################################################
  20. # These options mainly affect the speed of the JIT compiler itself, not the
  21. # speed of the JIT-compiled code. Turn any of the optional settings on by
  22. # removing the '#' in front of them. Make sure you force a full recompile
  23. # with "make clean", followed by "make" if you change any options.
  24. #
  25. # LuaJIT builds as a native 32 or 64 bit binary by default.
  26. CC= gcc
  27. #
  28. # Use this if you want to force a 32 bit build on a 64 bit multilib OS.
  29. #CC= gcc -m32
  30. #
  31. # Since the assembler part does NOT maintain a frame pointer, it's pointless
  32. # to slow down the C part by not omitting it. Debugging, tracebacks and
  33. # unwinding are not affected -- the assembler part has frame unwind
  34. # information and GCC emits it where needed (x64) or with -g (see CCDEBUG).
  35. CCOPT= -O2 -fomit-frame-pointer
  36. # Use this if you want to generate a smaller binary (but it's slower):
  37. #CCOPT= -Os -fomit-frame-pointer
  38. # Note: it's no longer recommended to use -O3 with GCC 4.x.
  39. # The I-Cache bloat usually outweighs the benefits from aggressive inlining.
  40. #
  41. # Target-specific compiler options:
  42. #
  43. # x86/x64 only: For GCC 4.2 or higher and if you don't intend to distribute
  44. # the binaries to a different machine you could also use: -march=native
  45. #
  46. CCOPT_x86= -march=i686 -msse -msse2 -mfpmath=sse
  47. CCOPT_x64=
  48. CCOPT_arm=
  49. CCOPT_arm64=
  50. CCOPT_ppc=
  51. CCOPT_mips=
  52. #
  53. CCDEBUG=
  54. # Uncomment the next line to generate debug information:
  55. #CCDEBUG= -g
  56. #
  57. CCWARN= -Wall
  58. # Uncomment the next line to enable more warnings:
  59. #CCWARN+= -Wextra -Wdeclaration-after-statement -Wredundant-decls -Wshadow -Wpointer-arith
  60. #
  61. ##############################################################################

  62. ##############################################################################
  63. ################################  BUILD MODE  ################################
  64. ##############################################################################
  65. # The default build mode is mixed mode on POSIX. On Windows this is the same
  66. # as dynamic mode.
  67. #
  68. # Mixed mode creates a static + dynamic library and a statically linked luajit.
  69. BUILDMODE= mixed
  70. #
  71. # Static mode creates a static library and a statically linked luajit.
  72. #BUILDMODE= static
  73. #
  74. # Dynamic mode creates a dynamic library and a dynamically linked luajit.
  75. # Note: this executable will only run when the library is installed!
  76. #BUILDMODE= dynamic
  77. #
  78. ##############################################################################

  79. ##############################################################################
  80. #################################  FEATURES  #################################
  81. ##############################################################################
  82. # Enable/disable these features as needed, but make sure you force a full
  83. # recompile with "make clean", followed by "make".
  84. XCFLAGS=
  85. #
  86. # Permanently disable the FFI extension to reduce the size of the LuaJIT
  87. # executable. But please consider that the FFI library is compiled-in,
  88. # but NOT loaded by default. It only allocates any memory, if you actually
  89. # make use of it.
  90. #XCFLAGS+= -DLUAJIT_DISABLE_FFI
  91. #
  92. # Features from Lua 5.2 that are unlikely to break existing code are
  93. # enabled by default. Some other features that *might* break some existing
  94. # code (e.g. __pairs or os.execute() return values) can be enabled here.
  95. # Note: this does not provide full compatibility with Lua 5.2 at this time.
  96. #XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
  97. #
  98. # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.
  99. #XCFLAGS+= -DLUAJIT_DISABLE_JIT
  100. #
  101. # Some architectures (e.g. PPC) can use either single-number (1) or
  102. # dual-number (2) mode. Uncomment one of these lines to override the
  103. # default mode. Please see LJ_ARCH_NUMMODE in lj_arch.h for details.
  104. #XCFLAGS+= -DLUAJIT_NUMMODE=1
  105. #XCFLAGS+= -DLUAJIT_NUMMODE=2
  106. #
  107. ##############################################################################

  108. ##############################################################################
  109. ############################  DEBUGGING SUPPORT  #############################
  110. ##############################################################################
  111. # Enable these options as needed, but make sure you force a full recompile
  112. # with "make clean", followed by "make".
  113. # Note that most of these are NOT suitable for benchmarking or release mode!
  114. #
  115. # Use the system provided memory allocator (realloc) instead of the
  116. # bundled memory allocator. This is slower, but sometimes helpful for
  117. # debugging. This option cannot be enabled on x64, since realloc usually
  118. # doesn't return addresses in the right address range.
  119. # OTOH this option is mandatory for Valgrind's memcheck tool on x64 and
  120. # the only way to get useful results from it for all other architectures.
  121. #XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
  122. #
  123. # This define is required to run LuaJIT under Valgrind. The Valgrind
  124. # header files must be installed. You should enable debug information, too.
  125. # Use --suppressions=lj.supp to avoid some false positives.
  126. #XCFLAGS+= -DLUAJIT_USE_VALGRIND
  127. #
  128. # This is the client for the GDB JIT API. GDB 7.0 or higher is required
  129. # to make use of it. See lj_gdbjit.c for details. Enabling this causes
  130. # a non-negligible overhead, even when not running under GDB.
  131. #XCFLAGS+= -DLUAJIT_USE_GDBJIT
  132. #
  133. # Turn on assertions for the Lua/C API to debug problems with lua_* calls.
  134. # This is rather slow -- use only while developing C libraries/embeddings.
  135. #XCFLAGS+= -DLUA_USE_APICHECK
  136. #
  137. # Turn on assertions for the whole LuaJIT VM. This significantly slows down
  138. # everything. Use only if you suspect a problem with LuaJIT itself.
  139. #XCFLAGS+= -DLUA_USE_ASSERT
  140. #
  141. ##############################################################################
  142. # You probably don't need to change anything below this line!
  143. ##############################################################################

  144. ##############################################################################
  145. # Flags and options for host and target.
  146. ##############################################################################

  147. # You can override the following variables at the make command line:
  148. #   CC       HOST_CC       STATIC_CC       DYNAMIC_CC
  149. #   CFLAGS   HOST_CFLAGS   TARGET_CFLAGS
  150. #   LDFLAGS  HOST_LDFLAGS  TARGET_LDFLAGS  TARGET_SHLDFLAGS
  151. #   LIBS     HOST_LIBS     TARGET_LIBS
  152. #   CROSS    HOST_SYS      TARGET_SYS      TARGET_FLAGS
  153. #
  154. # Cross-compilation examples:
  155. #   make HOST_CC="gcc -m32" CROSS=i586-mingw32msvc- TARGET_SYS=Windows
  156. #   make HOST_CC="gcc -m32" CROSS=powerpc-linux-gnu-

  157. ASOPTIONS= $(CCOPT) $(CCWARN) $(XCFLAGS) $(CFLAGS)
  158. CCOPTIONS= $(CCDEBUG) $(ASOPTIONS)
  159. LDOPTIONS= $(CCDEBUG) $(LDFLAGS)

  160. HOST_CC= $(CC)
  161. HOST_RM= rm -f
  162. # If left blank, minilua is built and used. You can supply an installed
  163. # copy of (plain) Lua 5.1 or 5.2, plus Lua BitOp. E.g. with: HOST_LUA=lua
  164. HOST_LUA=

  165. HOST_XCFLAGS= -I.
  166. HOST_XLDFLAGS=
  167. HOST_XLIBS=
  168. HOST_ACFLAGS= $(CCOPTIONS) $(HOST_XCFLAGS) $(TARGET_ARCH) $(HOST_CFLAGS)
  169. HOST_ALDFLAGS= $(LDOPTIONS) $(HOST_XLDFLAGS) $(HOST_LDFLAGS)
  170. HOST_ALIBS= $(HOST_XLIBS) $(LIBS) $(HOST_LIBS)

  171. STATIC_CC = $(CROSS)$(CC)
  172. DYNAMIC_CC = $(CROSS)$(CC) -fPIC
  173. TARGET_CC= $(STATIC_CC)
  174. TARGET_STCC= $(STATIC_CC)
  175. TARGET_DYNCC= $(DYNAMIC_CC)
  176. TARGET_LD= $(CROSS)$(CC)
  177. TARGET_AR= $(CROSS)ar rcus
  178. TARGET_STRIP= $(CROSS)strip

  179. TARGET_LIBPATH= $(or $(PREFIX),/usr/local)/$(or $(MULTILIB),lib)
  180. TARGET_SONAME= libluajit-$(ABIVER).so.$(MAJVER)
  181. TARGET_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).dylib
  182. TARGET_DYLIBPATH= $(TARGET_LIBPATH)/$(TARGET_DYLIBNAME)
  183. TARGET_DLLNAME= lua$(NODOTABIVER).dll
  184. TARGET_XSHLDFLAGS= -shared -fPIC -Wl,-soname,$(TARGET_SONAME)
  185. TARGET_DYNXLDOPTS=

  186. TARGET_LFSFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
  187. TARGET_XCFLAGS= $(TARGET_LFSFLAGS) -U_FORTIFY_SOURCE
  188. TARGET_XLDFLAGS=
  189. TARGET_XLIBS= -lm
  190. TARGET_TCFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
  191. TARGET_ACFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
  192. TARGET_ASFLAGS= $(ASOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
  193. TARGET_ALDFLAGS= $(LDOPTIONS) $(TARGET_XLDFLAGS) $(TARGET_FLAGS) $(TARGET_LDFLAGS)
  194. TARGET_ASHLDFLAGS= $(LDOPTIONS) $(TARGET_XSHLDFLAGS) $(TARGET_FLAGS) $(TARGET_SHLDFLAGS)
  195. TARGET_ALIBS= $(TARGET_XLIBS) $(LIBS) $(TARGET_LIBS)

  196. TARGET_TESTARCH=$(shell $(TARGET_CC) $(TARGET_TCFLAGS) -E lj_arch.h -dM)
  197. ifneq (,$(findstring LJ_TARGET_X64 ,$(TARGET_TESTARCH)))
  198.   TARGET_LJARCH= x64
  199. else
  200. ifneq (,$(findstring LJ_TARGET_X86 ,$(TARGET_TESTARCH)))
  201.   TARGET_LJARCH= x86
  202. else
  203. ifneq (,$(findstring LJ_TARGET_ARM ,$(TARGET_TESTARCH)))
  204.   TARGET_LJARCH= arm
  205. else
  206. ifneq (,$(findstring LJ_TARGET_ARM64 ,$(TARGET_TESTARCH)))
  207.   TARGET_LJARCH= arm64
  208. else
  209. ifneq (,$(findstring LJ_TARGET_PPC ,$(TARGET_TESTARCH)))
  210.   TARGET_LJARCH= ppc
  211. else
  212. ifneq (,$(findstring LJ_TARGET_MIPS ,$(TARGET_TESTARCH)))
  213.   ifneq (,$(findstring MIPSEL ,$(TARGET_TESTARCH)))
  214.     TARGET_ARCH= -D__MIPSEL__=1
  215.   endif
  216.   TARGET_LJARCH= mips
  217. else
  218.   $(error Unsupported target architecture)
  219. endif
  220. endif
  221. endif
  222. endif
  223. endif
  224. endif

  225. ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH)))
  226.   TARGET_SYS= PS3
  227.   TARGET_ARCH+= -D__CELLOS_LV2__
  228.   TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
  229.   TARGET_XLIBS+= -lpthread
  230. endif
  231. ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))
  232.   TARGET_ARCH+= -DLUAJIT_NO_UNWIND
  233. endif

  234. TARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH))
  235. TARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH))

  236. ifneq (,$(PREFIX))
  237. ifneq (/usr/local,$(PREFIX))
  238.   TARGET_XCFLAGS+= -DLUA_ROOT=\"$(PREFIX)\"
  239.   ifneq (/usr,$(PREFIX))
  240.     TARGET_DYNXLDOPTS= -Wl,-rpath,$(TARGET_LIBPATH)
  241.   endif
  242. endif
  243. endif
  244. ifneq (,$(MULTILIB))
  245.   TARGET_XCFLAGS+= -DLUA_MULTILIB=\"$(MULTILIB)\"
  246. endif
  247. ifneq (,$(LMULTILIB))
  248.   TARGET_XCFLAGS+= -DLUA_LMULTILIB=\"$(LMULTILIB)\"
  249. endif

  250. ##############################################################################
  251. # System detection.
  252. ##############################################################################

  253. ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM))
  254.   HOST_SYS= Windows
  255.   HOST_RM= del
  256. else
  257.   HOST_SYS:= $(shell uname -s)
  258.   ifneq (,$(findstring MINGW,$(HOST_SYS)))
  259.     HOST_SYS= Windows
  260.     HOST_MSYS= mingw
  261.   endif
  262.   ifneq (,$(findstring CYGWIN,$(HOST_SYS)))
  263.     HOST_SYS= Windows
  264.     HOST_MSYS= cygwin
  265.   endif
  266. endif

  267. TARGET_SYS?= $(HOST_SYS)
  268. ifeq (Windows,$(TARGET_SYS))
  269.   TARGET_STRIP+= --strip-unneeded
  270.   TARGET_XSHLDFLAGS= -shared
  271.   TARGET_DYNXLDOPTS=
  272. else
  273. ifeq (,$(shell $(TARGET_CC) -o /dev/null -c -x c /dev/null -fno-stack-protector 2>/dev/null || echo 1))
  274.   TARGET_XCFLAGS+= -fno-stack-protector
  275. endif
  276. ifeq (Darwin,$(TARGET_SYS))
  277.   ifeq (,$(MACOSX_DEPLOYMENT_TARGET))
  278.     export MACOSX_DEPLOYMENT_TARGET=10.4
  279.   endif
  280.   TARGET_STRIP+= -x
  281.   TARGET_AR+= 2>/dev/null
  282.   TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
  283.   TARGET_DYNXLDOPTS=
  284.   TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
  285.   ifeq (x64,$(TARGET_LJARCH))
  286.     TARGET_XLDFLAGS+= -pagezero_size 10000 -image_base 100000000
  287.     TARGET_XSHLDFLAGS+= -image_base 7fff04c4a000
  288.   endif
  289. else
  290. ifeq (iOS,$(TARGET_SYS))
  291.   TARGET_STRIP+= -x
  292.   TARGET_AR+= 2>/dev/null
  293.   TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
  294.   TARGET_DYNXLDOPTS=
  295.   TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
  296.   ifeq (arm64,$(TARGET_LJARCH))
  297.     TARGET_XCFLAGS+= -fno-omit-frame-pointer
  298.   endif
  299. else
  300.   ifneq (SunOS,$(TARGET_SYS))
  301.     ifneq (PS3,$(TARGET_SYS))
  302.       TARGET_XLDFLAGS+= -Wl,-E
  303.     endif
  304.   endif
  305.   ifeq (Linux,$(TARGET_SYS))
  306.     TARGET_XLIBS+= -ldl
  307.   endif
  308.   ifeq (GNU/kFreeBSD,$(TARGET_SYS))
  309.     TARGET_XLIBS+= -ldl
  310.   endif
  311. endif
  312. endif
  313. endif

  314. ifneq ($(HOST_SYS),$(TARGET_SYS))
  315.   ifeq (Windows,$(TARGET_SYS))
  316.     HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS
  317.   else
  318.   ifeq (Linux,$(TARGET_SYS))
  319.     HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX
  320.   else
  321.   ifeq (Darwin,$(TARGET_SYS))
  322.     HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
  323.   else
  324.   ifeq (iOS,$(TARGET_SYS))
  325.     HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
  326.   else
  327.     HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER
  328.   endif
  329.   endif
  330.   endif
  331.   endif
  332. endif

  333. ifneq (,$(CCDEBUG))
  334.   TARGET_STRIP= @:
  335. endif

  336. ##############################################################################
  337. # Files and pathnames.
  338. ##############################################################################

  339. MINILUA_O= host/minilua.o
  340. MINILUA_LIBS= -lm
  341. MINILUA_T= host/minilua
  342. MINILUA_X= $(MINILUA_T)

  343. ifeq (,$(HOST_LUA))
  344.   HOST_LUA= $(MINILUA_X)
  345.   DASM_DEP= $(MINILUA_T)
  346. endif

  347. DASM_DIR= ../dynasm
  348. DASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua
  349. DASM_XFLAGS=
  350. DASM_AFLAGS=
  351. DASM_ARCH= $(TARGET_LJARCH)

  352. ifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH)))
  353.   DASM_AFLAGS+= -D P64
  354. endif
  355. ifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH)))
  356.   DASM_AFLAGS+= -D JIT
  357. endif
  358. ifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH)))
  359.   DASM_AFLAGS+= -D FFI
  360. endif
  361. ifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH)))
  362.   DASM_AFLAGS+= -D DUALNUM
  363. endif
  364. ifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH)))
  365.   DASM_AFLAGS+= -D FPU
  366.   TARGET_ARCH+= -DLJ_ARCH_HASFPU=1
  367. else
  368.   TARGET_ARCH+= -DLJ_ARCH_HASFPU=0
  369. endif
  370. ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH)))
  371.   DASM_AFLAGS+= -D HFABI
  372.   TARGET_ARCH+= -DLJ_ABI_SOFTFP=0
  373. else
  374.   TARGET_ARCH+= -DLJ_ABI_SOFTFP=1
  375. endif
  376. DASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH))))
  377. ifeq (Windows,$(TARGET_SYS))
  378.   DASM_AFLAGS+= -D WIN
  379. endif
  380. ifeq (x64,$(TARGET_LJARCH))
  381.   ifeq (,$(findstring LJ_FR2 1,$(TARGET_TESTARCH)))
  382.     DASM_ARCH= x86
  383.   endif
  384. else
  385. ifeq (arm,$(TARGET_LJARCH))
  386.   ifeq (iOS,$(TARGET_SYS))
  387.     DASM_AFLAGS+= -D IOS
  388.   endif
  389. else
  390. ifeq (ppc,$(TARGET_LJARCH))
  391.   ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH)))
  392.     DASM_AFLAGS+= -D SQRT
  393.   endif
  394.   ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH)))
  395.     DASM_AFLAGS+= -D ROUND
  396.   endif
  397.   ifneq (,$(findstring LJ_ARCH_PPC32ON64 1,$(TARGET_TESTARCH)))
  398.     DASM_AFLAGS+= -D GPR64
  399.   endif
  400.   ifeq (PS3,$(TARGET_SYS))
  401.     DASM_AFLAGS+= -D PPE -D TOC
  402.   endif
  403.   ifneq (,$(findstring LJ_ARCH_PPC64 ,$(TARGET_TESTARCH)))
  404.     DASM_ARCH= ppc64
  405.   endif
  406. endif
  407. endif
  408. endif

  409. DASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS)
  410. DASM_DASC= vm_$(DASM_ARCH).dasc

  411. BUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \
  412.            host/buildvm_lib.o host/buildvm_fold.o
  413. BUILDVM_T= host/buildvm
  414. BUILDVM_X= $(BUILDVM_T)

  415. HOST_O= $(MINILUA_O) $(BUILDVM_O)
  416. HOST_T= $(MINILUA_T) $(BUILDVM_T)

  417. LJVM_S= lj_vm.S
  418. LJVM_O= lj_vm.o
  419. LJVM_BOUT= $(LJVM_S)
  420. LJVM_MODE= elfasm

  421. LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
  422.          lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o
  423. LJLIB_C= $(LJLIB_O:.o=.c)

  424. LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o lj_buf.o \
  425.           lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \
  426.           lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o lj_strscan.o \
  427.           lj_strfmt.o lj_api.o lj_profile.o \
  428.           lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \
  429.           lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
  430.           lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \
  431.           lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \
  432.           lj_asm.o lj_trace.o lj_gdbjit.o \
  433.           lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \
  434.           lj_carith.o lj_clib.o lj_cparse.o \
  435.           lj_lib.o lj_alloc.o lib_aux.o \
  436.           $(LJLIB_O) lib_init.o

  437. LJVMCORE_O= $(LJVM_O) $(LJCORE_O)
  438. LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o)

  439. LIB_VMDEF= jit/vmdef.lua
  440. LIB_VMDEFP= $(LIB_VMDEF)

  441. LUAJIT_O= luajit.o
  442. LUAJIT_A= libluajit.a
  443. LUAJIT_SO= libluajit.so
  444. LUAJIT_T= luajit

  445. ALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T)
  446. ALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \
  447.             host/buildvm_arch.h
  448. ALL_GEN= $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP)
  449. WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk
  450. ALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM)

  451. ##############################################################################
  452. # Build mode handling.
  453. ##############################################################################

  454. # Mixed mode defaults.
  455. TARGET_O= $(LUAJIT_A)
  456. TARGET_T= $(LUAJIT_T) $(LUAJIT_SO)
  457. TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO)

  458. ifeq (Windows,$(TARGET_SYS))
  459.   TARGET_DYNCC= $(STATIC_CC)
  460.   LJVM_MODE= peobj
  461.   LJVM_BOUT= $(LJVM_O)
  462.   LUAJIT_T= luajit.exe
  463.   ifeq (cygwin,$(HOST_MSYS))
  464.     LUAJIT_SO= cyg$(TARGET_DLLNAME)
  465.   else
  466.     LUAJIT_SO= $(TARGET_DLLNAME)
  467.   endif
  468.   # Mixed mode is not supported on Windows. And static mode doesn't work well.
  469.   # C modules cannot be loaded, because they bind to lua51.dll.
  470.   ifneq (static,$(BUILDMODE))
  471.     BUILDMODE= dynamic
  472.     TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL
  473.   endif
  474. endif
  475. ifeq (Darwin,$(TARGET_SYS))
  476.   LJVM_MODE= machasm
  477. endif
  478. ifeq (iOS,$(TARGET_SYS))
  479.   LJVM_MODE= machasm
  480. endif
  481. ifeq (SunOS,$(TARGET_SYS))
  482.   BUILDMODE= static
  483. endif
  484. ifeq (PS3,$(TARGET_SYS))
  485.   BUILDMODE= static
  486. endif

  487. ifeq (Windows,$(HOST_SYS))
  488.   MINILUA_T= host/minilua.exe
  489.   BUILDVM_T= host/buildvm.exe
  490.   ifeq (,$(HOST_MSYS))
  491.     MINILUA_X= host\minilua
  492.     BUILDVM_X= host\buildvm
  493.     ALL_RM:= $(subst /,\,$(ALL_RM))
  494.   endif
  495. endif

  496. ifeq (static,$(BUILDMODE))
  497.   TARGET_DYNCC= @:
  498.   TARGET_T= $(LUAJIT_T)
  499.   TARGET_DEP= $(LIB_VMDEF)
  500. else
  501. ifeq (dynamic,$(BUILDMODE))
  502.   ifneq (Windows,$(TARGET_SYS))
  503.     TARGET_CC= $(DYNAMIC_CC)
  504.   endif
  505.   TARGET_DYNCC= @:
  506.   LJVMCORE_DYNO= $(LJVMCORE_O)
  507.   TARGET_O= $(LUAJIT_SO)
  508.   TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS)
  509. else
  510. ifeq (Darwin,$(TARGET_SYS))
  511.   TARGET_DYNCC= @:
  512.   LJVMCORE_DYNO= $(LJVMCORE_O)
  513. endif
  514. ifeq (iOS,$(TARGET_SYS))
  515.   TARGET_DYNCC= @:
  516.   LJVMCORE_DYNO= $(LJVMCORE_O)
  517. endif
  518. endif
  519. endif

  520. Q= @
  521. E= @echo
  522. #Q=
  523. #E= @:

  524. ##############################################################################
  525. # Make targets.
  526. ##############################################################################

  527. default all:        $(TARGET_T)

  528. amalg:
  529.         @grep "^[+|]" ljamalg.c
  530.         $(MAKE) all "LJCORE_O=ljamalg.o"

  531. clean:
  532.         $(HOST_RM) $(ALL_RM)

  533. libbc:
  534.         ./$(LUAJIT_T) host/genlibbc.lua -o host/buildvm_libbc.h $(LJLIB_C)
  535.         $(MAKE) all

  536. depend:
  537.         @for file in $(ALL_HDRGEN); do \
  538.           test -f $$file || touch $$file; \
  539.           done
  540.         @$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \
  541.           sed -e "s| [^ ]*/dasm_\S*\.h||g" \
  542.               -e "s|^\([^l ]\)|host/\1|" \
  543.               -e "s| lj_target_\S*\.h| lj_target_*.h|g" \
  544.               -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \
  545.               -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep
  546.         @for file in $(ALL_HDRGEN); do \
  547.           test -s $$file || $(HOST_RM) $$file; \
  548.           done

  549. .PHONY: default all amalg clean libbc depend

  550. ##############################################################################
  551. # Rules for generated files.
  552. ##############################################################################

  553. $(MINILUA_T): $(MINILUA_O)
  554.         $(E) "HOSTLINK  $@"
  555.         $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS)

  556. host/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP)
  557.         $(E) "DYNASM    $@"
  558.         $(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC)

  559. host/buildvm.o: $(DASM_DIR)/dasm_*.h

  560. $(BUILDVM_T): $(BUILDVM_O)
  561.         $(E) "HOSTLINK  $@"
  562.         $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS)

  563. $(LJVM_BOUT): $(BUILDVM_T)
  564.         $(E) "BUILDVM   $@"
  565.         $(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@

  566. lj_bcdef.h: $(BUILDVM_T) $(LJLIB_C)
  567.         $(E) "BUILDVM   $@"
  568.         $(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C)

  569. lj_ffdef.h: $(BUILDVM_T) $(LJLIB_C)
  570.         $(E) "BUILDVM   $@"
  571.         $(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C)

  572. lj_libdef.h: $(BUILDVM_T) $(LJLIB_C)
  573.         $(E) "BUILDVM   $@"
  574.         $(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C)

  575. lj_recdef.h: $(BUILDVM_T) $(LJLIB_C)
  576.         $(E) "BUILDVM   $@"
  577.         $(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C)

  578. $(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C)
  579.         $(E) "BUILDVM   $@"
  580.         $(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C)

  581. lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c
  582.         $(E) "BUILDVM   $@"
  583.         $(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c

  584. ##############################################################################
  585. # Object file rules.
  586. ##############################################################################

  587. %.o: %.c
  588.         $(E) "CC        $@"
  589.         $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<
  590.         $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<

  591. %.o: %.S
  592.         $(E) "ASM       $@"
  593.         $(Q)$(TARGET_DYNCC) $(TARGET_ASFLAGS) -c -o $(@:.o=_dyn.o) $<
  594.         $(Q)$(TARGET_CC) $(TARGET_ASFLAGS) -c -o $@ $<

  595. $(LUAJIT_O):
  596.         $(E) "CC        $@"
  597.         $(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -c -o $@ $<

  598. $(HOST_O): %.o: %.c
  599.         $(E) "HOSTCC    $@"
  600.         $(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<

  601. include Makefile.dep

  602. ##############################################################################
  603. # Target file rules.
  604. ##############################################################################

  605. $(LUAJIT_A): $(LJVMCORE_O)
  606.         $(E) "AR        $@"
  607.         $(Q)$(TARGET_AR) $@ $(LJVMCORE_O)

  608. # The dependency on _O, but linking with _DYNO is intentional.
  609. $(LUAJIT_SO): $(LJVMCORE_O)
  610.         $(E) "DYNLINK   $@"
  611.         $(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS)
  612.         $(Q)$(TARGET_STRIP) $@

  613. $(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP)
  614.         $(E) "LINK      $@"
  615.         $(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS)
  616.         $(Q)$(TARGET_STRIP) $@
  617.         $(E) "OK        Successfully built LuaJIT"

  618. ##############################################################################