diff --git a/Project/Makefile b/Project/Makefile new file mode 100644 index 0000000..4cb793a --- /dev/null +++ b/Project/Makefile @@ -0,0 +1,44 @@ +prefix = /usr/bin + +PROJECT_SRCS := $(shell find . -name 'PROJECT/*.c') +PROJECT_OBJS := $(patsubst ./%.c,c-out/obj/%.o,$(PROJECT_SRCS)) + +PROJECT := c-out/bin/PROJECT + +-include config.mak + +ifeq ($(wildcard config.mak),) +all: + @echo "File config.mak not found, run configure" + @exit 1 +else + +all: build $(Project) + +build: + mkdir -p c-out/bin + mkdir -p c-out/obj + +c-out/obj/%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +$(PROJECT): $(PROJECT_OBJS) + $(CC) $(CFLAGS) -DCOMMIT=$(shell git rev-list --count --all 2>/dev/null || echo 0) $^ -o $@ + +endif + +install: + @echo "NOT IMPL" + exit 1 + +uninstall: + @echo "NOT IMPL" + exit 1 + +clean: + rm -rf c-out + +dist-clean: clean + rm -f config.mak + +.PHONY: all clean dist-clean install uninstall diff --git a/Project/configure b/Project/configure new file mode 100644 index 0000000..e69de29 diff --git a/c-out/bin/yait b/c-out/bin/yait new file mode 100755 index 0000000..683d089 Binary files /dev/null and b/c-out/bin/yait differ diff --git a/c-out/obj/main.o b/c-out/obj/main.o new file mode 100644 index 0000000..f2abc25 Binary files /dev/null and b/c-out/obj/main.o differ diff --git a/config.mak b/config.mak new file mode 100644 index 0000000..fcef174 --- /dev/null +++ b/config.mak @@ -0,0 +1,4 @@ +PREFIX=/usr/bin/ +CFLAGS=-Wall -Wextra -ggdb +LDFLAGS= +CC=clang diff --git a/sample_project/Makefile b/sample_project/Makefile new file mode 100644 index 0000000..f7bb34d --- /dev/null +++ b/sample_project/Makefile @@ -0,0 +1,44 @@ +prefix = /usr/bin + +SAMPLE_PROJECT_SRCS := $(shell find . -name 'SAMPLE_PROJECT/*.c') +SAMPLE_PROJECT_OBJS := $(patsubst ./%.c,c-out/obj/%.o,$(SAMPLE_PROJECT_SRCS)) + +SAMPLE_PROJECT := c-out/bin/SAMPLE_PROJECT + +-include config.mak + +ifeq ($(wildcard config.mak),) +all: + @echo "File config.mak not found, run configure" + @exit 1 +else + +all: build $(sample_project) + +build: + mkdir -p c-out/bin + mkdir -p c-out/obj + +c-out/obj/%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +$(SAMPLE_PROJECT): $(SAMPLE_PROJECT_OBJS) + $(CC) $(CFLAGS) -DCOMMIT=$(shell git rev-list --count --all 2>/dev/null || echo 0) $^ -o $@ + +endif + +install: + @echo "NOT IMPL" + exit 1 + +uninstall: + @echo "NOT IMPL" + exit 1 + +clean: + rm -rf c-out + +dist-clean: clean + rm -f config.mak + +.PHONY: all clean dist-clean install uninstall diff --git a/sample_project/configure b/sample_project/configure new file mode 100644 index 0000000..e69de29 diff --git a/yait/contents.h b/yait/contents.h index d5ed0ab..32dd8a7 100644 --- a/yait/contents.h +++ b/yait/contents.h @@ -177,7 +177,7 @@ char *config_h_template = line () line ("/* Program information */") line ("#define PROGRAM \"%s\"") - line ("#define LICENSE_line \"%s\"") + line ("#define LICENSE_LINE \"%s\"") line ("#define AUTHORS \"%s\"") line ("#define VERSION \"pre-alpha\"") line ("#define YEAR 2025") diff --git a/yait/main.c b/yait/main.c index 56f0bad..a692fee 100644 --- a/yait/main.c +++ b/yait/main.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "../config.h" @@ -329,31 +330,39 @@ static int create_configure(manifest_t manifest) return status; } -static int generate_source_code(manifest_t manifest) +static int generate_source_code(manifest_t manifest, char *licence_line) { - int status; + int status, year; + + time_t t = time(NULL); + struct tm tm = *localtime(&t); + year = tm.tm_year + 1900; + + // XXX(vx-clutch): this segfaults, but why? + // status = create_file_with_content("config.h", manifest.project, licence_line, year); + if (status) { + printfn("failed to create config.h: %s", strerror(status)); + return status; + } status = create_and_enter_directory(manifest.project); + ++depth; if (status) { printfn("failed to create or enter directory: %s", strerror(status)); return status; } - ++depth; if (manifest.flag.GNU) { - create_file_with_content("main.c", main_c_gnu_template, - manifest.project, manifest.name); - - goto atexit_clean; + status = create_file_with_content("main.c", main_c_gnu_template, + manifest.project, + manifest.name); + } else { + status = create_file_with_content("main.c", main_c_template, + manifest.project, + manifest.name); } - - create_file_with_content("main.c", main_c_template, manifest.project, - manifest.name); - -atexit_clean: - reset_path; - return 0; + return status; } static int create_project(manifest_t manifest) @@ -399,25 +408,25 @@ static int create_project(manifest_t manifest) } // TODO(vx-clutch): make this smarter--or not ( macro ). - char *licence = malloc(sizeof(char) * 1024); - if (!licence) { + char *licence_line = malloc(sizeof(char) * 1024); + if (!licence_line) { printfn("failed to create memory for licence line: %s", strerror(status)); return status; } - status = create_licence(manifest, &licence); + status = create_licence(manifest, &licence_line); if (status) { printfn("failed to get libraries: %s", strerror(status)); return status; } // TODO(vx-clutch): Take in licence line and put it into standard.c - status = generate_source_code(manifest); + status = generate_source_code(manifest, licence_line); if (status) { printfn("failed to generate source code: %s", strerror(status)); return status; } - free(licence); + free(licence_line); status = create_libraries(manifest); if (status) { @@ -445,7 +454,12 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - parse_arguments(&manifest, argc, argv); + // TODO(vx-clutch): enable argument parsing + // parse_arguments(&manifest, argc, argv); + manifest.project = "sample_project"; + manifest.name = "vx_clutch"; + manifest.licence = BSD3; + manifest.libraries = ADD_LIBRARY(manifest.libraries, LIB_NONE); status = create_project(manifest); return status == 0 ? EXIT_SUCCESS : EXIT_FAILURE;