forked from pure-c/purec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
134 lines (107 loc) · 3.07 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
.PHONY: clean deps deps/npm deps/bwdgc purec test test/build
CLANG ?= clang
CFLAGS ?=
SHELL := /bin/bash
SHELLFLAGS := -eo pipefail
PURS := PATH=$$PATH:node_modules/.bin purs
PULP := PATH=$$PATH:node_modules/.bin pulp
PUREC_JS := purec.js
PUREC := node $(PUREC_JS)
PUREC_WORKDIR := .purec-work
BWDGC_V := v8.0.0
PUREC_LIB := libpurec.a
PUREC_INTERMEDIATE_LIB := libpurec.intermediate.a
BWDGC_LIB := deps/bwdgc/.libs/libgc.a
RUNTIME_SOURCES = \
runtime/purescript.c \
$(shell find ccan -type f -name '*.c') \
$(shell find vendor -type f -name '*.c')
RUNTIME_OBJECTS = \
$(patsubst %.c,%.o,$(RUNTIME_SOURCES))
CFLAGS += \
-D 'uthash_malloc=GC_malloc' \
-D 'uthash_free(ptr, sz)=NULL' \
-D 'vec_realloc=GC_realloc' \
-D 'vec_free(x)=NULL' \
-D 'vec_malloc=GC_malloc'
$(BWDGC_LIB):
@$(MAKE) -s deps/bwdgc
@cd deps/bwdgc && \
./autogen.sh && \
./configure --enable-static && \
$(MAKE)
$(PUREC_INTERMEDIATE_LIB): $(RUNTIME_OBJECTS)
@ar csr $@ $^
$(PUREC_LIB): $(PUREC_INTERMEDIATE_LIB) $(BWDGC_LIB)
@rm -rf .build
@mkdir -p .build
@cd .build &&\
for a in $^; do\
ar x ../$$a;\
done &&\
ar csr $@ $$(find . -type f -name '*.o')&&\
cp $@ ..
.PHONY: $(PUREC_LIB)
purec:
@npm run build
clean:
@rm -rf $(PUREC_WORKDIR)
@rm -f $(RUNTIME_OBJECTS)
@rm -f $$(find . -name '*.out')
@rm -f $$(find . -maxdepth 1 -name '*.a')
@rm -rf $$(find examples -type d -name $(PUREC_WORKDIR))
%.o: %.c | $(BWDGC_LIB)
@echo "Compile" $^
@$(CLANG) $^ -c -o $@ \
-Wall \
-Wno-unused-variable \
-Wno-unused-value \
-I runtime \
-I . \
$(CFLAGS)
#-------------------------------------------------------------------------------
# Dependencies
#-------------------------------------------------------------------------------
deps:\
deps/npm\
deps/bwdgc
deps/npm:
@npm install
@node_modules/.bin/bower install
deps/bwdgc:
@if [ ! -d deps/bwdgc ]; then \
if [ ! -f gc.tar.gz ]; then \
echo "downloading bwdgc tarball...";\
curl -sfLo gc.tar.gz \
'https://api.github.com/repos/ivmai/bdwgc/tarball/$(BWDGC_V)'; \
fi && \
mkdir -p deps/bwdgc && \
tar -C deps/bwdgc -xzf gc.tar.gz --strip-components 1; \
fi
#-------------------------------------------------------------------------------
# Tests
#-------------------------------------------------------------------------------
# note: this is temporary while building up the project
test: examples/bower_components
test/examples:
@$(MAKE) -s examples
@./examples/example1/main.out <<< "john"
@./examples/example2/main.out
@./examples/effect/main.out
.PHONY: test/examples
test/pulp: upstream/tests/support/bower_components
$(PULP) test
.PHONY: test/pulp
test: test/examples test/pulp
#-------------------------------------------------------------------------------
# Examples
#-------------------------------------------------------------------------------
examples: purec examples/bower_components
@$(MAKE) -s -C examples/example1
@$(MAKE) -s -C examples/example2
@$(MAKE) -s -C examples/effect
.PHONY: examples
%/bower_components:
@ROOT=$(PWD) &&\
cd "$(dir $@)" &&\
"$$ROOT/node_modules/.bin/bower" install