forked from ArtifexSoftware/mujs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
135 lines (98 loc) · 3.19 KB
/
Copy pathMakefile
File metadata and controls
135 lines (98 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Build type and install directories:
build ?= release
prefix ?= /usr/local
bindir ?= $(prefix)/bin
incdir ?= $(prefix)/include
libdir ?= $(prefix)/lib
ifeq "$(wildcard .git)" ".git"
VERSION := $(shell git describe --tags --always)
else
VERSION := $(shell basename $$PWD | sed -e s,^mujs-,,)
endif
# Compiler flags for various configurations:
CFLAGS := -std=c99 -pedantic -Wall -Wextra -Wno-unused-parameter
ifeq "$(CC)" "clang"
CFLAGS += -Wunreachable-code
endif
ifeq "$(shell uname)" "Linux"
CFLAGS += -ffunction-sections -fdata-sections
LDFLAGS += -Wl,--gc-sections
endif
ifeq "$(build)" "debug"
CFLAGS += -g
else ifeq "$(build)" "sanitize"
CFLAGS += -pipe -g -fsanitize=address -fno-omit-frame-pointer
LDFLAGS += -fsanitize=address
else
CFLAGS += -Os
LDFLAGS += -Wl,-s
endif
CFLAGS += $(XCFLAGS)
# You shouldn't need to edit anything below here.
OUT := build/$(build)
SRCS := $(wildcard js*.c utf*.c regexp.c)
HDRS := $(wildcard js*.h mujs.h utf.h regexp.h)
default: static
static: $(OUT) $(OUT)/mujs $(OUT)/libmujs.a $(OUT)/mujs.pc
shared: static $(OUT)/libmujs.so
astnames.h: jsparse.h
grep -E '(AST|EXP|STM)_' jsparse.h | sed 's/^[^A-Z]*\(AST_\)*/"/;s/,.*/",/' | tr A-Z a-z > $@
opnames.h: jscompile.h
grep -E 'OP_' jscompile.h | sed 's/^[^A-Z]*OP_/"/;s/,.*/",/' | tr A-Z a-z > $@
one.c: $(SRCS)
ls $(SRCS) | awk '{print "#include \""$$1"\""}' > $@
jsdump.c: astnames.h opnames.h
$(OUT):
mkdir -p $(OUT)
$(OUT)/main.o: main.c $(HDRS)
$(CC) $(CFLAGS) -o $@ -c $<
$(OUT)/libmujs.o: one.c $(HDRS)
$(CC) $(CFLAGS) -o $@ -c $<
$(OUT)/libmujs.a: $(OUT)/libmujs.o
$(AR) cru $@ $^
$(OUT)/libmujs.so: one.c $(HDRS)
$(CC) $(CFLAGS) -fPIC -shared -o $@ $< -lm
$(OUT)/mujs: $(OUT)/libmujs.o $(OUT)/main.o
$(CC) $(LDFLAGS) -o $@ $^ -lm
$(OUT)/mujs.pc:
@ echo Creating $@
@ echo > $@ Name: mujs
@ echo >> $@ Description: MuJS embeddable Javascript interpreter
@ echo >> $@ Version: $(VERSION)
@ echo >> $@ Cflags: -I$(incdir)
@ echo >> $@ Libs: -L$(libdir) -lmujs
@ echo >> $@ Libs.private: -lm
watch:
@ while ! inotifywait -q -e modify $(SRCS) $(HDRS) ; do time -p $(MAKE) ; done
install-common: release
install -d $(DESTDIR)$(incdir)
install -d $(DESTDIR)$(libdir)
install -d $(DESTDIR)$(libdir)/pkgconfig
install -d $(DESTDIR)$(bindir)
install -m 644 mujs.h $(DESTDIR)$(incdir)
install -m 644 build/release/mujs.pc $(DESTDIR)$(libdir)/pkgconfig
install -m 755 build/release/mujs $(DESTDIR)$(bindir)
install-static: install-common
install -m 644 build/release/libmujs.a $(DESTDIR)$(libdir)
install-shared: install-common
install -m 755 build/release/libmujs.so $(DESTDIR)$(libdir)
install: install-static
tarball:
git archive --format=zip --prefix=mujs-$(VERSION)/ HEAD > mujs-$(VERSION).zip
git archive --format=tar --prefix=mujs-$(VERSION)/ HEAD | gzip > mujs-$(VERSION).tar.gz
git archive --format=tar --prefix=mujs-$(VERSION)/ HEAD | xz > mujs-$(VERSION).tar.xz
tags: $(SRCS) main.c $(HDRS)
ctags $^
clean:
rm -rf build
nuke: clean
rm -f astnames.h opnames.h one.c
debug:
$(MAKE) build=debug
sanitize:
$(MAKE) build=sanitize
release:
$(MAKE) build=release shared
.PHONY: default static shared clean nuke
.PHONY: install install-common install-shared install-static
.PHONY: debug sanitize release