Repository navigation
Expand file tree
/
Copy pathinstall_fpc_lazarus
More file actions
executable file
·217 lines (185 loc) · 7.11 KB
/
Copy pathinstall_fpc_lazarus
File metadata and controls
executable file
·217 lines (185 loc) · 7.11 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
set -eu
# ----------------------------------------------------------------------------
# Get from version control FPC, Lazarus and build + install them system-wide.
#
# In a way, this is a "simplest version of fpcup / fpcupdeluxe".
# This strives to be a simplest command-line script that gets FPC and Lazarus
# from version control and installs.
#
# Note: This assumes that FPC version suitable for "boostrapping" the indicated
# version (in FPC_BRANCHTAG) is already installed and on $PATH.
# E.g. you can do "apt install fpc" if your OS ships with proper FPC version
# (equal or one before FPC_BRANCHTAG).
# Alternatively you can uncomment and adjust BOOTSTRAP_FPC below to use
# some ready FPC versions for bootstrapping inside this repo.
# There is no need for Lazarus for bootstrapping.
#
# Author: Michalis Kamburelis
# License: permissive "modified BSD (3-clause)", https://github.com/castle-engine/castle-engine/blob/master/doc/licenses/COPYING.BSD-3-clause.txt
#
# To use the installed FPC and Lazarus, it's simplest to
# 1. Add them on $PATH.
# 2. Always call FPC using "fpc.sh",
# or include the ${FPC_INSTALL}/fpc.cfg to ~/.fpc.cfg.
# This is important when calling FPC from Lazarus (IDE or lazbuild) too,
# they also must call "fpc.sh" or you have to extend ~/.fpc.cfg .
# ----------------------------------------------------------------------------
# Configure these variables freely
# FPC branch or tag.
# See for possibilities:
# https://gitlab.com/freepascal.org/fpc/source/-/tags
# https://gitlab.com/freepascal.org/fpc/source/-/branches
FPC_BRANCHTAG='release_3_2_2'
#FPC_BRANCHTAG='fixes_3_2'
# Lazarus branch or tag.
# See for posibilities:
# https://gitlab.com/freepascal.org/lazarus/lazarus/-/tags
# https://gitlab.com/freepascal.org/lazarus/lazarus/-/branches
#LAZARUS_BRANCHTAG='main' # use this for very latest commit
LAZARUS_BRANCHTAG='lazarus_3_8'
# Must match FPC version in install directory.
# Also used to name src/install subdirectories of FPC.
FPC_VERSION='3.2.2'
# Used to name src/install subdirectories of Lazarus.
LAZARUS_VERSION='3.8'
# ppc binary suffix corresponding to current system architecture.
# FPC team invent 3-letter suffix for all architectures.
# Examples below.
PPC_SUFFIX='x64'
# Arm (32-bit)
#PPC_SUFFIX='arm'
# Aarch64 (aka Arm 64-bit)
#PPC_SUFFIX='a64'
# Current architecture and OS, used by FPC to name the units subdirectory.
# Correspond to FPC OS and CPU names, can also be seen in "castle-engine --help"
# as CGE uses the same OS and CPU names for consistency with FPC.
FPC_ARCH='x86_64'
#FPC_ARCH='arm'
#FPC_ARCH='aarch64'
FPC_OS='linux'
# Building given FPC version requires having last stable
# FPC version installed and on $PATH.
# Or, uncomment and adjust line below to use specific version
# for bootstrapping.
#BOOTSTRAP_FPC=FPC=`pwd`/bootstrap-fpc/3.2.2/ppca64
BOOTSTRAP_FPC='FPC=fpc'
# source install_fpc_lazarus.config, if exists, so that it can override
# the parameters above.
# Create it e.g. by "cp install_fpc_lazarus.config.linux_aarch64 install_fpc_lazarus.config"
if [ -f install_fpc_lazarus.config ]; then
source install_fpc_lazarus.config
fi
# ----------------------------------------------------------------------------
# Calculated variables. Cannot be adjusted by install_fpc_lazarus.config .
# TODO: But we could allow it, just define these only if not defined already.
# FPC and Lazarus sources and installed files will be under this.
# Our current scheme is to
# - create subdirectory like fpcXXX-lazarusYYY
# (since these FPC/Lazarus versions should be used together, as this FPC was used for this Lazarus)
# - underneath there will be bin/ lib/ and other subdirs created by FPC and Lazarus "make install"
# We put them both under the same subdir.
# This also gives one simple ${BASE_DIR}/bin.
# - sources are in src/ .
BASE_DIR="$HOME/installed/fpclazarus/cge-scripts-fpc${FPC_VERSION}-lazarus${LAZARUS_VERSION}"
FPC_INSTALL="$BASE_DIR"
LAZARUS_INSTALL="$BASE_DIR"
FPC_SRC_PARENT="$BASE_DIR/src/fpc"
LAZARUS_SRC_PARENT="$BASE_DIR/src/lazarus"
FPC_SRC="$FPC_SRC_PARENT/$FPC_VERSION"
LAZARUS_SRC="$LAZARUS_SRC_PARENT/$LAZARUS_VERSION"
# ----------------------------------------------------------------------------
# End of configurable section.
export PATH="${BASE_DIR}/bin:${PATH}"
do_cleanup ()
{
rm -Rf "${BASE_DIR}"
}
do_get_fpc_lazarus ()
{
mkdir -p "$FPC_SRC_PARENT" "$LAZARUS_SRC_PARENT"
cd "$FPC_SRC_PARENT"
git clone https://gitlab.com/freepascal.org/fpc/source.git --depth 1 \
--single-branch --branch "${FPC_BRANCHTAG}" "${FPC_VERSION}"
cd "$LAZARUS_SRC_PARENT"
git clone https://gitlab.com/freepascal.org/lazarus/lazarus.git --depth 1 \
--single-branch --branch "${LAZARUS_BRANCHTAG}" "${LAZARUS_VERSION}"
}
do_install_fpc ()
{
cd "$FPC_SRC"
mkdir -p "${FPC_INSTALL}"
make clean all install INSTALL_PREFIX="${FPC_INSTALL}" ${BOOTSTRAP_FPC}
cd "${FPC_INSTALL}"/bin
ln -s ../lib/fpc/"${FPC_VERSION}"/ppc"$PPC_SUFFIX" .
# make "current" symlink, useful e.g. by fpc.cfg, and $FPCDIR if you want it
rm -f "${FPC_INSTALL}"/lib/fpc/current/
ln -s "${FPC_VERSION}" "${FPC_INSTALL}"/lib/fpc/current
cat > "${FPC_INSTALL}/fpc.cfg" <<EOF
-Fu${FPC_INSTALL}/lib/fpc/current/units/${FPC_ARCH}-${FPC_OS}/*
EOF
cat > "${FPC_INSTALL}/bin/fpc.sh" <<EOF
#!/bin/bash
set -eu
${FPC_INSTALL}/bin/fpc -n @${FPC_INSTALL}/fpc.cfg "\$@"
EOF
chmod +x "${FPC_INSTALL}/bin/fpc.sh"
}
do_test_fpc ()
{
cd /tmp/
echo 'Testing FPC on /tmp/install_fpc_lazarus_test.pas'
# Test new fpc - compile something (using some units, to make sure they are set up)
echo 'uses SysUtils; begin Writeln(2+2) end.' > install_fpc_lazarus_test.pas
"${FPC_INSTALL}/bin/fpc.sh" -l install_fpc_lazarus_test.pas
./install_fpc_lazarus_test
}
do_install_lazarus ()
{
cd "$LAZARUS_SRC"
mkdir -p "${LAZARUS_INSTALL}"
make clean all install INSTALL_PREFIX="${LAZARUS_INSTALL}" PP="${FPC_INSTALL}/bin/fpc.sh"
# fix lazbuild to work, by passing --lazarusdir
mv "${LAZARUS_INSTALL}/bin/lazbuild" "${LAZARUS_INSTALL}/bin/lazbuild-real"
cat > "${LAZARUS_INSTALL}/bin/lazbuild" <<EOF
#!/bin/bash
set -eu
# DO NOT EDIT - this file is auto-generated and may be overridden.
# Created by CGE FPC/Lazarus compilation script.
${LAZARUS_INSTALL}/bin/lazbuild-real --lazarusdir=${LAZARUS_SRC} "\$@"
EOF
chmod +x "${LAZARUS_INSTALL}/bin/lazbuild"
}
do_test_lazarus ()
{
"${LAZARUS_INSTALL}/bin/lazbuild" --version
}
do_done ()
{
echo "----------------------------------------------------------------------"
echo "Done."
echo "Installed FPC in ${FPC_INSTALL}"
"${FPC_INSTALL}/bin/fpc.sh" -iV
echo "Installed Lazarus in ${LAZARUS_INSTALL}"
"${LAZARUS_INSTALL}/bin/lazbuild" --version
echo "To use them:"
echo
echo "1. You *may* add them to \$PATH (unless you will always run by providing full path), like this:"
cat <<EOF
export PATH="${BASE_DIR}/bin:\${PATH}"
EOF
echo
echo '2. Make sure that FPC always uses proper config:'
echo '2.1. Always call FPC using "fpc.sh".'
echo '2.2. Or extend your FPC configuration, by adding this to ~/.fpc.cfg:'
cat <<EOF
#INCLUDE ${FPC_INSTALL}/fpc.cfg
EOF
}
do_cleanup
do_get_fpc_lazarus
do_install_fpc
do_test_fpc
do_install_lazarus
do_test_lazarus
do_done