-
Notifications
You must be signed in to change notification settings - Fork 100
/
Makefile
170 lines (139 loc) · 4.43 KB
/
Makefile
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Makefile for building MuJS libraries, shell, and pretty-printer.
#
# Useful targets are: release, install, uninstall.
default: build/debug/mujs build/debug/mujs-pp
CFLAGS = -std=c99 -pedantic -Wall -Wextra -Wno-unused-parameter
OPTIM = -O3
prefix = /usr/local
bindir = $(prefix)/bin
incdir = $(prefix)/include
libdir = $(prefix)/lib
ifeq ($(wildcard .git),.git)
VERSION = $(shell git describe --tags --always)
else
VERSION = $(patsubst mujs-%,%,$(notdir $(CURDIR)))
endif
ifeq ($(shell uname),Darwin)
SO = dylib
else
SO = so
endif
ifeq ($(shell uname),FreeBSD)
CFLAGS += -I/usr/local/include -L/usr/local/lib
endif
HDRS = mujs.h jsi.h regexp.h utf.h astnames.h opnames.h
ifneq ($(HAVE_READLINE),no)
READLINE_CFLAGS = -DHAVE_READLINE
READLINE_LIBS = -lreadline
endif
SRCS = \
jsarray.c \
jsboolean.c \
jsbuiltin.c \
jscompile.c \
jsdate.c \
jsdtoa.c \
jserror.c \
jsfunction.c \
jsgc.c \
jsintern.c \
jslex.c \
jsmath.c \
jsnumber.c \
jsobject.c \
json.c \
jsparse.c \
jsproperty.c \
jsregexp.c \
jsrepr.c \
jsrun.c \
jsstate.c \
jsstring.c \
jsvalue.c \
regexp.c \
utf.c
one.c:
for F in $(SRCS); do echo "#include \"$$F\""; done > $@
astnames.h: jsi.h
grep -E '\<(AST|EXP|STM)_' jsi.h | sed 's/^[^A-Z]*\(AST_\)*/"/;s/,.*/",/' | tr A-Z a-z > $@
opnames.h: jsi.h
grep -E '\<OP_' jsi.h | sed 's/^[^A-Z]*OP_/"/;s/,.*/",/' | tr A-Z a-z > $@
UnicodeData.txt:
curl -s -o $@ https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt
utfdata.h: genucd.py UnicodeData.txt
python3 genucd.py UnicodeData.txt >$@
build/sanitize/mujs: main.c one.c $(SRCS) $(HDRS)
@mkdir -p $(@D)
$(CC) $(CFLAGS) -g -fsanitize=address -fno-omit-frame-pointer -o $@ main.c one.c -lm $(READLINE_CFLAGS) $(READLINE_LIBS)
build/debug/libmujs.$(SO): one.c $(SRCS) $(HDRS)
@mkdir -p $(@D)
$(CC) $(CFLAGS) -g -fPIC -shared -o $@ one.c -lm
build/debug/libmujs.o: one.c $(SRCS) $(HDRS)
@mkdir -p $(@D)
$(CC) $(CFLAGS) -g -c -o $@ one.c
build/debug/libmujs.a: build/debug/libmujs.o
$(AR) cr $@ $^
build/debug/mujs: main.c build/debug/libmujs.o
$(CC) $(CFLAGS) -g -o $@ $^ -lm $(READLINE_CFLAGS) $(READLINE_LIBS)
build/debug/mujs-pp: pp.c build/debug/libmujs.o
$(CC) $(CFLAGS) -g -o $@ $^ -lm
build/release/libmujs.$(SO): one.c $(SRCS) $(HDRS)
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(OPTIM) -fPIC -shared -o $@ one.c -lm
build/release/libmujs.o: one.c $(SRCS) $(HDRS)
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(OPTIM) -c -o $@ one.c
build/release/libmujs.a: build/release/libmujs.o
$(AR) cr $@ $^
build/release/mujs: main.c build/release/libmujs.o
$(CC) $(CFLAGS) $(OPTIM) -o $@ $^ -lm $(READLINE_CFLAGS) $(READLINE_LIBS)
build/release/mujs-pp: pp.c build/release/libmujs.o
$(CC) $(CFLAGS) $(OPTIM) -o $@ $^ -lm
build/release/mujs.pc:
@mkdir -p $(@D)
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
install-common: build/release/mujs build/release/mujs-pp build/release/mujs.pc
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 -m 755 build/release/mujs-pp $(DESTDIR)$(bindir)
install-static: install-common build/release/libmujs.a
install -m 644 build/release/libmujs.a $(DESTDIR)$(libdir)
install-shared: install-common build/release/libmujs.$(SO)
install -m 755 build/release/libmujs.$(SO) $(DESTDIR)$(libdir)
install: install-static
uninstall:
rm -f $(DESTDIR)$(bindir)/mujs
rm -f $(DESTDIR)$(bindir)/mujs-pp
rm -f $(DESTDIR)$(incdir)/mujs.h
rm -f $(DESTDIR)$(libdir)/pkgconfig/mujs.pc
rm -f $(DESTDIR)$(libdir)/libmujs.a
rm -f $(DESTDIR)$(libdir)/libmujs.$(SO)
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
tags: $(SRCS) $(HDRS) main.c pp.c
ctags $^
clean:
rm -rf build
nuke: clean
rm -f one.c astnames.h opnames.h
sanitize: build/sanitize/mujs
debug: build/debug/libmujs.a
debug: build/debug/libmujs.$(SO)
debug: build/debug/mujs
debug: build/debug/mujs-pp
release: build/release/mujs.pc
release: build/release/libmujs.a
release: build/release/libmujs.$(SO)
release: build/release/mujs
release: build/release/mujs-pp