This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·191 lines (164 loc) · 5.95 KB
/
configure
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
#!/usr/bin/env sh
set -e
usage() {
{
echo "[ENV]=[VAL] $0 [FLAGS...]"
echo ' --help Print help/usage'
echo ' --use-clang Use clang instead of default ($CC or cc) compiler'
echo ' --use-gcc Use gcc instead of default ($CC or cc) compiler'
echo ' --use-harden Harden the binary'
echo ' --use-strip Strip the generated binary'
echo ' --use-pedantic Enable -Wpedantic -pedantic flags'
echo ' --use-warnings Enable -Wall and -Wextra'
echo ' --use-werror Enable -Werror'
echo ' --use-lto Enable LTO'
echo ' --use-config Install configuration to /usr/share/yafetch/init.lua or $CONF'
echo ' --use-extreme-strip Configure strip flags to be extreme'
echo ' --use-install Enable the `install` and `uninstall` makefile entries'
echo ' --use-optimise Add optimisation flags'
echo ' --use-debug Add debug symbols and generally optimise for debugging'
echo ' --use-prog-debug Enable binary-level debug logging'
echo ' --use-march Enable -march=native'
echo ''
echo ' $LUAPC Lualib pkg-config name'
} >&2
}
die() {
echo "$@" 1>&2
exit 1
}
check_cmd() {
echo "Checking for $1..."
command -v "$1" >/dev/null || die "$1 was not found"
}
check_pkg() {
echo "Checking for $1.pc..."
pkg-config --cflags "$1" >/dev/null || die "$1.pc was not found"
}
main() {
if [ ! "$1" ]; then
usage
exit 1
fi
LUAPC="${LUAPC:-lua5.4}"
check_cmd 'make'
check_cmd 'pkg-config'
check_pkg "$LUAPC"
project='yafetch'
compiler='$(CC)'
cflags='-std=c99 -D_POSIX_C_SOURCE=200112L -D_ISOC99_SOURCE'
ldflags=''
stripflags=''
strip_enable=0
config_enable=0
install_enable=0
for arg in "$@"; do
case "$arg" in
--help)
usage
exit
;;
--use-clang)
check_cmd 'clang'
compiler='clang'
;;
--use-gcc)
check_cmd 'gcc'
compiler='gcc'
;;
--use-harden)
cflags="$cflags -g -fstack-protector-strong -fstack-protector -fPIE -pie -D_FORTIFY_SOURCE=2 -O2 -Wno-unused-result -Wno-unused-command-line-argument"
ldflags="$ldflags -Wl,-z,relro,-z,now"
;;
--use-strip)
strip_enable=1
;;
--use-pedantic)
cflags="$cflags -Wpedantic -pedantic"
;;
--use-warnings)
cflags="$cflags -Wall -Wextra -Wformat -Wformat-security"
;;
--use-werror)
cflags="$cflags -Werror"
;;
--use-lto)
cflags="$cflags -flto"
ldflags="$ldflags -flto"
;;
--use-config)
config_enable=1
;;
--use-extreme-strip)
stripflags='--strip-all -N __gentoo_check_ldflags__ -R .comment -R .GCC.command.line --remove-section=.eh_frame --remove-section=.eh_frame_hdr --remove-section=.gnu.hash --remove-section=.eh_frame_hdr --remove-section=.eh_frame_ptr --remove-section=.note.gnu.gold-version --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag --remove-section=.note --remove-section=.gnu.version --remove-section=.comment --strip-debug --strip-unneeded'
;;
--use-install)
install_enable=1
;;
--use-optimise)
cflags="$cflags -O2 -ffast-math"
ldflags="$ldflags -O2"
;;
--use-debug)
cflags="$cflags -g -g3 -O0 -fno-eliminate-unused-debug-types"
;;
--use-prog-debug)
cflags="$cflags -DDEBUG"
;;
--use-march)
cflags="$cflags -march=native"
;;
*)
die "Flag $arg not found"
;;
esac
done
echo 'Configuring lua...'
cflags="$cflags $(pkg-config --cflags "${LUAPC}" || die 'pkg-config cflags failed for lua5.4')"
ldflags="$ldflags $(pkg-config --libs "${LUAPC}" || die 'pkg-config ldflags failed for lua5.4')"
after=''
all='all after clean'
{
echo 'OBJECTS := src/script.o src/func.o src/main.o'
echo "CFLAGS := \$(CFLAGS) $cflags"
echo "LDFLAGS := \$(LDFLAGS) $ldflags"
echo "CC := $compiler"
echo 'all: $(OBJECTS)'
printf "\t%s\n" "\$(CC) \$(CFLAGS) \$^ \$(LDFLAGS) -o $project"
printf "\t%s\n" "make after"
echo 'clean:'
printf "\t%s\n" "rm -f $project \$(OBJECTS)"
if [ "$config_enable" = 1 ]; then
echo 'CONF ?= /usr/share/yafetch'
echo 'y_config:'
printf "\t%s\n" 'rm -rf $(DESTDIR)$(CONF)/init.lua'
printf "\t%s\n" 'mkdir -p $(DESTDIR)$(CONF)'
printf "\t%s\n" 'install -Dm644 init.lua $(DESTDIR)$(CONF)'
all="$all y_config"
fi
if [ "$strip_enable" = 1 ]; then
echo "STRIPFLAGS := \$(STRIPFLAGS) $stripflags"
echo 'y_strip:'
printf "\t%s\n" "strip $project \$(STRIPFLAGS) -o $project"
after="$after y_strip"
fi
if [ "$install_enable" = 1 ]; then
echo 'PREFIX ?= /usr/local'
echo 'BINDIR ?= $(PREFIX)/bin'
echo "install: $project"
printf "\t%s\n" 'mkdir -p $(DESTDIR)$(BINDIR)'
printf "\t%s\n" 'install -Dm755 yafetch $(DESTDIR)$(BINDIR)'
echo 'uninstall:'
printf "\t%s\n" 'rm -i $(DESTDIR)$(BINDIR)/yafetch'
all="$all install uninstall"
fi
echo 'after:'
if [ "$after" ]; then
printf "\t%s\n" "make $after -j$(nproc --all)"
else
printf "\t%s\n" "-@echo 'No after-compile phase'"
fi
echo ".PHONY: $all $after"
} >Makefile
}
main "$@"