New build system
This commit is contained in:
parent
d4689a0b73
commit
4cf4468eb4
11
Makefile
11
Makefile
|
@ -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
|
|
26
build.sh
26
build.sh
|
@ -1,4 +1,22 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
cc builder/builder.c -Wall -Wextra -pedantic -Ibuilder -Ilibmu -Os -s -obuild
|
PROJECT_DIR=$(pwd)
|
||||||
./build
|
CFLAGS="-Wall -Wextra -I$PROJECT_DIR -I$PROJECT_DIR/libmu -lm"
|
||||||
rm build
|
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
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -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
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -82,5 +82,3 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -90,7 +90,7 @@ int main(int argc, char **argv) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -28,6 +28,6 @@ int main(const int argc, char **argv, const char **envp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
execvp(argv[i], argv + i);
|
execvp(argv[i], argv + i);
|
||||||
fprintf(stderr, "env: %s\n", strerror(errno));
|
fprintf(stderr, "env: %s: %s\n", argv[i], strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -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;
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -10,7 +10,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "parse_mode.h"
|
#include "parse_mode.h"
|
||||||
|
|
||||||
long parse_int(const char *str) {
|
long parse_long(const char *str) {
|
||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
long value = strtol(str, &ptr, 10);
|
long value = strtol(str, &ptr, 10);
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
dev_t dev = 0;
|
dev_t dev = 0;
|
||||||
if (argc == 4)
|
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))
|
if (!strncmp("b", argv[1], 1))
|
||||||
mode |= S_IFBLK;
|
mode |= S_IFBLK;
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,2 @@
|
||||||
|
#!/bin/sh
|
||||||
|
echo ./*.c $CFLAGS $OUTPUT | xargs $CC
|
|
@ -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
Loading…
Reference in New Issue