Makefile 22 KB

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