-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
core.functions
424 lines (352 loc) · 12.4 KB
/
core.functions
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#
# Core functions for 'Marisa' build system
#
# Copyright (c) 2016-2021 Ataraxia GNU/Linux <ataraxialinux@protonmail.com>
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
msg() { printf "\033[1;34m::\033[0m %s\n" "$@"; }
die() { printf "\033[1;31m::\033[0m %s\n" "$@"; exit 1; }
pushd () { command pushd "$@" > /dev/null; }
popd () { command popd "$@" > /dev/null; }
check_for_root() {
if [[ $EUID -ne 0 ]]; then
die 'You must be root to run `build`'
fi
}
check_for_arch() {
if [ -z "$1" ]; then
die 'Architecture is not specified'
fi
}
parse_architecture() {
check_for_arch "$1"
case "$1" in
x86_64) export XTARGET="x86_64-linux-musl" ;;
i386) export XTARGET="i386-linux-musl" ;;
arm64) export XTARGET="aarch64-linux-musl" ;;
arm) export XTARGET="armv7l-linux-musleabihf" ;;
powerpc64le) export XTARGET="powerpc64le-linux-musl" ;;
powerpc64) export XTARGET="powerpc64-linux-musl" ;;
powerpc) export XTARGET="powerpc-linux-musl" ;;
powerpcspe) export XTARGET="powerpc-linux-muslspe" ;;
riscv64) export XTARGET="riscv64-linux-musl" ;;
*) die 'Architecture called `'${1}'` is not supported by Ataraxia GNU/Linux' ;;
esac
export XHOST="$(echo $(clang -dumpmachine) | sed -e 's/-[^-]*/-cross/')"
}
export_variables() {
check_for_arch "$1"
parse_architecture "$1"
export CWD="$(pwd)"
export BUILD="$CWD/OUT.$1"
export SOURCES="$BUILD/sources"
export PACKAGES="$BUILD/packages"
export ROOTFS="$BUILD/rootfs"
export TOOLS="$BUILD/tools"
export STUFF="$CWD/stuff"
export REPO="$CWD/packages"
export TCREPO="$CWD/toolchain"
export UTILS="$CWD/utils"
export PATH="$TOOLS/bin:$PATH"
export HOSTCC="clang"
export HOSTCXX="clang++"
export ORIGMAKE="$(command -v make)"
if [ "$CCACHE" == "1" ]; then
if [ -e "/usr/lib/ccache" ]; then
export PATH="/usr/lib/ccache:$PATH"
elif [ -e "/usr/lib/ccache/bin" ]; then
export PATH="/usr/lib/ccache/bin:$PATH"
elif [ -e "/usr/lib/ccache" ]; then
export PATH="/usr/lib64/ccache:$PATH"
elif [ -e "/usr/lib/ccache/bin" ]; then
export PATH="/usr/lib64/ccache/bin:$PATH"
fi
fi
if [ -z "$JOBS" ]; then
export MKOPTS="-j$(expr $(nproc) + 1)"
fi
if [ -f "/sys/fs/selinux/enforce" ] && [ "$NOSECHECK" != "1" ]; then
echo 0 > /sys/fs/selinux/enforce
fi
}
export_cflags() {
check_for_arch "$1"
case "$1" in
x86_64|i386)
export xcflags="-D_FORTIFY_SOURCE=2 -g0 -Os -flto -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables -ffunction-sections -fdata-sections -fstack-protector-strong -fstack-clash-protection -mretpoline --param=ssp-buffer-size=4 -pipe"
export xldflags="-Wl,-z,relro,-z,now -Wl,--as-needed -Wl,--gc-sections -Wl,-z,noexecstack -s"
;;
arm64)
export xcflags="-D_FORTIFY_SOURCE=2 -g0 -Os -flto -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables -ffunction-sections -fdata-sections -fstack-protector-strong --param=ssp-buffer-size=4 -pipe"
export xldflags="-Wl,-z,relro,-z,now -Wl,--as-needed -Wl,--gc-sections -Wl,-z,noexecstack -s"
;;
arm)
export xcflags="-D_FORTIFY_SOURCE=2 -g0 -Os -flto -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables -ffunction-sections -fdata-sections -fstack-protector-strong -fsanitize=cfi --param=ssp-buffer-size=4 -pipe"
export xldflags="-Wl,-z,relro,-z,now -Wl,--as-needed -Wl,--gc-sections -Wl,-z,noexecstack -s"
;;
powerpc64le|powerpc64|powerpc|powerpcspe)
export xcflags="-D_FORTIFY_SOURCE=2 -g0 -Os -flto -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables -ffunction-sections -fdata-sections -fstack-protector-strong -fstack-clash-protection --param=ssp-buffer-size=4 -pipe"
export xldflags="-Wl,-z,relro,-z,now -Wl,--as-needed -Wl,--gc-sections -Wl,-z,noexecstack -s"
;;
riscv64)
export xcflags="-D_FORTIFY_SOURCE=2 -g0 -Os -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables -ffunction-sections -fdata-sections -fstack-protector-strong --param=ssp-buffer-size=4 -pipe"
export xldflags="-Wl,-z,relro,-z,now -Wl,--as-needed -Wl,--gc-sections -Wl,-z,noexecstack -s"
;;
*)
export xcflags="-D_FORTIFY_SOURCE=2 -g0 -Os -flto -fomit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables -ffunction-sections -fdata-sections -fstack-protector-strong --param=ssp-buffer-size=4 -pipe"
export xldflags="-Wl,-z,relro,-z,now -Wl,--as-needed -Wl,--gc-sections -Wl,-z,noexecstack -s"
;;
esac
}
generate_config() {
if [ "$target" = "1" ]; then
cat > "$1" <<- EOF
# Target configuration
export BARCH="$BARCH"
export XHOST="$XHOST"
export XTARGET="$XTARGET"
export BUILDFLAGS="--build=$XHOST --host=$XTARGET"
export TOOLFLAGS="--build=$XHOST --host=$XTARGET --target=$XTARGET"
export PERLFLAGS="--target=$XTARGET"
export CMAKEFLAGS="-DCMAKE_CROSSCOMPILING=ON -DCMAKE_TOOLCHAIN_FILE=$TOOLS/share/cmake/cmake.cross"
# Host tools configuration
export PATH="$PATH"
export HOSTCC="$HOSTCC"
export HOSTCXX="$HOSTCXX"
export HOSTLD="ld.lld"
export HOSTAR="llvm-ar"
export ORIGMAKE="$ORIGMAKE"
export MAKEINFO=true
# Target tools configuration
export CROSS_COMPILE="$XTARGET-"
export CC="$XTARGET-clang"
export CXX="$XTARGET-clang++"
export AR="$XTARGET-ar"
export AS="$XTARGET-as"
export RANLIB="$XTARGET-ranlib"
export LD="$XTARGET-ld"
export LDBFD="$(command -v $XTARGET-ld.bfd)"
export STRIP="$XTARGET-strip"
export OBJCOPY="$XTARGET-objcopy"
export OBJDUMP="$XTARGET-objdump"
export SIZE="$XTARGET-size"
# Compiler flags
export CFLAGS="$xcflags"
export CXXFLAGS="$xcflags"
export LDFLAGS="$xldflags"
# Host compiler flags
export HOSTCFLAGS=""
export HOSTCXXFLAGS=""
export HOSTLDFLAGS=""
# Paths configuration
export ROOTFS="$ROOTFS"
export STAGING_INCDIR="$ROOTFS/usr/include"
export STAGING_LIBDIR="$ROOTFS/usr/lib"
export TOOLS="$TOOLS"
export STUFF="$STUFF"
# pkg-config configuration
export PKG_CONFIG="$XTARGET-pkgconf"
export PKG_CONFIG_LIBDIR="$ROOTFS/usr/lib/pkgconfig:$ROOTFS/usr/share/pkgconfig"
export PKG_CONFIG_PATH="$ROOTFS/usr/lib/pkgconfig:$ROOTFS/usr/share/pkgconfig"
export PKG_CONFIG_SYSROOT_DIR="$ROOTFS"
export PKG_CONFIG_SYSTEM_INCLUDE_PATH="$ROOTFS/usr/include"
export PKG_CONFIG_SYSTEM_LIBRARY_PATH="$ROOTFS/usr/lib"
# Package manager configuration
export mkopts="$MKOPTS"
export buildoptions=('emptydirs' 'strip' 'makeflags' '~locales' '~docs' 'ccache' '~libtool' '~nobootstrap')
export repos="$REPO"
export pkgdest="$PACKAGES"
export srcdest="$SOURCES"
EOF
elif [ "$host" = "1" ]; then
cat > "$1" <<- EOF
# Target configuration
export BARCH="$BARCH"
export XHOST="$XHOST"
export XTARGET="$XTARGET"
# Host tools configuration
export PATH="$PATH"
export CC="$HOSTCC"
export CXX="$HOSTCXX"
export HOSTCC="$HOSTCC"
export HOSTCXX="$HOSTCXX"
export ORIGMAKE="$ORIGMAKE"
export MAKEINFO=true
# Compiler flags
export CFLAGS=""
export CXXFLAGS=""
export LDFLAGS=""
# Compiler flags for target
export TARGET_CFLAGS="$xcflags"
export TARGET_CXXFLAGS="$xcflags"
export TARGET_LDFLAGS="$xldflags"
# Paths configuration
export ROOTFS="$ROOTFS"
export TOOLS="$TOOLS"
export REPO="$REPO"
export STUFF="$STUFF"
# pkg-config configuration
export PKG_CONFIG="$(which pkg-config)"
# Package manager configuration
export mkopts="$MKOPTS"
export buildoptions=('emptydirs' 'strip' 'makeflags' 'locales' 'docs' 'ccache' 'libtool' '~nobootstrap')
export repos="$TCREPO"
export pkgdest="$PACKAGES"
export srcdest="$SOURCES"
EOF
fi
}
make_environment() {
rm -rf "$BUILD"
mkdir -p "$BUILD" "$SOURCES" "$PACKAGES" "$ROOTFS/usr/lib/tsukuri/db" "$TOOLS"
host=1 generate_config "$BUILD"/host.config
target=1 generate_config "$BUILD"/target.config
}
emerge_host() {
if [ -z "$1" ]; then
die 'Package was not specified'
fi
if [ ! -f "$TCREPO/host-${1}/KagamiBuild" ]; then
die 'Package does not exist'
fi
pushd "$TCREPO/host-${1}"
tsukuri bi -c "$BUILD/host.config" -wp
popd
}
emerge_target() {
local root
if [ -z "$1" ]; then
die 'Package was not specified'
fi
if [ -n "$2" ]; then
root="$2"
else
root="$ROOTFS"
fi
if [ ! -f "$REPO/$1/KagamiBuild" ]; then
die 'Package does not exist'
fi
tsukuri em -c "$BUILD/target.config" -r "$root" -wNDSH $force $1
}
emerge_ht() {
local root
if [ -z "$1" ]; then
die 'Package was not specified'
fi
if [ -n "$2" ]; then
root="$2"
else
root="$ROOTFS"
fi
if [ ! -f "$REPO/$1/KagamiBuild" ]; then
die 'Package does not exist'
fi
pushd "$REPO/$1"
tsukuri bi -c "$BUILD/host.config" -w
popd
tsukuri em -c "$BUILD/target.config" -r "$root" -wNDSH $1
}
stamp() {
local target="$1"
if [ -z "$target" ]; then
return 1
fi
if [ ! -f "$BUILD/.${target}_stamp" ]; then
touch "$BUILD/.${target}_stamp"
fi
}
check_stamp() {
local target="$1"
if [ -z "$target" ]; then
return 1
fi
if [ -f "$BUILD/.${target}_stamp" ]; then
return 0
else
return 1
fi
}
get_desktop_packages() {
local desktop="$1"
local packages
if [ -z "$desktop" ]; then
return 1
fi
packages="linux-firmware"
case $desktop in
gnome|gnome-core|xfce|xfce-core|mate|mate-core|budgie) packages="$packages xorg-server xinit xf86-video-amdgpu xf86-video-ati xf86-video-nouveau xf86-video-fbdev xf86-video-vesa xf86-input-libinput" ;;
esac
case $desktop in
gnome) packages="$packages gnome" ;;
gnome-core) packages="$packages gnome-core" ;;
xfce) packages="$packages xfce lxdm network-manager-applet pipewire" ;;
xfce-core) packages="$packages xfce-core lxdm network-manager-applet pipewire" ;;
mate) packages="$packages mate lxdm network-manager-applet pipewire" ;;
mate-core) packages="$packages mate-core lxdm network-manager-applet pipewire" ;;
budgie) packages="$packages budgie lxdm" ;;
sway) packages="$packages sway networkmanager pipewire" ;;
weston) packages="weston networkmanager" ;;
*) die "You haven't specified desktop environment/windows manager or it's not supported" ;;
esac
case $desktop in
gnome|gnome-core|xfce|xfce-core|mate|mate-core|budgie) packages="$packages font-adobe-source-han-sans-jp-fonts font-adobe-source-han-sans-kr-fonts mozc ibus-hangul" ;;
esac
case $BARCH in
x86_64|i386|arm64|arm) packages="$packages firefox" ;;
esac
case $BARCH in
x86_64|i386) packages="$packages xf86-video-intel xf86-video-vmware grub" ;;
esac
echo "$packages"
}
parse_numbersign() {
# $1 - kagamibuild
# $2 - number sign variable
[ -z "$1" ] && exit 1
[ -z "$2" ] && exit 1
echo "$(grep -w "^# ${2}[[:blank:]]*:" "$1" | sed "s/^# ${2}[[:blank:]]*:[[:blank:]]*//" | tr ',' ' ')"
}
genrepo() {
set -x
unset name version release options backup source noextract depends topdir
local d i url
if [ ! -d "$1" ]; then
return 0
fi
export topdir="$1"
source $1/KagamiBuild
local summary="$(parse_numbersign $1/KagamiBuild "Description")"
local homepage="$(parse_numbersign $1/KagamiBuild "URL")"
local category="$(parse_numbersign $1/KagamiBuild "Section")"
local maintainer="$(parse_numbersign $1/KagamiBuild "Maintainer")"
maintainer="$(echo $maintainer | tr -d ',' | awk '{print $1}') <$(echo $maintainer | tr -d ',' | sed 's/^\w*\ *//' | sed 's/ at /@/' | sed 's/ dot /./')>"
for i in ${source[*]}; do
if echo $i | grep -q '::archive='; then
url="$(echo $i | sed -e 's/::archive=/ /g' | awk '{print $1}')"
else
url="$i"
fi
if [ -n "$d" ]; then
d="$d $url"
else
d="$url"
fi
done
echo -e '\t{' >> "$2"
echo -e '\t\t"name": "'${name}'",' >> "$2"
echo -e '\t\t"version": "'${version}'",' >> "$2"
echo -e '\t\t"summary": "'${summary}'",' >> "$2"
echo -e '\t\t"maintainer": "'${maintainer}'",' >> "$2"
echo -e '\t\t"download": "'${d}'",' >> "$2"
echo -e '\t\t"homepage": "'${homepage}'",' >> "$2"
echo -e '\t\t"category": "'${category}'"' >> "$2"
echo -e '\t},' >> "$2"
}