| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | #
 | 
					
						
							|  |  |  | # QuickJS Javascript Engine
 | 
					
						
							|  |  |  | # 
 | 
					
						
							| 
									
										
										
										
											2021-07-27 22:00:49 +00:00
										 |  |  | # Copyright (c) 2017-2021 Fabrice Bellard
 | 
					
						
							|  |  |  | # Copyright (c) 2017-2021 Charlie Gordon
 | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | #
 | 
					
						
							|  |  |  | # Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  | # of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  | # in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  | # copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  | # furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  | #
 | 
					
						
							|  |  |  | # The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  | # all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  | #
 | 
					
						
							|  |  |  | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
					
						
							|  |  |  | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  | # THE SOFTWARE.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ifeq ($(shell uname -s),Darwin) | 
					
						
							|  |  |  | CONFIG_DARWIN=y | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | # Windows cross compilation from Linux
 | 
					
						
							|  |  |  | #CONFIG_WIN32=y
 | 
					
						
							|  |  |  | # use link time optimization (smaller and faster executables but slower build)
 | 
					
						
							|  |  |  | CONFIG_LTO=y | 
					
						
							|  |  |  | # consider warnings as errors (for development)
 | 
					
						
							|  |  |  | #CONFIG_WERROR=y
 | 
					
						
							|  |  |  | # force 32 bit build for some utilities
 | 
					
						
							|  |  |  | #CONFIG_M32=y
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ifdef CONFIG_DARWIN | 
					
						
							|  |  |  | # use clang instead of gcc
 | 
					
						
							|  |  |  | CONFIG_CLANG=y | 
					
						
							|  |  |  | CONFIG_DEFAULT_AR=y | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # installation directory
 | 
					
						
							|  |  |  | prefix=/usr/local | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # use the gprof profiler
 | 
					
						
							|  |  |  | #CONFIG_PROFILE=y
 | 
					
						
							|  |  |  | # use address sanitizer
 | 
					
						
							|  |  |  | #CONFIG_ASAN=y
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | # include the code for BigInt/BigFloat/BigDecimal and math mode
 | 
					
						
							|  |  |  | CONFIG_BIGNUM=y | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | OBJDIR=.obj | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ifdef CONFIG_WIN32 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  |   ifdef CONFIG_M32 | 
					
						
							|  |  |  |     CROSS_PREFIX=i686-w64-mingw32- | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     CROSS_PREFIX=x86_64-w64-mingw32- | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  |   EXE=.exe | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |   CROSS_PREFIX= | 
					
						
							|  |  |  |   EXE= | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | ifdef CONFIG_CLANG | 
					
						
							|  |  |  |   HOST_CC=clang | 
					
						
							|  |  |  |   CC=$(CROSS_PREFIX)clang | 
					
						
							|  |  |  |   CFLAGS=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d | 
					
						
							|  |  |  |   CFLAGS += -Wextra | 
					
						
							|  |  |  |   CFLAGS += -Wno-sign-compare | 
					
						
							|  |  |  |   CFLAGS += -Wno-missing-field-initializers | 
					
						
							|  |  |  |   CFLAGS += -Wundef -Wuninitialized | 
					
						
							|  |  |  |   CFLAGS += -Wunused -Wno-unused-parameter | 
					
						
							|  |  |  |   CFLAGS += -Wwrite-strings | 
					
						
							|  |  |  |   CFLAGS += -Wchar-subscripts -funsigned-char | 
					
						
							|  |  |  |   CFLAGS += -MMD -MF $(OBJDIR)/$(@F).d | 
					
						
							|  |  |  |   ifdef CONFIG_DEFAULT_AR | 
					
						
							|  |  |  |     AR=$(CROSS_PREFIX)ar | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     ifdef CONFIG_LTO | 
					
						
							|  |  |  |       AR=$(CROSS_PREFIX)llvm-ar | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       AR=$(CROSS_PREFIX)ar | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |   HOST_CC=gcc | 
					
						
							|  |  |  |   CC=$(CROSS_PREFIX)gcc | 
					
						
							|  |  |  |   CFLAGS=-g -Wall -MMD -MF $(OBJDIR)/$(@F).d | 
					
						
							|  |  |  |   CFLAGS += -Wno-array-bounds -Wno-format-truncation | 
					
						
							|  |  |  |   ifdef CONFIG_LTO | 
					
						
							|  |  |  |     AR=$(CROSS_PREFIX)gcc-ar | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     AR=$(CROSS_PREFIX)ar | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | STRIP=$(CROSS_PREFIX)strip | 
					
						
							|  |  |  | ifdef CONFIG_WERROR | 
					
						
							|  |  |  | CFLAGS+=-Werror | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | DEFINES:=-D_GNU_SOURCE -DCONFIG_VERSION=\"$(shell cat VERSION)\" | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | ifdef CONFIG_BIGNUM | 
					
						
							|  |  |  | DEFINES+=-DCONFIG_BIGNUM | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | ifdef CONFIG_WIN32 | 
					
						
							|  |  |  | DEFINES+=-D__USE_MINGW_ANSI_STDIO # for standard snprintf behavior | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | CFLAGS+=$(DEFINES) | 
					
						
							|  |  |  | CFLAGS_DEBUG=$(CFLAGS) -O0 | 
					
						
							|  |  |  | CFLAGS_SMALL=$(CFLAGS) -Os | 
					
						
							|  |  |  | CFLAGS_OPT=$(CFLAGS) -O2 | 
					
						
							|  |  |  | CFLAGS_NOLTO:=$(CFLAGS_OPT) | 
					
						
							|  |  |  | LDFLAGS=-g | 
					
						
							|  |  |  | ifdef CONFIG_LTO | 
					
						
							|  |  |  | CFLAGS_SMALL+=-flto | 
					
						
							|  |  |  | CFLAGS_OPT+=-flto | 
					
						
							|  |  |  | LDFLAGS+=-flto | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | ifdef CONFIG_PROFILE | 
					
						
							|  |  |  | CFLAGS+=-p | 
					
						
							|  |  |  | LDFLAGS+=-p | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | ifdef CONFIG_ASAN | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | CFLAGS+=-fsanitize=address -fno-omit-frame-pointer | 
					
						
							|  |  |  | LDFLAGS+=-fsanitize=address -fno-omit-frame-pointer | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | ifdef CONFIG_WIN32 | 
					
						
							|  |  |  | LDEXPORT= | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  | LDEXPORT=-rdynamic | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | PROGS=qjs$(EXE) qjsc$(EXE) run-test262 | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | ifneq ($(CROSS_PREFIX),) | 
					
						
							|  |  |  | QJSC_CC=gcc | 
					
						
							|  |  |  | QJSC=./host-qjsc | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | PROGS+=$(QJSC) | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | else | 
					
						
							|  |  |  | QJSC_CC=$(CC) | 
					
						
							|  |  |  | QJSC=./qjsc$(EXE) | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | ifndef CONFIG_WIN32 | 
					
						
							|  |  |  | PROGS+=qjscalc | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | ifdef CONFIG_M32 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | PROGS+=qjs32 qjs32_s | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | endif | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | PROGS+=libquickjs.a | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | ifdef CONFIG_LTO | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | PROGS+=libquickjs.lto.a | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # examples
 | 
					
						
							|  |  |  | ifeq ($(CROSS_PREFIX),) | 
					
						
							|  |  |  | ifdef CONFIG_ASAN | 
					
						
							|  |  |  | PROGS+= | 
					
						
							|  |  |  | else | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | PROGS+=examples/hello examples/hello_module examples/test_fib | 
					
						
							|  |  |  | ifndef CONFIG_DARWIN | 
					
						
							|  |  |  | PROGS+=examples/fib.so examples/point.so | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | all: $(OBJDIR) $(OBJDIR)/quickjs.check.o $(OBJDIR)/qjs.check.o $(PROGS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QJS_LIB_OBJS=$(OBJDIR)/quickjs.o $(OBJDIR)/libregexp.o $(OBJDIR)/libunicode.o $(OBJDIR)/cutils.o $(OBJDIR)/quickjs-libc.o | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QJS_OBJS=$(OBJDIR)/qjs.o $(OBJDIR)/repl.o $(QJS_LIB_OBJS) | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | ifdef CONFIG_BIGNUM | 
					
						
							|  |  |  | QJS_LIB_OBJS+=$(OBJDIR)/libbf.o  | 
					
						
							|  |  |  | QJS_OBJS+=$(OBJDIR)/qjscalc.o | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | HOST_LIBS=-lm -ldl -lpthread | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | LIBS=-lm | 
					
						
							|  |  |  | ifndef CONFIG_WIN32 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | LIBS+=-ldl -lpthread | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | endif | 
					
						
							| 
									
										
										
										
											2021-07-27 22:00:49 +00:00
										 |  |  | LIBS+=$(EXTRA_LIBS) | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $(OBJDIR): | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	mkdir -p $(OBJDIR) $(OBJDIR)/examples $(OBJDIR)/tests | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | qjs$(EXE): $(QJS_OBJS) | 
					
						
							|  |  |  | 	$(CC) $(LDFLAGS) $(LDEXPORT) -o $@ $^ $(LIBS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qjs-debug$(EXE): $(patsubst %.o, %.debug.o, $(QJS_OBJS)) | 
					
						
							|  |  |  | 	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qjsc$(EXE): $(OBJDIR)/qjsc.o $(QJS_LIB_OBJS) | 
					
						
							|  |  |  | 	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ifneq ($(CROSS_PREFIX),) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(QJSC): $(OBJDIR)/qjsc.host.o \ | 
					
						
							|  |  |  |     $(patsubst %.o, %.host.o, $(QJS_LIB_OBJS)) | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	$(HOST_CC) $(LDFLAGS) -o $@ $^ $(HOST_LIBS) | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | endif #CROSS_PREFIX
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QJSC_DEFINES:=-DCONFIG_CC=\"$(QJSC_CC)\" -DCONFIG_PREFIX=\"$(prefix)\" | 
					
						
							|  |  |  | ifdef CONFIG_LTO | 
					
						
							|  |  |  | QJSC_DEFINES+=-DCONFIG_LTO | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | QJSC_HOST_DEFINES:=-DCONFIG_CC=\"$(HOST_CC)\" -DCONFIG_PREFIX=\"$(prefix)\" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | $(OBJDIR)/qjsc.o: CFLAGS+=$(QJSC_DEFINES) | 
					
						
							|  |  |  | $(OBJDIR)/qjsc.host.o: CFLAGS+=$(QJSC_HOST_DEFINES) | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | qjs32: $(patsubst %.o, %.m32.o, $(QJS_OBJS)) | 
					
						
							|  |  |  | 	$(CC) -m32 $(LDFLAGS) $(LDEXPORT) -o $@ $^ $(LIBS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qjs32_s: $(patsubst %.o, %.m32s.o, $(QJS_OBJS)) | 
					
						
							|  |  |  | 	$(CC) -m32 $(LDFLAGS) -o $@ $^ $(LIBS) | 
					
						
							|  |  |  | 	@size $@ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | qjscalc: qjs | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 	ln -sf $< $@ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ifdef CONFIG_LTO | 
					
						
							|  |  |  | LTOEXT=.lto | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  | LTOEXT= | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | libquickjs$(LTOEXT).a: $(QJS_LIB_OBJS) | 
					
						
							|  |  |  | 	$(AR) rcs $@ $^ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ifdef CONFIG_LTO | 
					
						
							|  |  |  | libquickjs.a: $(patsubst %.o, %.nolto.o, $(QJS_LIB_OBJS)) | 
					
						
							|  |  |  | 	$(AR) rcs $@ $^ | 
					
						
							|  |  |  | endif # CONFIG_LTO
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | repl.c: $(QJSC) repl.js | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 	$(QJSC) -c -o $@ -m repl.js | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | qjscalc.c: $(QJSC) qjscalc.js | 
					
						
							|  |  |  | 	$(QJSC) -fbignum -c -o $@ qjscalc.js | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ifneq ($(wildcard unicode/UnicodeData.txt),) | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | $(OBJDIR)/libunicode.o $(OBJDIR)/libunicode.m32.o $(OBJDIR)/libunicode.m32s.o \ | 
					
						
							|  |  |  |     $(OBJDIR)/libunicode.nolto.o: libunicode-table.h | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | libunicode-table.h: unicode_gen | 
					
						
							|  |  |  | 	./unicode_gen unicode $@ | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | run-test262: $(OBJDIR)/run-test262.o $(QJS_LIB_OBJS) | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | run-test262-debug: $(patsubst %.o, %.debug.o, $(OBJDIR)/run-test262.o $(QJS_LIB_OBJS)) | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | run-test262-32: $(patsubst %.o, %.m32.o, $(OBJDIR)/run-test262.o $(QJS_LIB_OBJS)) | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	$(CC) -m32 $(LDFLAGS) -o $@ $^ $(LIBS) | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | # object suffix order: nolto, [m32|m32s]
 | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | $(OBJDIR)/%.o: %.c | $(OBJDIR) | 
					
						
							|  |  |  | 	$(CC) $(CFLAGS_OPT) -c -o $@ $< | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(OBJDIR)/%.host.o: %.c | $(OBJDIR) | 
					
						
							|  |  |  | 	$(HOST_CC) $(CFLAGS_OPT) -c -o $@ $< | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(OBJDIR)/%.pic.o: %.c | $(OBJDIR) | 
					
						
							|  |  |  | 	$(CC) $(CFLAGS_OPT) -fPIC -DJS_SHARED_LIBRARY -c -o $@ $< | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(OBJDIR)/%.nolto.o: %.c | $(OBJDIR) | 
					
						
							|  |  |  | 	$(CC) $(CFLAGS_NOLTO) -c -o $@ $< | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(OBJDIR)/%.m32.o: %.c | $(OBJDIR) | 
					
						
							|  |  |  | 	$(CC) -m32 $(CFLAGS_OPT) -c -o $@ $< | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(OBJDIR)/%.m32s.o: %.c | $(OBJDIR) | 
					
						
							|  |  |  | 	$(CC) -m32 $(CFLAGS_SMALL) -c -o $@ $< | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(OBJDIR)/%.debug.o: %.c | $(OBJDIR) | 
					
						
							|  |  |  | 	$(CC) $(CFLAGS_DEBUG) -c -o $@ $< | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $(OBJDIR)/%.check.o: %.c | $(OBJDIR) | 
					
						
							|  |  |  | 	$(CC) $(CFLAGS) -DCONFIG_CHECK_JSVALUE -c -o $@ $< | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | regexp_test: libregexp.c libunicode.c cutils.c | 
					
						
							|  |  |  | 	$(CC) $(LDFLAGS) $(CFLAGS) -DTEST -o $@ libregexp.c libunicode.c cutils.c $(LIBS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | unicode_gen: $(OBJDIR)/unicode_gen.host.o $(OBJDIR)/cutils.host.o libunicode.c unicode_gen_def.h | 
					
						
							|  |  |  | 	$(HOST_CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJDIR)/unicode_gen.host.o $(OBJDIR)/cutils.host.o | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | clean: | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	rm -f repl.c qjscalc.c out.c | 
					
						
							|  |  |  | 	rm -f *.a *.o *.d *~ unicode_gen regexp_test $(PROGS) | 
					
						
							|  |  |  | 	rm -f hello.c test_fib.c | 
					
						
							|  |  |  | 	rm -f examples/*.so tests/*.so | 
					
						
							|  |  |  | 	rm -rf $(OBJDIR)/ *.dSYM/ qjs-debug | 
					
						
							|  |  |  | 	rm -rf run-test262-debug run-test262-32 | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | install: all | 
					
						
							|  |  |  | 	mkdir -p "$(DESTDIR)$(prefix)/bin" | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	$(STRIP) qjs qjsc | 
					
						
							|  |  |  | 	install -m755 qjs qjsc "$(DESTDIR)$(prefix)/bin" | 
					
						
							|  |  |  | 	ln -sf qjs "$(DESTDIR)$(prefix)/bin/qjscalc" | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 	mkdir -p "$(DESTDIR)$(prefix)/lib/quickjs" | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	install -m644 libquickjs.a "$(DESTDIR)$(prefix)/lib/quickjs" | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | ifdef CONFIG_LTO | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	install -m644 libquickjs.lto.a "$(DESTDIR)$(prefix)/lib/quickjs" | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 	mkdir -p "$(DESTDIR)$(prefix)/include/quickjs" | 
					
						
							|  |  |  | 	install -m644 quickjs.h quickjs-libc.h "$(DESTDIR)$(prefix)/include/quickjs" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ###############################################################################
 | 
					
						
							|  |  |  | # examples
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # example of static JS compilation
 | 
					
						
							|  |  |  | HELLO_SRCS=examples/hello.js | 
					
						
							|  |  |  | HELLO_OPTS=-fno-string-normalize -fno-map -fno-promise -fno-typedarray \
 | 
					
						
							|  |  |  |            -fno-typedarray -fno-regexp -fno-json -fno-eval -fno-proxy \
 | 
					
						
							|  |  |  |            -fno-date -fno-module-loader | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | ifdef CONFIG_BIGNUM | 
					
						
							|  |  |  | HELLO_OPTS+=-fno-bigint | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | hello.c: $(QJSC) $(HELLO_SRCS) | 
					
						
							|  |  |  | 	$(QJSC) -e $(HELLO_OPTS) -o $@ $(HELLO_SRCS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ifdef CONFIG_M32 | 
					
						
							|  |  |  | examples/hello: $(OBJDIR)/hello.m32s.o $(patsubst %.o, %.m32s.o, $(QJS_LIB_OBJS)) | 
					
						
							|  |  |  | 	$(CC) -m32 $(LDFLAGS) -o $@ $^ $(LIBS) | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  | examples/hello: $(OBJDIR)/hello.o $(QJS_LIB_OBJS) | 
					
						
							|  |  |  | 	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # example of static JS compilation with modules
 | 
					
						
							|  |  |  | HELLO_MODULE_SRCS=examples/hello_module.js | 
					
						
							|  |  |  | HELLO_MODULE_OPTS=-fno-string-normalize -fno-map -fno-promise -fno-typedarray \
 | 
					
						
							|  |  |  |            -fno-typedarray -fno-regexp -fno-json -fno-eval -fno-proxy \
 | 
					
						
							|  |  |  |            -fno-date -m | 
					
						
							|  |  |  | examples/hello_module: $(QJSC) libquickjs$(LTOEXT).a $(HELLO_MODULE_SRCS) | 
					
						
							|  |  |  | 	$(QJSC) $(HELLO_MODULE_OPTS) -o $@ $(HELLO_MODULE_SRCS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # use of an external C module (static compilation)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | test_fib.c: $(QJSC) examples/test_fib.js | 
					
						
							|  |  |  | 	$(QJSC) -e -M examples/fib.so,fib -m -o $@ examples/test_fib.js | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | examples/test_fib: $(OBJDIR)/test_fib.o $(OBJDIR)/examples/fib.o libquickjs$(LTOEXT).a | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 	$(CC) $(LDFLAGS) -o $@ $^ $(LIBS) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | examples/fib.so: $(OBJDIR)/examples/fib.pic.o | 
					
						
							|  |  |  | 	$(CC) $(LDFLAGS) -shared -o $@ $^ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | examples/point.so: $(OBJDIR)/examples/point.pic.o | 
					
						
							|  |  |  | 	$(CC) $(LDFLAGS) -shared -o $@ $^ | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ###############################################################################
 | 
					
						
							|  |  |  | # documentation
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DOCS=doc/quickjs.pdf doc/quickjs.html doc/jsbignum.pdf doc/jsbignum.html  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | build_doc: $(DOCS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | clean_doc:  | 
					
						
							|  |  |  | 	rm -f $(DOCS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | doc/%.pdf: doc/%.texi | 
					
						
							|  |  |  | 	texi2pdf --clean -o $@ -q $< | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | doc/%.html.pre: doc/%.texi | 
					
						
							|  |  |  | 	makeinfo --html --no-headers --no-split --number-sections -o $@ $< | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | doc/%.html: doc/%.html.pre | 
					
						
							|  |  |  | 	sed -e 's|</style>|</style>\n<meta name="viewport" content="width=device-width, initial-scale=1.0">|' < $< > $@ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ###############################################################################
 | 
					
						
							|  |  |  | # tests
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ifndef CONFIG_DARWIN | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | test: tests/bjson.so examples/point.so | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | ifdef CONFIG_M32 | 
					
						
							|  |  |  | test: qjs32 | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | test: qjs | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 	./qjs tests/test_closure.js | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	./qjs tests/test_language.js | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 	./qjs tests/test_builtin.js | 
					
						
							|  |  |  | 	./qjs tests/test_loop.js | 
					
						
							|  |  |  | 	./qjs tests/test_std.js | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	./qjs tests/test_worker.js | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | ifndef CONFIG_DARWIN | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | ifdef CONFIG_BIGNUM | 
					
						
							|  |  |  | 	./qjs --bignum tests/test_bjson.js | 
					
						
							|  |  |  | else | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 	./qjs tests/test_bjson.js | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	./qjs examples/test_point.js | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | ifdef CONFIG_BIGNUM | 
					
						
							|  |  |  | 	./qjs --bignum tests/test_op_overloading.js | 
					
						
							|  |  |  | 	./qjs --bignum tests/test_bignum.js | 
					
						
							|  |  |  | 	./qjs --qjscalc tests/test_qjscalc.js | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | ifdef CONFIG_M32 | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 	./qjs32 tests/test_closure.js | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	./qjs32 tests/test_language.js | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 	./qjs32 tests/test_builtin.js | 
					
						
							|  |  |  | 	./qjs32 tests/test_loop.js | 
					
						
							|  |  |  | 	./qjs32 tests/test_std.js | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	./qjs32 tests/test_worker.js | 
					
						
							|  |  |  | ifdef CONFIG_BIGNUM | 
					
						
							|  |  |  | 	./qjs32 --bignum tests/test_op_overloading.js | 
					
						
							|  |  |  | 	./qjs32 --bignum tests/test_bignum.js | 
					
						
							|  |  |  | 	./qjs32 --qjscalc tests/test_qjscalc.js | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | stats: qjs qjs32 | 
					
						
							|  |  |  | 	./qjs -qd | 
					
						
							|  |  |  | 	./qjs32 -qd | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | microbench: qjs | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	./qjs tests/microbench.js | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | microbench-32: qjs32 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | 	./qjs32 tests/microbench.js | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | # ES5 tests (obsolete)
 | 
					
						
							|  |  |  | test2o: run-test262 | 
					
						
							|  |  |  | 	time ./run-test262 -m -c test262o.conf | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test2o-32: run-test262-32 | 
					
						
							|  |  |  | 	time ./run-test262-32 -m -c test262o.conf | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test2o-update: run-test262 | 
					
						
							|  |  |  | 	./run-test262 -u -c test262o.conf | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Test262 tests
 | 
					
						
							|  |  |  | test2-default: run-test262 | 
					
						
							|  |  |  | 	time ./run-test262 -m -c test262.conf | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test2: run-test262 | 
					
						
							|  |  |  | 	time ./run-test262 -m -c test262.conf -a | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test2-32: run-test262-32 | 
					
						
							|  |  |  | 	time ./run-test262-32 -m -c test262.conf -a | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test2-update: run-test262 | 
					
						
							|  |  |  | 	./run-test262 -u -c test262.conf -a | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test2-check: run-test262 | 
					
						
							|  |  |  | 	time ./run-test262 -m -c test262.conf -E -a | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | testall: all test microbench test2o test2 | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | testall-32: all test-32 microbench-32 test2o-32 test2-32 | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | testall-complete: testall testall-32 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | bench-v8: qjs | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 	make -C tests/bench-v8 | 
					
						
							|  |  |  | 	./qjs -d tests/bench-v8/combined.js | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 18:10:00 +00:00
										 |  |  | tests/bjson.so: $(OBJDIR)/tests/bjson.pic.o | 
					
						
							| 
									
										
										
										
											2019-10-06 22:19:08 +00:00
										 |  |  | 	$(CC) $(LDFLAGS) -shared -o $@ $^ $(LIBS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | -include $(wildcard $(OBJDIR)/*.d) |