This commit is contained in:
2025-08-17 21:37:58 -04:00
parent a386594b1f
commit f92a896ca2
14 changed files with 109 additions and 254 deletions

View File

@@ -1,9 +1,8 @@
prefix = /usr/bin prefix = /usr/bin
YAIT_SRCS := $(wildcard yait/*.c) $(wildcard core/*.c) YAIT_SRCS := $(wildcard src/*.c)
YAIT_OBJS := $(patsubst yait/%.c,c-out/obj/%.o,$(YAIT_SRCS))
YAIT := c-out/bin/yait YAIT := bin/yait
-include config.mak -include config.mak
@@ -16,14 +15,10 @@ else
all: build $(YAIT) $(YAIT_DOC) all: build $(YAIT) $(YAIT_DOC)
build: build:
mkdir -p c-out/bin mkdir bin
mkdir -p c-out/obj
c-out/obj/%.o: yait/%.c $(YAIT): $(YAIT_SRCS)
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -Iinclude -DCOMMIT=$(shell git rev-list --count --all) $^ -o $@
$(YAIT): $(YAIT_OBJS) $(EMBED_HEADER)
$(CC) $(CFLAGS) -DCOMMIT=$(shell git rev-list --count --all) $^ -o $@
endif endif
@@ -36,11 +31,9 @@ uninstall:
exit 1 exit 1
clean: clean:
rm -rf c-out $(RM) -rf bin
rm -f $(EMBED_HEADER)
rm -f $(EMBED_HEADERS)
dist-clean: clean dist-clean: clean
rm -f config.mak $(RM) -f config.mak
.PHONY: all clean dist-clean install uninstall build .PHONY: all clean dist-clean install uninstall build

0
configure vendored Normal file → Executable file
View File

View File

@@ -1,23 +0,0 @@
/* Copyright (C) vx_clutch
*
* This file is part of yait
*
* This project and file is licenced under the BSD-3-Clause licence.
* <https://opensource.org/license/bsd-3-clause>
*/
#include "yait.h"
#include <stdarg.h>
#include <stdio.h>
int printfn(char *format, ...)
{
int len;
va_list args;
va_start(args, format);
fprintf(stderr, "yait: ");
len = vfprintf(stderr, format, args);
fprintf(stderr, "\n"); /* Use stderr consistently */
va_end(args);
return len;
}

View File

@@ -1,19 +0,0 @@
/* Copyright (C) vx_clutch
*
* This file is part of yait
*
* This project and file is licenced under the BSD-3-Clause licence.
* <https://opensource.org/licence/bsd-3-clause>
*/
#include "yait.h"
void emit_progress(const char *action, int count)
{
if (count > 0) {
fprintf(stderr, "%s %d", strcat("\r", action), count);
fflush(stderr);
} else {
fprintf(stderr, ", done\n");
}
}

View File

@@ -1,36 +1,34 @@
/* Copyright (C) vx_clutch /* Copyright (C) vx_clutch
* *
* This file is part of yait * This file is part of yait
* *
* This project and file is licenced under the BSD-3-Clause licence. * This project and file is licenced under the BSD-3-Clause licence.
* <https://opensource.org/licence/bsd-3-clause> * <https://opensource.org/license/bsd-3-clause>
*/ */
#ifndef FORMAT_H #ifndef YAIT_H
#define FORMAT_H #define YAIT_H
#include <stdbool.h>
#include <string.h> #include <string.h>
#include <stdio.h>
typedef enum { typedef enum {
BSD3, /* BSD 3-Clause Licence */ BSD3,
GPLv3, /* GNU General Public Licence v3 */ GPLv3,
MIT, /* MIT Licence */ MIT,
UNLICENCE, /* Unlicence */ UNLICENCE,
LICENCE_HELP, /* Help case */ LICENCE_HELP,
} licence_t; } licence_t;
/* A bit field is used so that we can accomplish two things. (a) store lots of /* A bit field is used so that we can accomplish two things. (a) store lots of
libraries without taxing memory; and (b) a dynamic array is not neccescary. libraries without taxing memory; and (b) a dynamic array is not neccescary.
*/ */
typedef enum { typedef enum {
LIB_NONE = 0, /* No libraries selected */ LIB_NONE = 0,
LIB_RAYLIB = 1 << 0, /* Raylib game library */ LIB_RAYLIB = 1 << 0,
LIB_NCURSES = 1 << 1, /* Windows API */ LIB_NCURSES = 1 << 1,
LIB_CURL = 1 << 2, /* cURL library */ LIB_CURL = 1 << 2,
LIB_COUNT_, /* Number of Libraries */ LIB_COUNT_,
LIB_HELP, /* Help case */ LIB_HELP,
} lib_flags_t; } lib_flags_t;
typedef struct { typedef struct {
@@ -41,12 +39,11 @@ typedef struct {
} flags_t; } flags_t;
typedef struct { typedef struct {
licence_t licence; /* Licence type for the project */ licence_t licence;
char *project; /* Project name */ char *project;
char *path; /* Path */ char *name;
char *name; /* Author/creator name ( if not provided infered on sanitize ) */ lib_flags_t libraries;
lib_flags_t libraries; /* Selected libraries (bit field) */ flags_t flag;
flags_t flag; /* Flags */
} manifest_t; } manifest_t;
#define DEFAULT_CLANG_FORMAT true #define DEFAULT_CLANG_FORMAT true
@@ -71,8 +68,7 @@ typedef struct {
return LIB_CURL; return LIB_CURL;
if (strcmp(src, "help")) if (strcmp(src, "help"))
return LIB_HELP; return LIB_HELP;
fprintf(stderr, "could not find library %s", src);
return LIB_COUNT_; /* bad case */ return LIB_COUNT_; /* bad case */
} }
#endif #endif // YAIT_H

View File

@@ -8,7 +8,6 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
@@ -54,13 +53,19 @@ int program_exists(const char *prog)
int sanitize(manifest_t *m) int sanitize(manifest_t *m)
{ {
int status;
struct passwd *pw = getpwuid(getuid());
status = program_exists("git");
if (status != 0)
return fprintf(stderr, "git binary not present\n"),
EXIT_FAILURE;
if (!m->project) if (!m->project)
m->project = DEFAULT_PROJECT_NAME; m->project = DEFAULT_PROJECT_NAME;
if (!m->name) { if (!m->name)
struct passwd *pw = getpwuid(getuid());
m->name = (pw && pw->pw_name) ? pw->pw_name : DEFAULT_USER_NAME; m->name = (pw && pw->pw_name) ? pw->pw_name : DEFAULT_USER_NAME;
}
if (m->licence == UNLICENCE) if (m->licence == UNLICENCE)
m->licence = DEFAULT_LICENCE; m->licence = DEFAULT_LICENCE;
@@ -74,10 +79,6 @@ int sanitize(manifest_t *m)
if (!m->flag.GNU) if (!m->flag.GNU)
m->flag.GNU = DEFAULT_GNU; m->flag.GNU = DEFAULT_GNU;
if (strcmp(".", m->project) == 0) {
}
return 0; return 0;
} }
@@ -263,96 +264,77 @@ int create_project(manifest_t manifest)
sanitize(&manifest); sanitize(&manifest);
if (strcmp(manifest.path, ".") != 0) { // TODO(vx-clutch): take dir.
status = mkdir(manifest.path, 0755);
if (status != 0 && errno != EEXIST) {
fprintf(stderr,
"create_project: failed to create directory '%s': %s\n",
manifest.path, strerror(errno));
return errno;
}
status = chdir(manifest.path); // status = create_makefile(manifest);
if (status != 0) { // if (status != 0) {
fprintf(stderr, // fprintf(stderr,
"create_project: failed to enter directory '%s': %s\n", // "create_project: failed to create Makefile: %s\n",
manifest.path, strerror(errno)); // strerror(status));
return errno; // return status;
} // }
} else { //
manifest.path = ""; // status = create_configure(manifest);
// if (status != 0) {
// fprintf(stderr,
// "create_project: failed to create configure: %s\n",
// strerror(status));
// return status;
// }
//
// status = maybe_create_clang_format(manifest);
// if (status != 0) {
// fprintf(stderr,
// "create_project: warning: clang-format setup failed: %s\n",
// strerror(status));
// }
//
// char *licence_line = malloc(1024);
// if (!licence_line) {
// fputs("create_project: failed to allocate memory for licence line\n",
// stderr);
// return ENOMEM;
// }
//
// status = create_licence(manifest, &licence_line);
// if (status != 0) {
// fprintf(stderr,
// "create_project: failed to create licence: %s\n",
// strerror(status));
// free(licence_line);
// return status;
// }
//
// status = generate_source_code(manifest, licence_line);
// if (status != 0) {
// fprintf(stderr,
// "create_project: failed to generate source code: %s\n",
// strerror(status));
// free(licence_line);
// return status;
// }
//
// free(licence_line);
//
// status = create_libraries(manifest);
// if (status != 0) {
// printfn("failed to get libraries: %s", strerror(status));
// return status;
// }
//
// status = setup_git(manifest);
// if (status != 0) {
// printfn("warning: git initialization failed: %s",
// strerror(status));
// }
char *cwd = getcwd(NULL, 0);
if (!cwd) {
printfn("could not get current working directory");
return 1;
} }
fprintf(stderr, "Created %s at\n %s\n", manifest.project, cwd);
status = create_makefile(manifest); free(cwd);
if (status != 0) {
fprintf(stderr,
"create_project: failed to create Makefile: %s\n",
strerror(status));
return status;
}
status = create_configure(manifest);
if (status != 0) {
fprintf(stderr,
"create_project: failed to create configure: %s\n",
strerror(status));
return status;
}
status = maybe_create_clang_format(manifest);
if (status != 0) {
fprintf(stderr,
"create_project: warning: clang-format setup failed: %s\n",
strerror(status));
}
char *licence_line = malloc(1024);
if (!licence_line) {
fputs("create_project: failed to allocate memory for licence line\n",
stderr);
return ENOMEM;
}
status = create_licence(manifest, &licence_line);
if (status != 0) {
fprintf(stderr,
"create_project: failed to create licence: %s\n",
strerror(status));
free(licence_line);
return status;
}
status = generate_source_code(manifest, licence_line);
if (status != 0) {
fprintf(stderr,
"create_project: failed to generate source code: %s\n",
strerror(status));
free(licence_line);
return status;
}
free(licence_line);
status = create_libraries(manifest);
if (status != 0) {
printfn("failed to get libraries: %s", strerror(status));
return status;
}
status = setup_git(manifest);
if (status != 0) {
printfn("warning: git initialization failed: %s",
strerror(status));
}
char *resolved = realpath(manifest.path, NULL);
if (!resolved) {
fprintf(stderr, "Failed to get realpath for '%s': %s\n",
manifest.path, strerror(errno));
return 2;
}
fprintf(stderr, "Created %s at\n %s\n", manifest.project, resolved);
free(resolved);
return 0; return 0;
} }

