sfeed-box experiment, improvements - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit e5f51a04b7c616d81365c9daae1e31f999563d48
(DIR) parent a02ec4a24496c475c639b439771f603ad83976d7
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Wed, 19 Apr 2023 00:05:30 +0200
sfeed-box experiment, improvements
- add more aggressive optimization flags for size.
- use the same proper declaration for main(). (int, char **) or void.
- allow to run each step separately.
- code-cleanup
Diffstat:
M sfeed/sfeed-box.sh | 39 +++++++++++++++++++++----------
1 file changed, 27 insertions(+), 12 deletions(-)
---
(DIR) diff --git a/sfeed/sfeed-box.sh b/sfeed/sfeed-box.sh
@@ -8,9 +8,11 @@ if ! test -f sfeed.c; then
fi
CC="cc"
-CFLAGS="-Os" # optimize for size
+CFLAGS="-Os -flto -Wall" # optimize for size
+#CFLAGS="-Os" # optimize for size
CPPFLAGS="-D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -DSFEED_MINICURSES"
-LDFLAGS="-s" # strip
+LDFLAGS="-s -flto -Wl,--gc-sections" # strip
+#LDFLAGS="-s" # strip
# uncomment for static-linked.
#STATIC="-static"
@@ -23,7 +25,7 @@ box="build/sfeed-box.c"
compatsrc="strlcpy.c strlcat.c"
compatobj="strlcat.o strlcpy.o"
-dobuild() {
+do_build() {
rm -rf build
mkdir -p build
cp -fR $hdr $compatsrc $lib build/
@@ -37,7 +39,9 @@ cat <<! > "$box"
for f in $src; do
n="${f%.c}"
sed "s/^main(/$(echo "$n" | sed s/-/_/g)_&/" < $f > "build/$f"
- echo "int $(echo $n | sed 's/-/_/g')_main(int, char **);" >> "$box"
+
+ decl=$(sed -nE 's@^(main\(.*\))$@\1@p' < $f)
+ echo "int ${n}_${decl};" >> "$box"
done
# real main, compare argv[0] to program name.
@@ -45,12 +49,19 @@ cat <<! > "$box"
for f in $src; do
n="${f%.c}"
[ "$n" = "sfeed" ] && continue
- echo "else if(!strcmp(s, \"$n\")) return $(echo "$n" | sed s/-/_/g)_main(argc, argv);" >> "$box"
+
+ decl=$(sed -nE 's@^(main\(int.*\))$@\1@p' < $f)
+ if [ "$decl" != "" ]; then
+ decl="main(argc, argv);"
+ else
+ decl="main();"
+ fi
+ echo "else if(!strcmp(s, \"$n\")) return $(echo "$n" | sed s/-/_/g)_${decl}" >> "$box"
done
echo 'return sfeed_main(argc, argv); }' >> "$box"
}
-docompile() {
+do_compile() {
cd build/
$CC $STATIC $CFLAGS $CPPFLAGS -c *.c
$CC $STATIC $CFLAGS $LDFLAGS -o \
@@ -60,7 +71,7 @@ docompile() {
cd ../
}
-doinstall() {
+do_install() {
rm -rf install
mkdir -p install
cd install
@@ -78,12 +89,16 @@ doinstall() {
cp -f $scripts install/
}
-dolist() {
+do_list() {
ls -l install/
size install/sfeed
}
-dobuild
-docompile
-doinstall
-dolist
+if [ "$1" != "" ]; then
+ "do_$1"
+else
+ do_build
+ do_compile
+ do_install
+ do_list
+fi