micro-utils/scripts/build-box.sh

45 lines
856 B
Bash
Raw Normal View History

2024-07-09 19:33:45 +00:00
#!/bin/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[] = {
2024-07-13 11:43:49 +00:00
$(for i in $(ls src); do
f=$(basename $i .c)
2024-07-09 19:33:45 +00:00
2024-07-13 11:43:49 +00:00
#EDIT SOURCES
cat src/$i | sed "s/main(/"$f"_main(/g" > bin/$i
2024-07-09 19:33:45 +00:00
2024-07-13 11:43:49 +00:00
#FILL STRUCTURE
echo -e "\t{"$f"_main, \"$f\"},"
done)
2024-07-09 19:33:45 +00:00
};
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
2024-07-13 11:43:49 +00:00
echo $CFLAGS | xargs $CC -Iconfigs -Ilibmu mutils.c obj/*.o bin/*.c -o mutils