Makefile 21 KB

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