New build system

This commit is contained in:
Your Name 2023-12-19 16:13:27 +03:00
parent d4689a0b73
commit 4cf4468eb4
115 changed files with 214 additions and 154 deletions

View File

@ -1,11 +0,0 @@
CFLAGS?=-Wall -Wextra -pedantic -Ibuilder -Ilibmu -Os -s
CC?=cc
all:
$(CC) builder/builder.c $(CFLAGS) -obuild
./build
rm build
clean:
rm bin/*
rm build

View File

@ -1,4 +1,22 @@
#!/bin/sh
cc builder/builder.c -Wall -Wextra -pedantic -Ibuilder -Ilibmu -Os -s -obuild
./build
rm build
#!/bin/bash
PROJECT_DIR=$(pwd)
CFLAGS="-Wall -Wextra -I$PROJECT_DIR -I$PROJECT_DIR/libmu -lm"
projects="console-tools coreutils sysutils sysutils-linux findutils networking miscutils shell loginutils procps"
CC=cc
#Compile
for project in $projects; do
echo "Chdir" $project
for p in $project/*; do
echo " * Makeing" $p
for i in $p; do
cd $PROJECT_DIR/$i
echo " * Compile" $i
env CC=$CC CFLAGS="$CFLAGS" OUTPUT="-o $PROJECT_DIR"/bin/$(basename $i) ./build.sh
cd $PROJECT_DIR
done
echo
done
done

View File

@ -1,84 +0,0 @@
#include <stdio.h>
#include <errno.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include "make_path.h"
#include "config.h"
void remove_suffix(char *base, const char *suffix) {
char *ptr = base + strlen(base) - strlen(suffix);
if (!strcmp(ptr, suffix))
*ptr = '\0';
}
char *MakePath(const char *src, const char *output_dir) {
char *dup = strdup(src);
if (dup == NULL) {
fprintf(stderr, "builder: strdup failed\n");
exit(1);
}
remove_suffix(dup, ".c");
char *new_path = mu_make_path("builder", output_dir, dup);
if (new_path == NULL) {
free(dup);
exit(1);
}
free(dup);
return new_path;
}
void Compile(const char *src, const char *output_dir) {
char *path = MakePath(src, output_dir);
printf(CC_FMT, src, path);
pid_t pid;
if ((pid = fork()) == 0)
execlp(CC, CC, CFLAGS, src, "-o", path, NULL);
else if (pid == -1) {
fprintf(stderr, "builder: fork failed\n");
exit(1);
}
free(path);
int status = 0;
waitpid(pid, &status, 0);
if (status)
exit(status);
}
void ListAndCompile(const char *dir, const char *output_dir) {
if (chdir(dir) < 0) {
fprintf(stderr, "builder: %s: %s\n", dir, strerror(errno));
exit(1);
}
printf(CHDIR_FMT, dir);
DIR *dp = opendir(".");
struct dirent *ep;
while ((ep = readdir(dp)) != NULL) {
if (!strcmp(ep->d_name, ".") || !strcmp(ep->d_name, ".."))
continue;
Compile(ep->d_name, output_dir);
}
closedir(dp);
chdir("..");
}
int main(void) {
for (size_t i = 0; i < sizeof(objects) / sizeof(char *); i++)
ListAndCompile(objects[i], "../bin");
return 0;
}

View File

@ -1,24 +0,0 @@
#ifndef _CONFIG_H
#define _CONFIG_H
const char *objects[] = {
"console-tools",
"coreutils",
"networking",
"procps",
"findutils",
"sysutils",
"sysutils-linux",
"miscutils",
"shell"
};
#define CHDIR_FMT "Making \033[32m%s\033[0m\n"
#define CC_FMT "CC %10s -> %s\n"
/* Need by spark */
#define LDFLAGS "-lm"
#define CFLAGS "-Wall", "-Werror", "-Wextra", "-pedantic", "-flto", "-Os", "-s", "-I../libmu", "-I../", LDFLAGS
#define CC "cc"
#endif

2
console-tools/clear/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
console-tools/reset/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/basename/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/cat/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/chgrp/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

View File

@ -82,5 +82,3 @@ int main(int argc, char **argv) {
return ret;
}

