micro-utils/build-box.sh
2024-07-10 16:59:36 +03:00

51 lines
953 B
Bash
Executable File

#!/bin/sh
CFLAGS="-s -Os -Wextra -Wall -pedantic"
CC="cc"
chmod +x ./libmu/build-libmu.sh
./libmu/build-libmu.sh
cat > mutils.c << EOF
#include <stdio.h>
#include <string.h>
$(for i in $(ls src); do
f=$(basename $i .c)
echo "int "$f"_main(int argc, char **argv);"
done)
struct cmd {
int (*func)(int argc, char **argv);
const char *str;
} cmds[] = {
$(for i in $(ls src); do
f=$(basename $i .c)
#EDIT SOURCES
cat src/$i | sed "s/main(/"$f"_main(/g" > bin/$i
#MAKE STRUCTURE
echo -e "\t{"$f"_main, \"$f\"},"
done)
};
int main(int argc, char **argv) {
if (argc > 1) {
argc--;
argv++;
for (size_t i = 0; i < sizeof(cmds) / sizeof(struct cmd); i++)
if (!strcmp(argv[0], cmds[i].str))
return cmds[i].func(argc, argv);
}
for (size_t i = 0; i < sizeof(cmds) / sizeof(struct cmd); i++)
printf("%s ", cmds[i].str);
putchar('\n');
return 0;
}
EOF
echo $CFLAGS | xargs $CC -Iconfigs -Ilibmu bin/*.c obj/*.o mutils.c -omutils