This commit is contained in:
2025-08-07 09:46:57 -04:00
parent b7e67b1440
commit cd1fded589
9 changed files with 127 additions and 21 deletions

44
Project/Makefile Normal file
View File

@@ -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

0
Project/configure vendored Normal file
View File

BIN
c-out/bin/yait Executable file

Binary file not shown.

BIN
c-out/obj/main.o Normal file

Binary file not shown.

4
config.mak Normal file
View File

@@ -0,0 +1,4 @@
PREFIX=/usr/bin/
CFLAGS=-Wall -Wextra -ggdb
LDFLAGS=
CC=clang

44
sample_project/Makefile Normal file
View File

@@ -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

0
sample_project/configure vendored Normal file
View File

View File

@@ -177,7 +177,7 @@ char *config_h_template =
line () line ()
line ("/* Program information */") line ("/* Program information */")
line ("#define PROGRAM \"%s\"") line ("#define PROGRAM \"%s\"")
line ("#define LICENSE_line \"%s\"") line ("#define LICENSE_LINE \"%s\"")
line ("#define AUTHORS \"%s\"") line ("#define AUTHORS \"%s\"")
line ("#define VERSION \"pre-alpha\"") line ("#define VERSION \"pre-alpha\"")
line ("#define YEAR 2025") line ("#define YEAR 2025")

View File

@@ -15,6 +15,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include "../config.h" #include "../config.h"
@@ -329,31 +330,39 @@ static int create_configure(manifest_t manifest)
return status; 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); status = create_and_enter_directory(manifest.project);
++depth;
if (status) { if (status) {
printfn("failed to create or enter directory: %s", printfn("failed to create or enter directory: %s",
strerror(status)); strerror(status));
return status; return status;
} }
++depth;
if (manifest.flag.GNU) { if (manifest.flag.GNU) {
create_file_with_content("main.c", main_c_gnu_template, status = create_file_with_content("main.c", main_c_gnu_template,
manifest.project, manifest.name); manifest.project,
goto atexit_clean;
}
create_file_with_content("main.c", main_c_template, manifest.project,
manifest.name); manifest.name);
} else {
atexit_clean: status = create_file_with_content("main.c", main_c_template,
reset_path; manifest.project,
return 0; manifest.name);
}
return status;
} }
static int create_project(manifest_t manifest) 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 ). // TODO(vx-clutch): make this smarter--or not ( macro ).
char *licence = malloc(sizeof(char) * 1024); char *licence_line = malloc(sizeof(char) * 1024);
if (!licence) { if (!licence_line) {
printfn("failed to create memory for licence line: %s", printfn("failed to create memory for licence line: %s",
strerror(status)); strerror(status));
return status; return status;
} }
status = create_licence(manifest, &licence); status = create_licence(manifest, &licence_line);
if (status) { if (status) {
printfn("failed to get libraries: %s", strerror(status)); printfn("failed to get libraries: %s", strerror(status));
return status; return status;
} }
// TODO(vx-clutch): Take in licence line and put it into standard.c // 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) { if (status) {
printfn("failed to generate source code: %s", strerror(status)); printfn("failed to generate source code: %s", strerror(status));
return status; return status;
} }
free(licence); free(licence_line);
status = create_libraries(manifest); status = create_libraries(manifest);
if (status) { if (status) {
@@ -445,7 +454,12 @@ int main(int argc, char **argv)
return EXIT_FAILURE; 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); status = create_project(manifest);
return status == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return status == 0 ? EXIT_SUCCESS : EXIT_FAILURE;