2
coreutils/chmod/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/chown/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

View File

@ -90,7 +90,7 @@ int main(int argc, char **argv) {
break;
default:
printf("chown USER[:[GRP]] [file1 file2...]\n\t[-H If a command line argument is a symbolic link]\n\t[-R Recursive]\n\t[-f Silent]\n");
printf("chown USER[:[GRP]] [file1 file2...]\n\t[-H If a command line argument is a symbolic link]\n\t[-R Recursive] [-f Silent]\n");
return 0;
}
}

2
coreutils/chroot/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/cmp/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/cp/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/dirname/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/du/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/echo/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/env/build.sh vendored Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

View File

@ -28,6 +28,6 @@ int main(const int argc, char **argv, const char **envp) {
}
execvp(argv[i], argv + i);
fprintf(stderr, "env: %s\n", strerror(errno));
fprintf(stderr, "env: %s: %s\n", argv[i], strerror(errno));
return 1;
}

2
coreutils/false/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/head/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/id/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/ln/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/logname/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/ls/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/mkdir/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

View File

@ -1,21 +0,0 @@
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
int main(const int argc, const char **argv) {
if (argc == 1) {
printf("mkfifo: missing operand\n");
return 1;
}
for (int i = 1; i < argc; i++) {
if (mkfifo(argv[i], 0666)) {
fprintf(stderr, "mkfifo: %s %s\n", argv[i], strerror(errno));
return 1;
}
}
return 0;
}

2
coreutils/mkfifo/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

52
coreutils/mkfifo/mkfifo.c Normal file
View File

@ -0,0 +1,52 @@
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
long parse_long(const char *str) {
char *ptr = NULL;
long value = strtol(str, &ptr, 10);
if (*ptr) {
fprintf(stderr, "mkfifo: not a number: %s\n", str);
exit(1);
}
else if (value < 1) {
fprintf(stderr, "mknod: number is negative: %s\n", str);
exit(1);
}
return value;
}
int main(int argc, char **argv) {
mode_t mode = 0666;
int opt;
while ((opt = getopt(argc, argv, "m:")) != -1) {
switch (opt) {
case 'm':
mode = parse_long(optarg);
break;
default:
printf("mkfifo [file1 file2...]\n\t[-m Mode]\n");
return 0;
}
}
argv += optind;
argc -= optind;
for (int i = 0; i < argc; i++) {
if (mkfifo(argv[i], mode)) {
fprintf(stderr, "mkfifo: %s %s\n", argv[i], strerror(errno));
return 1;
}
}
return 0;
}

2
coreutils/mknod/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

View File

@ -10,7 +10,7 @@
#include <stdio.h>
#include "parse_mode.h"
long parse_int(const char *str) {
long parse_long(const char *str) {
char *ptr = NULL;
long value = strtol(str, &ptr, 10);
@ -53,7 +53,7 @@ int main(int argc, char **argv) {
dev_t dev = 0;
if (argc == 4)
dev = makedev(parse_int(argv[2]), parse_int(argv[3]));
dev = makedev(parse_long(argv[2]), parse_long(argv[3]));
if (!strncmp("b", argv[1], 1))
mode |= S_IFBLK;

2
coreutils/mktemp/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/mv/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/nice/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/nl/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/nohup/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/printenv/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/pwd/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/renice/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/rev/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/rm/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/shred/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/sleep/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/sync/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/tee/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/touch/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/true/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/tty/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/uname/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/wc/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/whoami/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
coreutils/yes/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
findutils/xargs/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

13
libmu/mount_opts.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef _MOUNT_OPTS_H
#define _MOUNT_OPTS_H
typedef struct {
char *title;
unsigned long opt
} MU_OPTS
MU_OPTS mu_mount_opts[] = {
{"ro", },
}
#endif

9
libmu/parse_mount.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef _PARSE_MOUNT_H
#define _PARSE_MOUNT_H
unsigned long mu_parse_opts(const char *str) {
(void)str;
return 0;
}
#endif

2
loginutils/nologin/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

2
miscutils/spark/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
echo ./*.c $CFLAGS $OUTPUT | xargs $CC

Some files were not shown because too many files have changed in this diff Show More