forked from ooc-lang/rock
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
113 lines (97 loc) · 3.81 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
.PHONY: all clean mrproper prepare_bootstrap bootstrap install rescue backup
PARSER_GEN=greg
NQ_PATH=source/rock/frontend/NagaQueen.c
DATE=$(shell date +%Y-%m-%d)
TIME=$(shell date +%H:%M)
OOC_WARN_FLAGS?=+-w
OOC_OWN_FLAGS=-sourcepath=source -v +-O0 -g -ignoredefine=ROCK_BUILD_ ${OOC_WARN_FLAGS}
# 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
ifdef WINDIR
OOC_OWN_FLAGS+=+-DROCK_BUILD_DATE=\\\"${DATE}\\\" +-DROCK_BUILD_TIME=\\\"${TIME}\\\"
else
OOC_OWN_FLAGS+=+-DROCK_BUILD_DATE=\"${DATE}\" +-DROCK_BUILD_TIME=\"${TIME}\" +-rdynamic
endif
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/nddrylliog/nagaqueen
# http://github.com/nddrylliog/greg
grammar:
${PARSER_GEN} ../nagaqueen/grammar/nagaqueen.leg > ${NQ_PATH}
$(MAKE) .libs/NagaQueen.o
.libs/NagaQueen.o: source/rock/frontend/NagaQueen.c
mkdir -p .libs
${CC} -std=c99 ${NQ_PATH} -O3 -fomit-frame-pointer -D__OOC_USE_GC__ -w -c -o .libs/NagaQueen.o
# gcc -std=c99 ${NQ_PATH} -O0 -g -D__OOC_USE_GC__ -w -c -o .libs/NagaQueen.o
# 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 boostrap (in build/ directory)"
rm -rf build/
${OOC} -driver=make -sourcepath=source -outpath=c-source rock/rock -o=../bin/c_rock c-source/${NQ_PATH} -v -g +-w
ifeq ($(shell uname -s), FreeBSD)
sed s/-w.*/-w\ -DROCK_BUILD_DATE=\\\"\\\\\"bootstrapped\\\\\"\\\"\ -DROCK_BUILD_TIME=\\\"\\\\\"\\\\\"\\\"/ build/Makefile > build/Makefile.tmp
rm build/Makefile
mv build/Makefile.tmp build/Makefile
else
sed s/-w.*/-w\ -DROCK_BUILD_DATE=\\\"\\\\\"bootstrapped\\\\\"\\\"\ -DROCK_BUILD_TIME=\\\"\\\\\"\\\\\"\\\"/ -i build/Makefile
endif
cp ${NQ_PATH} build/c-source/${NQ_PATH}
@echo "Done!"
boehmgc:
cd libs && $(MAKE)
# 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"
cd build/ && ROCK_DIST=.. $(MAKE)
@echo "Now re-compiling ourself"
OOC=bin/c_rock ROCK_DIST=. $(MAKE) self
@echo "Congrats! you have a boostrapped version of rock in bin/rock now. Have fun!"
else
@cat BOOTSTRAP
@exit 1
endif
# 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 $(shell pwd)/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: .libs/NagaQueen.o
mkdir -p bin/
${OOC_CMD} rock/rock -o=bin/rock .libs/NagaQueen.o
# Save your rock binary under bin/safe_rock
backup:
cp bin/rock bin/safe_rock
# Attempt to grab a rock bootstrap from Alpaca and recompile
rescue:
rm -rf build/
# Note: don't use --no-check-certificate, OSX is retarded
# Note: someone make a curl fallback already
wget --no-check-certificate http://www.fileville.net/ooc/bootstrap.tar.bz2 -O - | tar xjvmp 1>/dev/null
if [ ! -e build ]; then cp -rfv rock-*/build ./; fi
$(MAKE) clean bootstrap
# Compile rock with the backup'd version of itself
safe:
OOC=bin/safe_rock $(MAKE) self
# Clean all temporary files that may make a build fail
clean:
rm -rf *_tmp/ .libs/
rm -rf `find build/ -name '*.o'`