diff --git a/Makefile b/Makefile index cd82b75..915959b 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,8 @@ prefix = /usr/bin -YAIT_SRCS := $(wildcard yait/*.c) $(wildcard core/*.c) -YAIT_OBJS := $(patsubst yait/%.c,c-out/obj/%.o,$(YAIT_SRCS)) +YAIT_SRCS := $(wildcard src/*.c) -YAIT := c-out/bin/yait +YAIT := bin/yait -include config.mak @@ -16,14 +15,10 @@ else all: build $(YAIT) $(YAIT_DOC) build: - mkdir -p c-out/bin - mkdir -p c-out/obj + mkdir bin -c-out/obj/%.o: yait/%.c - $(CC) $(CFLAGS) -c $< -o $@ - -$(YAIT): $(YAIT_OBJS) $(EMBED_HEADER) - $(CC) $(CFLAGS) -DCOMMIT=$(shell git rev-list --count --all) $^ -o $@ +$(YAIT): $(YAIT_SRCS) + $(CC) $(CFLAGS) -Iinclude -DCOMMIT=$(shell git rev-list --count --all) $^ -o $@ endif @@ -36,11 +31,9 @@ uninstall: exit 1 clean: - rm -rf c-out - rm -f $(EMBED_HEADER) - rm -f $(EMBED_HEADERS) + $(RM) -rf bin dist-clean: clean - rm -f config.mak + $(RM) -f config.mak .PHONY: all clean dist-clean install uninstall build diff --git a/configure b/configure old mode 100644 new mode 100755 diff --git a/core/print.c b/core/print.c deleted file mode 100644 index 5d82b1b..0000000 --- a/core/print.c +++ /dev/null @@ -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. - * - */ - -#include "yait.h" -#include -#include - -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; -} diff --git a/core/util.c b/core/util.c deleted file mode 100644 index f6f7495..0000000 --- a/core/util.c +++ /dev/null @@ -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. - * - */ - -#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"); - } -} diff --git a/core/manifest.h b/include/yait.h similarity index 56% rename from core/manifest.h rename to include/yait.h index 9d10ea8..6fd671b 100644 --- a/core/manifest.h +++ b/include/yait.h @@ -1,36 +1,34 @@ /* Copyright (C) vx_clutch - * + * * This file is part of yait * * This project and file is licenced under the BSD-3-Clause licence. - * + * */ -#ifndef FORMAT_H -#define FORMAT_H +#ifndef YAIT_H +#define YAIT_H -#include #include -#include typedef enum { - BSD3, /* BSD 3-Clause Licence */ - GPLv3, /* GNU General Public Licence v3 */ - MIT, /* MIT Licence */ - UNLICENCE, /* Unlicence */ - LICENCE_HELP, /* Help case */ + BSD3, + GPLv3, + MIT, + UNLICENCE, + LICENCE_HELP, } licence_t; /* 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. */ typedef enum { - LIB_NONE = 0, /* No libraries selected */ - LIB_RAYLIB = 1 << 0, /* Raylib game library */ - LIB_NCURSES = 1 << 1, /* Windows API */ - LIB_CURL = 1 << 2, /* cURL library */ - LIB_COUNT_, /* Number of Libraries */ - LIB_HELP, /* Help case */ + LIB_NONE = 0, + LIB_RAYLIB = 1 << 0, + LIB_NCURSES = 1 << 1, + LIB_CURL = 1 << 2, + LIB_COUNT_, + LIB_HELP, } lib_flags_t; typedef struct { @@ -41,12 +39,11 @@ typedef struct { } flags_t; typedef struct { - licence_t licence; /* Licence type for the project */ - char *project; /* Project name */ - char *path; /* Path */ - char *name; /* Author/creator name ( if not provided infered on sanitize ) */ - lib_flags_t libraries; /* Selected libraries (bit field) */ - flags_t flag; /* Flags */ + licence_t licence; + char *project; + char *name; + lib_flags_t libraries; + flags_t flag; } manifest_t; #define DEFAULT_CLANG_FORMAT true @@ -71,8 +68,7 @@ typedef struct { return LIB_CURL; if (strcmp(src, "help")) return LIB_HELP; - fprintf(stderr, "could not find library %s", src); return LIB_COUNT_; /* bad case */ } -#endif +#endif // YAIT_H diff --git a/core/contents.h b/src/contents.h similarity index 100% rename from core/contents.h rename to src/contents.h diff --git a/core/create_project.c b/src/create_project.c similarity index 70% rename from core/create_project.c rename to src/create_project.c index 5478242..7b55c6f 100644 --- a/core/create_project.c +++ b/src/create_project.c @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -54,13 +53,19 @@ int program_exists(const char *prog) 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) m->project = DEFAULT_PROJECT_NAME; - if (!m->name) { - struct passwd *pw = getpwuid(getuid()); + if (!m->name) m->name = (pw && pw->pw_name) ? pw->pw_name : DEFAULT_USER_NAME; - } if (m->licence == UNLICENCE) m->licence = DEFAULT_LICENCE; @@ -74,10 +79,6 @@ int sanitize(manifest_t *m) if (!m->flag.GNU) m->flag.GNU = DEFAULT_GNU; - if (strcmp(".", m->project) == 0) { - - } - return 0; } @@ -263,96 +264,77 @@ int create_project(manifest_t manifest) sanitize(&manifest); - if (strcmp(manifest.path, ".") != 0) { - 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; - } + // TODO(vx-clutch): take dir. - status = chdir(manifest.path); - if (status != 0) { - fprintf(stderr, - "create_project: failed to enter directory '%s': %s\n", - manifest.path, strerror(errno)); - return errno; - } - } else { - manifest.path = ""; + // status = create_makefile(manifest); + // 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 *cwd = getcwd(NULL, 0); + if (!cwd) { + printfn("could not get current working directory"); + return 1; } - - status = create_makefile(manifest); - 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); + fprintf(stderr, "Created %s at\n %s\n", manifest.project, cwd); + free(cwd); return 0; } diff --git a/core/file.c b/src/file.c similarity index 100% rename from core/file.c rename to src/file.c diff --git a/yait/main.c b/src/main.c similarity index 92% rename from yait/main.c rename to src/main.c index 1c13841..4e37417 100644 --- a/yait/main.c +++ b/src/main.c @@ -148,16 +148,9 @@ int main(int argc, char **argv) manifest_t manifest = { 0 }; status = parse_standard_options(usage, argc, argv); - if (status != 0 && status != HELP_REQUESTED) { - fprintf(stderr, "error: %s\n", strerror(status)); - return EXIT_FAILURE; - } - - status = program_exists("git"); - if (status != 0) { - fprintf(stderr, "git binary not present\n"); - return EXIT_FAILURE; - } + if (status != 0 && status != HELP_REQUESTED) + return fprintf(stderr, "error: %s\n", strerror(status)), + EXIT_FAILURE; 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); return status == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/core/standard.c b/src/standard.c similarity index 100% rename from core/standard.c rename to src/standard.c diff --git a/core/yait.h b/src/yait.h similarity index 100% rename from core/yait.h rename to src/yait.h diff --git a/tools/Cleanup b/tools/Cleanup deleted file mode 100644 index 9008928..0000000 --- a/tools/Cleanup +++ /dev/null @@ -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 diff --git a/tools/check_header b/tools/check_header deleted file mode 100644 index a0cc5d2..0000000 --- a/tools/check_header +++ /dev/null @@ -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 diff --git a/tools/format b/tools/format old mode 100644 new mode 100755