View File

@@ -148,16 +148,9 @@ int main(int argc, char **argv)
manifest_t manifest = { 0 }; manifest_t manifest = { 0 };
status = parse_standard_options(usage, argc, argv); status = parse_standard_options(usage, argc, argv);
if (status != 0 && status != HELP_REQUESTED) { if (status != 0 && status != HELP_REQUESTED)
fprintf(stderr, "error: %s\n", strerror(status)); return fprintf(stderr, "error: %s\n", strerror(status)),
return EXIT_FAILURE; EXIT_FAILURE;
}
status = program_exists("git");
if (status != 0) {
fprintf(stderr, "git binary not present\n");
return EXIT_FAILURE;
}
parse_arguments(&manifest, argc, argv); parse_arguments(&manifest, argc, argv);
@@ -169,9 +162,6 @@ int main(int argc, char **argv)
} }
} }
manifest.path = manifest.project;
// TODO(vx-clutch): get name from path.
status = create_project(manifest); status = create_project(manifest);
return status == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return status == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }

View File

@@ -1,20 +0,0 @@
#!/bin/env bash
# Usage: ./Cleanup [FILE]...
make dist-clean
process_file() {
clang-format -i "$1"
tools/check_header_footer "$1"
}
if [[ $# -gt 0 ]]; then
for file in "$@"; do
process_file "$file"
done
else
for file in $(find yait core -type f \( -name "*.c" -o -name "*.h" \)); do
process_file "$file"
done
fi

View File

@@ -1,44 +0,0 @@
#!/bin/env bash
# Usage: ./check_header
if pwd | grep -q tools; then
cd ..
fi
files=$(find yait \( -name '*.c' -o -name '*.h' \))
files+=" "
files+=$(find core \( -name '*.c' -o -name '*.h' \))
files+=" $(find . -maxdepth 1 -type f)"
ignore="README COPYING .clang-format config.mak"
if [ -z "$files" ]; then
echo "No files found"
exit 0
fi
missing=""
for file in $files; do
if echo "$ignore" | grep -qw "$(basename "$file")"; then
continue
fi
echo -ne "$file... "
if grep -q "Copyright (C)" "$file"; then
echo -e "\033[1;32mOK\033[0m"
else
echo -e "\033[0;31mFAIL\033[0m"
missing+="$file "
fi
done
if [ "$missing" = "" ]; then
echo -e "\033[1;32mAll checks pass.\033[0m"
else
echo -e "\033[0;31mThe follwing files are missing copyright information.\033[0m"
fi
for file in $missing; do
echo " - $file"
done

0
tools/format Normal file → Executable file
View File