summaryrefslogtreecommitdiff
path: root/src/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'src/Makefile')
-rw-r--r--src/Makefile326
1 files changed, 326 insertions, 0 deletions
diff --git a/src/Makefile b/src/Makefile
new file mode 100644
index 00000000..bb1839d1
--- /dev/null
+++ b/src/Makefile
@@ -0,0 +1,326 @@
1##############################################################################
2# LuaJIT Makefile. Requires GNU Make.
3#
4# Suitable for POSIX platforms (Linux, *BSD, OSX etc.).
5# Also works with MinGW and Cygwin on Windows.
6# Please check msvcbuild.bat for building with MSVC on Windows.
7#
8# Copyright (C) 2005-2009 Mike Pall. See Copyright Notice in luajit.h
9##############################################################################
10
11##############################################################################
12# Compiler options: change them as needed. This mainly affects the speed of
13# the JIT compiler itself, not the speed of the JIT compiled code.
14# Turn any of the optional settings on by removing the '#' in front of them.
15#
16# Note: LuaJIT can only be compiled for x86, and not for x64 (yet)!
17# In the meantime, the x86 binary runs fine under a x64 OS.
18#
19# It's recommended to compile at least for i686. By default the assembler part
20# of the interpreter makes use of CMOV/FCOMI*/FUCOMI* instructions, anyway.
21CC= gcc -m32 -march=i686
22# Use this for GCC 4.2 or higher if you don't intend to distribute the
23# binaries to a different machine:
24#CC= gcc -m32 -march=native
25#
26# Since the assembler part does NOT maintain a frame pointer, it's pointless
27# to slow down the C part by not omitting it. Debugging and tracebacks are
28# not affected -- the assembler part has frame unwind information and GCC
29# emits it with -g (see CCDEBUG below).
30CCOPT= -O2 -fomit-frame-pointer
31# Use this if you want to generate a smaller binary (but it's slower):
32#CCOPT= -Os -fomit-frame-pointer
33# Note: it's no longer recommended to use -O3 with GCC 4.x.
34# The I-Cache bloat usually outweighs the benefits from aggressive inlining.
35#
36CCDEBUG=
37# Uncomment the next line to generate debug information:
38#CCDEBUG= -g
39#
40CCWARN= -Wall
41# Uncomment the next line to enable more warnings:
42#CCWARN+= -Wextra -Wdeclaration-after-statement -Wredundant-decls -Wshadow -Wpointer-arith
43#
44##############################################################################
45
46##############################################################################
47# Compile time definitions: change them as needed, but make sure you force
48# a full recompile with "make clean", followed by "make".
49# Note that most of these are NOT suitable for benchmarking or release mode!
50XCFLAGS=
51#
52# Disable the use of CMOV and FCOMI*/FUCOMI* instructions in the interpreter.
53# This is only necessary if you intend to run the code on REALLY ANCIENT CPUs
54# (before Pentium Pro, or on the VIA C3). This generally slows down the
55# interpreter. Don't bother if your OS wouldn't run on them, anyway.
56#XCFLAGS+= -DLUAJIT_CPU_NOCMOV
57#
58# Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter:
59#XCFLAGS+= -DLUAJIT_DISABLE_JIT
60#
61# Use the system provided memory allocator (realloc) instead of the
62# bundled memory allocator. This is slower, but sometimes helpful for
63# debugging. It's mandatory for Valgrind's memcheck tool, too.
64#XCFLAGS+= -DLUAJIT_USE_SYSMALLOC
65#
66# This define is required to run LuaJIT under Valgrind. The Valgrind
67# header files must be installed. You should enable debug information, too.
68#XCFLAGS+= -DLUAJIT_USE_VALGRIND
69#
70# This is the client for the GDB JIT API. GDB 7.0 or higher is required
71# to make use of it. See lj_gdbjit.c for details. Enabling this causes
72# a non-negligible overhead, even when not running under GDB.
73#XCFLAGS+= -DLUAJIT_USE_GDBJIT
74#
75# Turn on assertions for the Lua/C API to debug problems with lua_* calls.
76# This is rather slow -- use only while developing C libraries/embeddings.
77#XCFLAGS+= -DLUA_USE_APICHECK
78#
79# Turn on assertions for the whole LuaJIT VM. This significantly slows down
80# everything. Use only if you suspect a problem with LuaJIT itself.
81#XCFLAGS+= -DLUA_USE_ASSERT
82#
83##############################################################################
84# You probably don't need to change anything below this line.
85##############################################################################
86
87CCOPTIONS= $(CCDEBUG) $(CCOPT) $(CCWARN) $(CFLAGS) $(XCFLAGS)
88LDOPTIONS= $(CCDEBUG) $(LDFLAGS)
89
90HOST_CC= $(CC)
91HOST_RM= rm -f
92HOST_XCFLAGS=
93HOST_XLDFLAGS=
94HOST_XLIBS=
95
96TARGET_CC= $(CC)
97TARGET_STRIP= strip
98TARGET_XCFLAGS= -D_FILE_OFFSET_BITS=64
99TARGET_XLDFLAGS=
100TARGET_XSHLDFLAGS= -shared
101TARGET_XLIBS=
102TARGET_ARCH= $(patsubst %,-DLUAJIT_TARGET=LUAJIT_ARCH_%,$(TARGET))
103TARGET_DISABLE= -U_FORTIFY_SOURCE
104ifneq (,$(findstring stack-protector,$(shell $(CC) -dumpspecs)))
105 TARGET_DISABLE+= -fno-stack-protector
106endif
107
108ifneq (,$(findstring Windows,$(OS)))
109 TARGET_SYS= Windows
110else
111 TARGET_SYS:= $(shell uname -s)
112 ifneq (,$(findstring CYGWIN,$(TARGET_SYS)))
113 TARGET_SYS= Windows
114 endif
115endif
116
117ifeq (Linux,$(TARGET_SYS))
118 TARGET_XLIBS= -ldl
119 TARGET_XLDFLAGS= -Wl,-E
120else
121ifeq (Windows,$(TARGET_SYS))
122 HOST_RM= del
123 TARGET_STRIP= strip --strip-unneeded
124else
125ifeq (Darwin,$(TARGET_SYS))
126 TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup
127 TARGET_STRIP= strip -x
128 export MACOSX_DEPLOYMENT_TARGET=10.3
129else
130 TARGET_XLDFLAGS= -Wl,-E
131endif
132endif
133endif
134
135# NOTE: The LuaJIT distribution comes with a pre-generated buildvm_*.h.
136# You DO NOT NEED an installed copy of (plain) Lua 5.1 to run DynASM unless
137# you want to MODIFY the corresponding *.dasc file. You can also use LuaJIT
138# itself (bootstrapped from the pre-generated file) to run DynASM of course.
139DASM_LUA= lua
140
141Q= @
142E= @echo
143#Q=
144#E= @:
145
146##############################################################################
147
148TARGET_CFLAGS= $(CCOPTIONS) $(TARGET_DISABLE) $(TARGET_XCFLAGS)
149TARGET_LDFLAGS= $(LDOPTIONS) $(TARGET_XLDFLAGS)
150TARGET_SHLDFLAGS= $(LDOPTIONS) $(TARGET_XSHLDFLAGS)
151TARGET_LIBS= -lm $(TARGET_XLIBS)
152ifneq (,$(CCDEBUG))
153 TARGET_STRIP= @:
154endif
155
156HOST_CFLAGS= $(CCOPTIONS) $(HOST_XCFLAGS) $(TARGET_ARCH)
157HOST_LDFLAGS= $(LDOPTIONS) $(HOST_XLDFLAGS)
158HOST_LIBS= $(HOST_XLIBS)
159
160DASM_DIR= ../dynasm
161DASM= $(DASM_LUA) $(DASM_DIR)/dynasm.lua
162DASM_FLAGS=
163DASM_DISTFLAGS= -LN
164
165BUILDVM_O= buildvm.o buildvm_asm.o buildvm_peobj.o buildvm_lib.o buildvm_fold.o
166BUILDVM_T= buildvm
167
168HOST_O= $(BUILDVM_O)
169HOST_T= $(BUILDVM_T)
170
171LJVM_S= lj_vm.s
172LJVM_O= lj_vm.o
173LJVM_BOUT= $(LJVM_S)
174LJVM_MODE= asm
175
176LJLIB_O= lib_base.o lib_math.o lib_bit.o lib_string.o lib_table.o \
177 lib_io.o lib_os.o lib_package.o lib_debug.o lib_jit.o
178LJLIB_C= $(LJLIB_O:.o=.c)
179
180LJCORE_O= lj_gc.o lj_err.o lj_ctype.o lj_bc.o lj_obj.o \
181 lj_str.o lj_tab.o lj_func.o lj_udata.o lj_meta.o \
182 lj_state.o lj_dispatch.o lj_vmevent.o lj_api.o \
183 lj_lex.o lj_parse.o \
184 lj_ir.o lj_opt_mem.o lj_opt_fold.o lj_opt_narrow.o \
185 lj_opt_dce.o lj_opt_loop.o \
186 lj_mcode.o lj_snap.o lj_record.o lj_asm.o lj_trace.o lj_gdbjit.o \
187 lj_lib.o lj_alloc.o lib_aux.o \
188 $(LJLIB_O) lib_init.o
189
190LJVMCORE_O= $(LJVM_O) $(LJCORE_O)
191
192# NYI: Need complete support for building as a shared library on POSIX.
193# This is currently *only* suitable for MinGW and Cygwin, see below.
194LUAJIT_O= luajit.o
195LUAJIT_SO= luajit.so
196LUAJIT_T= luajit
197
198LIB_VMDEF= ../lib/vmdef.lua
199
200TARGET_DEP= $(LIB_VMDEF)
201TARGET_O= $(LJVMCORE_O) $(LUAJIT_O)
202TARGET_T= $(LUAJIT_T)
203
204ALL_GEN= $(LJVM_S) lj_ffdef.h lj_libdef.h lj_recdef.h $(LIB_VMDEF) lj_folddef.h
205ALL_DYNGEN= buildvm_x86.h
206WIN_RM= *.obj *.lib *.exp *.dll *.exe *.manifest
207ALL_RM= $(LUAJIT_T) $(LUAJIT_SO) $(HOST_T) $(ALL_GEN) *.o $(WIN_RM)
208
209ifeq (Windows,$(TARGET_SYS))
210 LJVM_BOUT= $(LJVM_O)
211 LJVM_MODE= peobj
212 LIB_VMDEF= ..\lib\vmdef.lua
213 # Imported symbols are bound to a specific DLL name under Windows.
214 LUAJIT_SO= lua51.dll
215 LUAJIT_T= luajit.exe
216 BUILDVM_T= buildvm.exe
217 #
218 # You can comment out the following two lines to build a static executable.
219 # But then you won't be able to dynamically load any C modules, because
220 # they bind to lua51.dll.
221 #
222 TARGET_XCFLAGS+= -DLUA_BUILD_AS_DLL
223 TARGET_O= $(LUAJIT_SO) $(LUAJIT_O)
224endif
225
226##############################################################################
227
228default: $(TARGET_T)
229
230all: $(TARGET_T)
231
232amalg:
233 @grep "^[+|]" ljamalg.c
234 $(MAKE) all "LJCORE_O=ljamalg.o"
235
236MAKE_TARGETS= amalg
237
238##############################################################################
239
240buildvm_x86.h: buildvm_x86.dasc
241 $(E) "DYNASM $@"
242 $(Q)$(DASM) $(DASM_FLAGS) -o $@ buildvm_x86.dasc
243
244$(BUILDVM_T): $(BUILDVM_O)
245 $(E) "HOSTLINK $@"
246 $(Q)$(HOST_CC) $(HOST_LDFLAGS) -o $@ $(BUILDVM_O) $(HOST_LIBS)
247
248$(LJVM_BOUT): $(BUILDVM_T)
249 $(E) "BUILDVM $@"
250 $(Q)./$(BUILDVM_T) -m $(LJVM_MODE) -o $@
251
252lj_ffdef.h: $(BUILDVM_T) $(LJLIB_C)
253 $(E) "BUILDVM $@"
254 $(Q)./$(BUILDVM_T) -m ffdef -o $@ $(LJLIB_C)
255
256lj_libdef.h: $(BUILDVM_T) $(LJLIB_C)
257 $(E) "BUILDVM $@"
258 $(Q)./$(BUILDVM_T) -m libdef -o $@ $(LJLIB_C)
259
260lj_recdef.h: $(BUILDVM_T) $(LJLIB_C)
261 $(E) "BUILDVM $@"
262 $(Q)./$(BUILDVM_T) -m recdef -o $@ $(LJLIB_C)
263
264$(LIB_VMDEF): $(BUILDVM_T) $(LJLIB_C)
265 $(E) "BUILDVM $@"
266 $(Q)./$(BUILDVM_T) -m vmdef -o $@ $(LJLIB_C)
267
268lj_folddef.h: $(BUILDVM_T) lj_opt_fold.c
269 $(E) "BUILDVM $@"
270 $(Q)./$(BUILDVM_T) -m folddef -o $@ lj_opt_fold.c
271
272$(LUAJIT_SO): $(LJVMCORE_O)
273 $(E) "LINK $@"
274 $(Q)$(TARGET_CC) $(TARGET_SHLDFLAGS) -o $@ $(LJVMCORE_O) $(TARGET_LIBS)
275 $(Q)$(TARGET_STRIP) $@
276
277$(LUAJIT_T): $(TARGET_O) $(TARGET_DEP)
278 $(E) "LINK $@"
279 $(Q)$(TARGET_CC) $(TARGET_LDFLAGS) -o $@ $(TARGET_O) $(TARGET_LIBS)
280 $(Q)$(TARGET_STRIP) $@
281 $(E) "OK Successfully built LuaJIT"
282
283##############################################################################
284
285%.o: %.c
286 $(E) "CC $@"
287 $(Q)$(TARGET_CC) $(TARGET_CFLAGS) -c -o $@ $<
288
289%.o: %.s
290 $(E) "ASM $@"
291 $(Q)$(TARGET_CC) $(TARGET_CFLAGS) -c -o $@ $<
292
293$(HOST_O): %.o: %.c
294 $(E) "HOSTCC $@"
295 $(Q)$(HOST_CC) $(HOST_CFLAGS) -c -o $@ $<
296
297include Makefile.dep
298
299##############################################################################
300
301clean:
302 $(HOST_RM) $(ALL_RM)
303
304cleaner: clean
305 $(HOST_RM) $(ALL_DYNGEN)
306
307distclean: clean
308 $(E) "DYNASM $@"
309 $(Q)$(DASM) $(DASM_DISTFLAGS) -o buildvm_x86.h buildvm_x86.dasc
310
311depend:
312 @test -f lj_ffdef.h || touch lj_ffdef.h
313 @test -f lj_libdef.h || touch lj_libdef.h
314 @test -f lj_recdef.h || touch lj_recdef.h
315 @test -f lj_folddef.h || touch lj_folddef.h
316 @test -f buildvm_x86.h || touch buildvm_x86.h
317 @$(HOST_CC) $(HOST_CFLAGS) -MM *.c | sed "s|$(DASM_DIR)|\$$(DASM_DIR)|g" >Makefile.dep
318 @test -s lj_ffdef.h || $(HOST_RM) lj_ffdef.h
319 @test -s lj_libdef.h || $(HOST_RM) lj_libdef.h
320 @test -s lj_recdef.h || $(HOST_RM) lj_recdef.h
321 @test -s lj_folddef.h || $(HOST_RM) lj_folddef.h
322 @test -s buildvm_x86.h || $(HOST_RM) buildvm_x86.h
323
324.PHONY: default all $(MAKE_TARGETS) clean cleaner distclean depend
325
326##############################################################################