-
Notifications
You must be signed in to change notification settings - Fork 40
/
Makefile
145 lines (120 loc) · 4.23 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
.PHONY: all clean mrproper prepare_bootstrap bootstrap install download-bootstrap rescue backup extensions extensions-clean
.SILENT: extensions extensions-clean
VENDOR_PREFIX:=$(CURDIR)/vendor-prefix
PARSER_GEN:=greg
NQ_PATH:=source/rock/frontend/NagaQueen.c
OOC_WARN_FLAGS?=+-w
OOC_OWN_FLAGS:=-v -pg -O3 $(OOC_WARN_FLAGS) --gc=dynamic
ifneq (${EXTERNAL_GC},)
OOC_OWN_FLAGS+=+-I/usr/local/include +-L/usr/local/lib
else
OOC_OWN_FLAGS+=-I$(VENDOR_PREFIX)/include -L$(VENDOR_PREFIX)/lib
endif
# used to be CC?=gcc, but that breaks on mingw where CC is set to 'cc' apparently
CC=gcc
PREFIX?=/usr
MAN_INSTALL_PATH?=/usr/local/man/man1
BIN_INSTALL_PATH?=$(PREFIX)/bin
OOC?=rock
OOC_CMD:=$(OOC) $(OOC_OWN_FLAGS) $(OOC_FLAGS)
IS_BOOTSTRAP:=$(wildcard build/Makefile)
all: bootstrap
# Regenerate NagaQueen.c from the greg grammar
# you need ../nagaqueen and greg to be in your path
#
# http://github.com/ooc-lang/nagaqueen
# http://github.com/ooc-lang/greg
grammar:
$(PARSER_GEN) ../nagaqueen/grammar/nagaqueen.leg > $(NQ_PATH)
# Prepares the build/ directory, used for bootstrapping
# The build/ directory contains all the C sources needed to build rock
# and a nice Makefile, too
prepare_bootstrap:
@echo "Preparing bootstrap (in build/ directory)"
rm -rf build/
$(OOC) -driver=make rock.use --outpath=c-source -o=../bin/c_rock -v -pg +-w
@echo "Done!"
boehmgc: vendor-prefix/lib/libgc.a
vendor-prefix/lib/libgc.a:
ifneq (${EXTERNAL_GC},)
@echo "EXTERNAL_GC is set, using os-provided Boehm GC library"
else
$(MAKE) boehmgc-clean
mkdir -p $(VENDOR_PREFIX)
mkdir -p vendor-build
(cd vendor-build && ../vendor/gc/configure --prefix=$(VENDOR_PREFIX) --disable-shared --enable-static ${GC_FLAGS} && $(MAKE) && $(MAKE) install)
rm -rf vendor-build
endif
boehmgc-clean:
rm -rf vendor-prefix vendor-build
# For c-source based rock releases, 'make bootstrap' will compile a version
# of rock from the C sources in build/, then use that version to re-compile itself
bootstrap: boehmgc
ifneq ($(IS_BOOTSTRAP),)
@echo "Creating bin/ in case it does not exist."
mkdir -p bin/
@echo "Compiling from C source"
ifneq (${EXTERNAL_GC},)
cd build/ && ROCK_DIST=.. GC_PATH="-lgc" $(MAKE) -j4
else
cd build/ && ROCK_DIST=.. CFLAGS="-I$(VENDOR_PREFIX)/include" LDFLAGS="-L$(VENDOR_PREFIX)/lib" GC_PATH="-lgc" PREFIX=$(VENDOR_PREFIX) $(MAKE) -j4
endif
@echo "Now re-compiling ourself"
OOC=bin/c_rock ROCK_DIST=. $(MAKE) self
@echo "Congrats! you have a bootstrapped version of rock in bin/rock now. Have fun!"
else
@cat BOOTSTRAP
@exit 1
endif
half-bootstrap: boehmgc
@echo "Creating bin/ in case it does not exist."
mkdir -p bin/
@echo "Compiling from C source"
cd build/ && ROCK_DIST=.. $(MAKE) -j4
@echo "Renaming c_rock to rock"
mv bin/c_rock bin/rock
@echo "Congrats! you have a half-bootstrapped version of rock in bin/rock now. Have fun!"
# Copy the manpage and create a symlink to the binary
install:
if [ -e $(BIN_INSTALL_PATH)/rock ]; then echo "$(BIN_INSTALL_PATH)/rock already exists, overwriting."; rm -f $(BIN_INSTALL_PATH)/rock $(BIN_INSTALL_PATH)/rock.exe; fi
ln -s $(CURDIR)/bin/rock* $(BIN_INSTALL_PATH)/
install -d $(MAN_INSTALL_PATH)
install docs/rock.1 $(MAN_INSTALL_PATH)/
# Regenerate the man page from docs/rock.1.txt You need ascidoc for that
man:
cd docs/ && a2x -f manpage rock.1.txt
# Compile rock with itself
self:
mkdir -p bin/
$(OOC_CMD) rock.use -o=bin/rock
# Save your rock binary under bin/safe_rock
backup:
cp bin/rock bin/safe_rock
download-bootstrap:
rm -rf build/
utils/download-bootstrap.sh
if [ ! -e build ]; then cp -rfv rock-*/build ./; fi
# Attempt to grab a rock bootstrap from Alpaca and recompile
rescue: download-bootstrap
$(MAKE) clean bootstrap
quick-rescue: download-bootstrap
$(MAKE) clean half-bootstrap
# Compile rock with the backup'd version of itself
safe: clean
OOC='bin/safe_rock' $(MAKE) self
bootstrap_tarball:
ifeq ($(VERSION),)
@echo "You must specify VERSION. Generates rock-VERSION-bootstrap-only.tar.bz2"
else
$(MAKE) prepare_bootstrap
tar cjvfm rock-$(VERSION)-bootstrap-only.tar.bz2 build
endif
# Clean all temporary files that may make a build fail
clean:
rm -rf *_tmp/ .libs/
rm -rf `find build/ -name '*.o'`
# === Extensions ===
extensions:
cd extensions && $(MAKE)
extensions-clean:
cd extensions && $(MAKE) clean