aboutsummaryrefslogtreecommitdiff
path: root/clean/bin/install_clean
blob: 697ab2bf1f6210bff8a437569740887c7d1010b2 (plain) (blame)
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
#!/bin/bash

DEFAULT_PLATFORMS="x64 x86"
PACKAGES="base
	abc-interpreter
	lib-argenv
	lib-directory
	lib-dynamics
	lib-gast
	lib-graphcopy
	lib-itasks
	lib-platform
	lib-stdlib
	lib-tcpip
	test"

link_local_file ()
{
	DIR="$1"
	FROM="$2"
	TO="$3"

	mkdir -p "$(dirname "$DIR/$FROM")"
	if [ -f "$DIR/$FROM" ]; then
		mv "$DIR/$FROM" "$DIR/$FROM.org"
		ln -s "$(realpath --no-symlinks "$TO")" "$DIR/$FROM.new"
		ln -s "$(basename "$FROM").new" "$DIR/$FROM"
	else
		ln -s "$(realpath --no-symlinks "$TO")" "$DIR/$FROM"
	fi
}


install ()
{
	PLATFORM="$1"
	PACKAGES="$2"
	DIR="$3"

	if [ -d "$DIR" ]; then
		rm -rf "$DIR.bak"
		mv "$DIR" "$DIR.bak"
	else
		rm -rf "$DIR"
	fi

	mkdir -p "$DIR"
	for pkg in $PACKAGES
	do
		echo "Fetching $pkg..."
		curl -# ftp://ftp.cs.ru.nl/pub/Clean/builds/linux-$PLATFORM/clean-$pkg-linux-$PLATFORM-latest.tgz\
			| tar xz --strip-components=1 -C "$DIR"
	done

	grep -h '^[[:space:]]' "$DIR"/etc/*.env >> "$DIR/etc/IDEEnvs"
	if [[ "$PLATFORM" = "x86" ]]; then
		sed \
			-e 's/gc-sections/gc-sections -m32/' \
			-e 's/Linux-64/Linux-32/' \
			-e 's/Environment64BitProcessor:\tTrue/Environment64BitProcessor:\tFalse/' \
			~/.clean/iTasksDev.env >> "$DIR/etc/IDEEnvs"
	else
		cat ~/.clean/iTasksDev.env >> "$DIR/etc/IDEEnvs"
		tail -n +20 ~/projects/top/viia/config/IDEEnvs >> "$DIR/etc/IDEEnvs"
	fi

	sed -i 's/cocl-itasks:/cocl-itasks:-h 1000m /' "$DIR/etc/IDEEnvs"
	sed -i 's/\tPers$/\t3/' "$DIR/etc/IDEEnvs"

	ln -s lib/exe "$DIR/exe"

	# cloogletags
	cloogletags -q -q -a -c -d "$DIR/lib" -o "$DIR/lib/tags"

	# Local versions of binaries
	#link_local_file "$DIR" bin/cpm ~/projects/clean/ide/cpm/cpm

	link_local_file "$DIR" lib/exe/cocl /home/camil/projects/clean/compiler/cocl
	rm "$DIR/lib/exe/cocl"
	ln -s cocl.org "$DIR/lib/exe/cocl"

	#link_local_file "$DIR" lib/exe/cg /home/camil/projects/clean/code-generator/cg

	link_local_file "$DIR" bin/cleantest ~/projects/clean/test/cleantest
	link_local_file "$DIR" bin/testproperties ~/projects/clean/test-properties/src/testproperties

	link_local_file "$DIR" data/cleandoc-default ~/projects/clean/doc/data/cleandoc-default
	link_local_file "$DIR" bin/cleandoc ~/projects/clean/doc/src/cleandoc

	link_local_file "$DIR" bin/cleanprof2callgrind ~/projects/clean/prof2callgrind/cleanprof2callgrind

	# ABC interpreter binaries
	link_local_file "$DIR" lib/exe/abcopt ~/projects/clean/abc-interpreter/src/abcopt
	link_local_file "$DIR" lib/exe/bcgen ~/projects/clean/abc-interpreter/src/bcgen
	link_local_file "$DIR" lib/exe/bclink ~/projects/clean/abc-interpreter/src/bclink
	link_local_file "$DIR" lib/exe/bcprelink ~/projects/clean/abc-interpreter/src/bcprelink
	link_local_file "$DIR" lib/exe/bcstrip ~/projects/clean/abc-interpreter/src/bcstrip

	# completion
	for f in ~/projects/clean/bash-completion/*; do
		[ -f "$f" ] || continue
		base="$(basename "$f")"
		if [[ "$base" == "Makefile" ]] || [[ "$base" == "README.md" ]] || [[ "$base" =~ .tar.gz$ ]]; then
			continue
		fi
		link_local_file $DIR "etc/completion/$base" "$f"
	done
}

PLATFORMS=$@
if [ -z "$PLATFORMS" ]; then
	PLATFORMS="$DEFAULT_PLATFORMS"
fi

for PLATFORM in $PLATFORMS
do
	install $PLATFORM "$PACKAGES" "$CLEAN_HOME-$PLATFORM"

	if [ ! -e "$CLEAN_HOME" ]; then
		ln -s "$CLEAN_HOME-$PLATFORM" "$CLEAN_HOME"
	fi
done