Makefile 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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-2012 Mike Pall. See Copyright Notice in luajit.h
  11. ##############################################################################
  12. MAJVER= 2
  13. MINVER= 0
  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 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_SONAME= libluajit-$(ABIVER).so.$(MAJVER)
  180. TARGET_DYLIBNAME= libluajit-$(ABIVER).$(MAJVER).dylib
  181. TARGET_DYLIBPATH= $(or $(PREFIX),/usr/local)/lib/$(TARGET_DYLIBNAME)
  182. TARGET_DLLNAME= lua$(NODOTABIVER).dll
  183. TARGET_XSHLDFLAGS= -shared -fPIC -Wl,-soname,$(TARGET_SONAME)
  184. TARGET_DYNXLDOPTS=
  185. TARGET_LFSFLAGS= -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
  186. TARGET_XCFLAGS= $(TARGET_LFSFLAGS) -U_FORTIFY_SOURCE
  187. TARGET_XLDFLAGS=
  188. TARGET_XLIBS= -lm
  189. TARGET_TCFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
  190. TARGET_ACFLAGS= $(CCOPTIONS) $(TARGET_XCFLAGS) $(TARGET_FLAGS) $(TARGET_CFLAGS)
  191. TARGET_ALDFLAGS= $(LDOPTIONS) $(TARGET_XLDFLAGS) $(TARGET_FLAGS) $(TARGET_LDFLAGS)
  192. TARGET_ASHLDFLAGS= $(LDOPTIONS) $(TARGET_XSHLDFLAGS) $(TARGET_FLAGS) $(TARGET_SHLDFLAGS)
  193. TARGET_ALIBS= $(TARGET_XLIBS) $(LIBS) $(TARGET_LIBS)
  194. TARGET_TESTARCH=$(shell $(TARGET_CC) $(TARGET_TCFLAGS) -E lj_arch.h -dM)
  195. ifneq (,$(findstring LJ_TARGET_X64 ,$(TARGET_TESTARCH)))
  196. TARGET_LJARCH= x64
  197. else
  198. ifneq (,$(findstring LJ_TARGET_X86 ,$(TARGET_TESTARCH)))
  199. TARGET_LJARCH= x86
  200. else
  201. ifneq (,$(findstring LJ_TARGET_ARM ,$(TARGET_TESTARCH)))
  202. TARGET_LJARCH= arm
  203. else
  204. ifneq (,$(findstring LJ_TARGET_PPC ,$(TARGET_TESTARCH)))
  205. TARGET_LJARCH= ppc
  206. else
  207. ifneq (,$(findstring LJ_TARGET_PPCSPE ,$(TARGET_TESTARCH)))
  208. TARGET_LJARCH= ppcspe
  209. else
  210. ifneq (,$(findstring LJ_TARGET_MIPS ,$(TARGET_TESTARCH)))
  211. ifneq (,$(findstring MIPSEL ,$(TARGET_TESTARCH)))
  212. TARGET_ARCH= -D__MIPSEL__=1
  213. endif
  214. TARGET_LJARCH= mips
  215. else
  216. $(error Unsupported target architecture)
  217. endif
  218. endif
  219. endif
  220. endif
  221. endif
  222. endif
  223. ifneq (,$(findstring LJ_TARGET_PS3 1,$(TARGET_TESTARCH)))
  224. TARGET_SYS= PS3
  225. TARGET_ARCH+= -D__CELLOS_LV2__
  226. TARGET_XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
  227. endif
  228. ifneq (,$(findstring LJ_NO_UNWIND 1,$(TARGET_TESTARCH)))
  229. TARGET_ARCH+= -DLUAJIT_NO_UNWIND
  230. endif
  231. TARGET_XCFLAGS+= $(CCOPT_$(TARGET_LJARCH))
  232. TARGET_ARCH+= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET_LJARCH))
  233. ifneq (,$(PREFIX))
  234. ifneq (/usr/local,$(PREFIX))
  235. TARGET_XCFLAGS+= -DLUA_XROOT=\"$(PREFIX)/\"
  236. ifneq (/usr,$(PREFIX))
  237. TARGET_DYNXLDOPTS= -Wl,-rpath,$(PREFIX)/lib
  238. endif
  239. endif
  240. endif
  241. ##############################################################################
  242. # System detection.
  243. ##############################################################################
  244. ifeq (Windows,$(findstring Windows,$(OS))$(MSYSTEM)$(TERM))
  245. HOST_SYS= Windows
  246. HOST_RM= del
  247. else
  248. HOST_SYS:= $(shell uname -s)
  249. ifneq (,$(findstring MINGW,$(HOST_SYS)))
  250. HOST_SYS= Windows
  251. HOST_MSYS= mingw
  252. endif
  253. ifneq (,$(findstring CYGWIN,$(HOST_SYS)))
  254. HOST_SYS= Windows
  255. HOST_MSYS= cygwin
  256. endif
  257. endif
  258. TARGET_SYS?= $(HOST_SYS)
  259. ifeq (Windows,$(TARGET_SYS))
  260. TARGET_STRIP+= --strip-unneeded
  261. TARGET_XSHLDFLAGS= -shared
  262. TARGET_DYNXLDOPTS=
  263. else
  264. ifeq (Darwin,$(TARGET_SYS))
  265. ifeq (,$(MACOSX_DEPLOYMENT_TARGET))
  266. export MACOSX_DEPLOYMENT_TARGET=10.4
  267. endif
  268. TARGET_STRIP+= -x
  269. TARGET_AR+= 2>/dev/null
  270. TARGET_XCFLAGS+= -fno-stack-protector
  271. TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
  272. TARGET_DYNXLDOPTS=
  273. TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
  274. ifeq (x64,$(TARGET_LJARCH))
  275. TARGET_XLDFLAGS+= -pagezero_size 10000 -image_base 100000000
  276. TARGET_XSHLDFLAGS+= -image_base 7fff04c4a000
  277. endif
  278. else
  279. ifeq (iOS,$(TARGET_SYS))
  280. TARGET_STRIP+= -x
  281. TARGET_AR+= 2>/dev/null
  282. TARGET_XCFLAGS+= -fno-stack-protector
  283. TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
  284. TARGET_DYNXLDOPTS=
  285. TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).$(RELVER)
  286. else
  287. ifneq (,$(findstring stack-protector,$(shell $(TARGET_CC) -dumpspecs)))
  288. TARGET_XCFLAGS+= -fno-stack-protector
  289. endif
  290. ifneq (SunOS,$(TARGET_SYS))
  291. ifneq (PS3,$(TARGET_SYS))
  292. TARGET_XLDFLAGS+= -Wl,-E
  293. endif
  294. endif
  295. ifeq (Linux,$(TARGET_SYS))
  296. TARGET_XLIBS+= -ldl
  297. endif
  298. ifeq (GNU/kFreeBSD,$(TARGET_SYS))
  299. TARGET_XLIBS+= -ldl
  300. endif
  301. endif
  302. endif
  303. endif
  304. ifneq ($(HOST_SYS),$(TARGET_SYS))
  305. ifeq (Windows,$(TARGET_SYS))
  306. HOST_XCFLAGS+= -malign-double -DLUAJIT_OS=LUAJIT_OS_WINDOWS
  307. else
  308. ifeq (Linux,$(TARGET_SYS))
  309. HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_LINUX
  310. else
  311. ifeq (Darwin,$(TARGET_SYS))
  312. HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
  313. else
  314. ifeq (iOS,$(TARGET_SYS))
  315. HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OSX
  316. else
  317. HOST_XCFLAGS+= -DLUAJIT_OS=LUAJIT_OS_OTHER
  318. endif
  319. endif
  320. endif
  321. endif
  322. endif
  323. ifneq (,$(CCDEBUG))
  324. TARGET_STRIP= @:
  325. endif
  326. ##############################################################################
  327. # Files and pathnames.
  328. ##############################################################################
  329. MINILUA_O= host/minilua.o
  330. MINILUA_LIBS= -lm
  331. MINILUA_T= host/minilua
  332. MINILUA_X= $(MINILUA_T)
  333. ifeq (,$(HOST_LUA))
  334. HOST_LUA= $(MINILUA_X)
  335. DASM_DEP= $(MINILUA_T)
  336. endif
  337. DASM_DIR= ../dynasm
  338. DASM= $(HOST_LUA) $(DASM_DIR)/dynasm.lua
  339. DASM_XFLAGS=
  340. DASM_AFLAGS=
  341. DASM_ARCH= $(TARGET_LJARCH)
  342. ifneq (,$(findstring LJ_ARCH_BITS 64,$(TARGET_TESTARCH)))
  343. DASM_AFLAGS+= -D P64
  344. endif
  345. ifneq (,$(findstring LJ_HASJIT 1,$(TARGET_TESTARCH)))
  346. DASM_AFLAGS+= -D JIT
  347. endif
  348. ifneq (,$(findstring LJ_HASFFI 1,$(TARGET_TESTARCH)))
  349. DASM_AFLAGS+= -D FFI
  350. endif
  351. ifneq (,$(findstring LJ_DUALNUM 1,$(TARGET_TESTARCH)))
  352. DASM_AFLAGS+= -D DUALNUM
  353. endif
  354. ifneq (,$(findstring LJ_ARCH_HASFPU 1,$(TARGET_TESTARCH)))
  355. DASM_AFLAGS+= -D FPU
  356. TARGET_ARCH+= -DLJ_ARCH_HASFPU=1
  357. else
  358. TARGET_ARCH+= -DLJ_ARCH_HASFPU=0
  359. endif
  360. ifeq (,$(findstring LJ_ABI_SOFTFP 1,$(TARGET_TESTARCH)))
  361. DASM_AFLAGS+= -D HFABI
  362. TARGET_ARCH+= -DLJ_ABI_SOFTFP=0
  363. else
  364. TARGET_ARCH+= -DLJ_ABI_SOFTFP=1
  365. endif
  366. DASM_AFLAGS+= -D VER=$(subst LJ_ARCH_VERSION_,,$(filter LJ_ARCH_VERSION_%,$(subst LJ_ARCH_VERSION ,LJ_ARCH_VERSION_,$(TARGET_TESTARCH))))
  367. ifeq (Windows,$(TARGET_SYS))
  368. DASM_AFLAGS+= -D WIN
  369. endif
  370. ifeq (x86,$(TARGET_LJARCH))
  371. ifneq (,$(findstring __SSE2__ 1,$(TARGET_TESTARCH)))
  372. DASM_AFLAGS+= -D SSE
  373. endif
  374. else
  375. ifeq (x64,$(TARGET_LJARCH))
  376. DASM_ARCH= x86
  377. else
  378. ifeq (arm,$(TARGET_LJARCH))
  379. ifeq (iOS,$(TARGET_SYS))
  380. DASM_AFLAGS+= -D IOS
  381. endif
  382. else
  383. ifeq (ppc,$(TARGET_LJARCH))
  384. ifneq (,$(findstring LJ_ARCH_SQRT 1,$(TARGET_TESTARCH)))
  385. DASM_AFLAGS+= -D SQRT
  386. endif
  387. ifneq (,$(findstring LJ_ARCH_ROUND 1,$(TARGET_TESTARCH)))
  388. DASM_AFLAGS+= -D ROUND
  389. endif
  390. ifneq (,$(findstring LJ_ARCH_PPC64 1,$(TARGET_TESTARCH)))
  391. DASM_AFLAGS+= -D GPR64
  392. endif
  393. ifeq (PS3,$(TARGET_SYS))
  394. DASM_AFLAGS+= -D PPE -D TOC
  395. endif
  396. endif
  397. endif
  398. endif
  399. endif
  400. DASM_FLAGS= $(DASM_XFLAGS) $(DASM_AFLAGS)
  401. DASM_DASC= vm_$(DASM_ARCH).dasc
  402. BUILDVM_O= host/buildvm.o host/buildvm_asm.o host/buildvm_peobj.o \
  403. host/buildvm_lib.o host/buildvm_fold.o
  404. BUILDVM_T= host/buildvm
  405. BUILDVM_X= $(BUILDVM_T)
  406. HOST_O= $(MINILUA_O) $(BUILDVM_O)
  407. HOST_T= $(MINILUA_T) $(BUILDVM_T)
  408. LJVM_S= lj_vm.s
  409. LJVM_O= lj_vm.o
  410. LJVM_BOUT= $(LJVM_S)
  411. LJVM_MODE= elfasm
  412. LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
  413. lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o lib_ffi.o
  414. LJLIB_C= $(LJLIB_O:.o=.c)
  415. LJCORE_O= lj_gc.o lj_err.o lj_char.o lj_bc.o lj_obj.o \
  416. lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o lj_debug.o \
  417. lj_state.o lj_dispatch.o lj_vmevent.o lj_vmmath.o lj_strscan.o \
  418. lj_api.o lj_lex.o lj_parse.o lj_bcread.o lj_bcwrite.o lj_load.o \
  419. lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
  420. lj_opt_dce.o lj_opt_loop.o lj_opt_split.o lj_opt_sink.o \
  421. lj_mcode.o lj_snap.o lj_record.o lj_crecord.o lj_ffrecord.o \
  422. lj_asm.o lj_trace.o lj_gdbjit.o \
  423. lj_ctype.o lj_cdata.o lj_cconv.o lj_ccall.o lj_ccallback.o \
  424. lj_carith.o lj_clib.o lj_cparse.o \
  425. lj_lib.o lj_alloc.o lib_aux.o \
  426. $(LJLIB_O) lib_init.o
  427. LJVMCORE_O= $(LJVM_O) $(LJCORE_O)
  428. LJVMCORE_DYNO= $(LJVMCORE_O:.o=_dyn.o)
  429. LIB_VMDEF= jit/vmdef.lua
  430. LIB_VMDEFP= $(LIB_VMDEF)
  431. LUAJIT_O= luajit.o
  432. LUAJIT_A= libluajit.a
  433. LUAJIT_SO= libluajit.so
  434. LUAJIT_T= luajit
  435. ALL_T= $(LUAJIT_T) $(LUAJIT_A) $(LUAJIT_SO) $(HOST_T)
  436. ALL_HDRGEN= lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h \
  437. host/buildvm_arch.h
  438. ALL_GEN= $(LJVM_S) $(ALL_HDRGEN) $(LIB_VMDEFP)
  439. WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk
  440. ALL_RM= $(ALL_T) $(ALL_GEN) *.o host/*.o $(WIN_RM)
  441. ##############################################################################
  442. # Build mode handling.
  443. ##############################################################################
  444. # Mixed mode defaults.
  445. TARGET_O= $(LUAJIT_A)
  446. TARGET_T= $(LUAJIT_T) $(LUAJIT_SO)
  447. TARGET_DEP= $(LIB_VMDEF) $(LUAJIT_SO)
  448. ifeq (Windows,$(TARGET_SYS))
  449. TARGET_DYNCC= $(STATIC_CC)
  450. LJVM_MODE= coffasm
  451. LUAJIT_T= luajit.exe
  452. ifeq (cygwin,$(HOST_MSYS))
  453. LUAJIT_SO= cyg$(TARGET_DLLNAME)
  454. else
  455. LUAJIT_SO= $(TARGET_DLLNAME)
  456. endif
  457. # Mixed mode is not supported on Windows. And static mode doesn't work well.
  458. # C modules cannot be loaded, because they bind to lua51.dll.
  459. ifneq (static,$(BUILDMODE))
  460. BUILDMODE= dynamic
  461. TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL
  462. endif
  463. endif
  464. ifeq (Darwin,$(TARGET_SYS))
  465. LJVM_MODE= machasm
  466. endif
  467. ifeq (iOS,$(TARGET_SYS))
  468. LJVM_MODE= machasm
  469. endif
  470. ifeq (SunOS,$(TARGET_SYS))
  471. BUILDMODE= static
  472. endif
  473. ifeq (PS3,$(TARGET_SYS))
  474. BUILDMODE= static
  475. endif
  476. ifeq (Windows,$(HOST_SYS))
  477. MINILUA_T= host/minilua.exe
  478. BUILDVM_T= host/buildvm.exe
  479. ifeq (,$(HOST_MSYS))
  480. MINILUA_X= host\minilua
  481. BUILDVM_X= host\buildvm
  482. ALL_RM:= $(subst /,\,$(ALL_RM))
  483. endif
  484. endif
  485. ifeq (static,$(BUILDMODE))
  486. TARGET_DYNCC= @:
  487. TARGET_T= $(LUAJIT_T)
  488. TARGET_DEP= $(LIB_VMDEF)
  489. else
  490. ifeq (dynamic,$(BUILDMODE))
  491. ifneq (Windows,$(TARGET_SYS))
  492. TARGET_CC= $(DYNAMIC_CC)
  493. endif
  494. TARGET_DYNCC= @:
  495. LJVMCORE_DYNO= $(LJVMCORE_O)
  496. TARGET_O= $(LUAJIT_SO)
  497. TARGET_XLDFLAGS+= $(TARGET_DYNXLDOPTS)
  498. else
  499. ifeq (Darwin,$(TARGET_SYS))
  500. TARGET_DYNCC= @:
  501. LJVMCORE_DYNO= $(LJVMCORE_O)
  502. endif
  503. ifeq (iOS,$(TARGET_SYS))
  504. TARGET_DYNCC= @:
  505. LJVMCORE_DYNO= $(LJVMCORE_O)
  506. endif
  507. endif
  508. endif
  509. Q= @
  510. E= @echo
  511. #Q=
  512. #E= @:
  513. ##############################################################################
  514. # Make targets.
  515. ##############################################################################
  516. default all: $(TARGET_T)
  517. amalg:
  518. @grep "^[+|]" ljamalg.c
  519. $(MAKE) all "LJCORE_O=ljamalg.o"
  520. clean:
  521. $(HOST_RM) $(ALL_RM)
  522. depend:
  523. @for file in $(ALL_HDRGEN); do \
  524. test -f $$file || touch $$file; \
  525. done
  526. @$(HOST_CC) $(HOST_ACFLAGS) -MM *.c host/*.c | \
  527. sed -e "s| [^ ]*/dasm_\S*\.h||g" \
  528. -e "s|^\([^l ]\)|host/\1|" \
  529. -e "s| lj_target_\S*\.h| lj_target_*.h|g" \
  530. -e "s| lj_emit_\S*\.h| lj_emit_*.h|g" \
  531. -e "s| lj_asm_\S*\.h| lj_asm_*.h|g" >Makefile.dep
  532. @for file in $(ALL_HDRGEN); do \
  533. test -s $$file || $(HOST_RM) $$file; \
  534. done
  535. .PHONY: default all amalg clean depend
  536. ##############################################################################
  537. # Rules for generated files.
  538. ##############################################################################
  539. $(MINILUA_T): $(MINILUA_O)
  540. $(E) "HOSTLINK $@"
  541. $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(MINILUA_O) $(MINILUA_LIBS) $(HOST_ALIBS)
  542. host/buildvm_arch.h: $(DASM_DASC) $(DASM_DEP)
  543. $(E) "DYNASM $@"
  544. $(Q)$(DASM) $(DASM_FLAGS) -o $@ $(DASM_DASC)
  545. host/buildvm.o: $(DASM_DIR)/dasm_*.h
  546. $(BUILDVM_T): $(BUILDVM_O)
  547. $(E) "HOSTLINK $@"
  548. $(Q)$(HOST_CC) $(HOST_ALDFLAGS) -o $@ $(BUILDVM_O) $(HOST_ALIBS)
  549. $(LJVM_BOUT): $(BUILDVM_T)
  550. $(E) "BUILDVM $@"
  551. $(Q)$(BUILDVM_X) -m $(LJVM_MODE) -o $@
  552. lj_bcdef.h: $(BUILDVM_T) $(LJLIB_C)
  553. $(E) "BUILDVM $@"
  554. $(Q)$(BUILDVM_X) -m bcdef -o $@ $(LJLIB_C)
  555. lj_ffdef.h: $(BUILDVM_T) $(LJLIB_C)
  556. $(E) "BUILDVM $@"
  557. $(Q)$(BUILDVM_X) -m ffdef -o $@ $(LJLIB_C)
  558. lj_libdef.h: $(BUILDVM_T) $(LJLIB_C)
  559. $(E) "BUILDVM $@"
  560. $(Q)$(BUILDVM_X) -m libdef -o $@ $(LJLIB_C)
  561. lj_recdef.h: $(BUILDVM_T) $(LJLIB_C)
  562. $(E) "BUILDVM $@"
  563. $(Q)$(BUILDVM_X) -m recdef -o $@ $(LJLIB_C)
  564. $(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C)
  565. $(E) "BUILDVM $@"
  566. $(Q)$(BUILDVM_X) -m vmdef -o $(LIB_VMDEFP) $(LJLIB_C)
  567. lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c
  568. $(E) "BUILDVM $@"
  569. $(Q)$(BUILDVM_X) -m folddef -o $@ lj_opt_fold.c
  570. ##############################################################################
  571. # Object file rules.
  572. ##############################################################################
  573. %.o: %.c
  574. $(E) "CC $@"
  575. $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<
  576. $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<
  577. %.o: %.s
  578. $(E) "ASM $@"
  579. $(Q)$(TARGET_DYNCC) $(TARGET_ACFLAGS) -c -o $(@:.o=_dyn.o) $<
  580. $(Q)$(TARGET_CC) $(TARGET_ACFLAGS) -c -o $@ $<
  581. $(LUAJIT_O):
  582. $(E) "CC $@"
  583. $(Q)$(TARGET_STCC) $(TARGET_ACFLAGS) -c -o $@ $<
  584. $(HOST_O): %.o: %.c
  585. $(E) "HOSTCC $@"
  586. $(Q)$(HOST_CC) $(HOST_ACFLAGS) -c -o $@ $<
  587. include Makefile.dep
  588. ##############################################################################
  589. # Target file rules.
  590. ##############################################################################
  591. $(LUAJIT_A): $(LJVMCORE_O)
  592. $(E) "AR $@"
  593. $(Q)$(TARGET_AR) $@ $(LJVMCORE_O)
  594. # The dependency on _O, but linking with _DYNO is intentional.
  595. $(LUAJIT_SO): $(LJVMCORE_O)
  596. $(E) "DYNLINK $@"
  597. $(Q)$(TARGET_LD) $(TARGET_ASHLDFLAGS) -o $@ $(LJVMCORE_DYNO) $(TARGET_ALIBS)
  598. $(Q)$(TARGET_STRIP) $@
  599. $(LUAJIT_T): $(TARGET_O) $(LUAJIT_O) $(TARGET_DEP)
  600. $(E) "LINK $@"
  601. $(Q)$(TARGET_LD) $(TARGET_ALDFLAGS) -o $@ $(LUAJIT_O) $(TARGET_O) $(TARGET_ALIBS)
  602. $(Q)$(TARGET_STRIP) $@
  603. $(E) "OK Successfully built LuaJIT"
  604. ##############################################################################