-
Notifications
You must be signed in to change notification settings - Fork 0
/
do_gcc.sh
executable file
·65 lines (47 loc) · 1.26 KB
/
do_gcc.sh
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
#!/bin/bash
set -euvfx
root=gcc_build
rm -rf $root
cp -r src $root
cd $root
[ -d gcm.cache ] && echo "BAD: gcm.cache exists" && exit 1
[ -f mapper.txt ] && echo "BAD: mapper.txt exists" && exit 1
[ -f main ] && echo "BAD: main exists" && exit 1
# Path to the mapper file
mapper=$(readlink -f mapper.txt)
# What's our compiler + flags?
cc="g++-11"
error_flags="-Wall -Wextra -Wpedantic -Werror"
mod_flags="-fmodules-ts -fmodule-mapper=$mapper"
cflags="$error_flags $mod_flags -std=c++20"
# Generate modules for our system headers
rm -rf sys_inc
mkdir sys_inc
cd sys_inc
for i in cstdint iostream; do
echo "/usr/include/c++/11/$i $(readlink -f $i.gcm)" >> ../mapper.txt
$cc $cflags -c -x c++-system-header $i
done
cd ..
# Generate our 'moo' module
cd mod_moo
module=moo
unit=mod_$module
echo "$module $(readlink -f $module.so.gcm)" >> ../mapper.txt
$cc $cflags -c $unit.cpp -o $unit.o
cd ..
# Generate our 'quack' module
cd mod_quack
module=quack
unit=mod_$module
echo "$module $(readlink -f $module.so.gcm)" >> ../mapper.txt
$cc $cflags -c $unit.cpp -o $unit.o
cd ..
# Compile main
$cc $cflags -c main.cpp -o main.o
# Link everything together
$cc $cflags mod_moo/mod_moo.o mod_quack/mod_quack.o main.o -o main
# Run our binary
echo "Running main ..."
./main
# EOF