save
This commit is contained in:
44
Project/Makefile
Normal file
44
Project/Makefile
Normal 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
0
Project/configure
vendored
Normal file
BIN
c-out/bin/yait
Executable file
BIN
c-out/bin/yait
Executable file
Binary file not shown.
BIN
c-out/obj/main.o
Normal file
BIN
c-out/obj/main.o
Normal file
Binary file not shown.
4
config.mak
Normal file
4
config.mak
Normal file
@@ -0,0 +1,4 @@
|
||||
PREFIX=/usr/bin/
|
||||
CFLAGS=-Wall -Wextra -ggdb
|
||||
LDFLAGS=
|
||||
CC=clang
|
||||
44
sample_project/Makefile
Normal file
44
sample_project/Makefile
Normal 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
0
sample_project/configure
vendored
Normal file
@@ -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")
|
||||
|
||||
54
yait/main.c
54
yait/main.c
@@ -15,6 +15,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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;
|
||||
|
||||
Reference in New Issue
Block a user