This commit is contained in:
2025-09-03 19:43:09 -04:00
parent 13b15cb07f
commit 19c1e37cd2
7 changed files with 71 additions and 91 deletions

11
doc/default Normal file
View File

@@ -0,0 +1,11 @@
Yb dP db 88 888888
YbdP dPYb 88 88
8P dP__Yb 88 88
dP dP""""Yb 88 88
yait manual
default
#######
This documentation goes over the whats and whys of the yait default layout.

View File

@@ -1,71 +0,0 @@
Yb dP db 88 888888
YbdP dPYb 88 88
8P dP__Yb 88 88
dP dP""""Yb 88 88
yait manual
styles
######
In yait there are a few pre-made styles you can choose from. Those styles being
the following.
* posix (default)
* gnu
* simple
* lib
* fasm
These can be selected through setting the --style=<STYLE> flag.
The POSIX style is the default style of yait and is the format used for the
project. The POSIX style is structured as the following:
project/
bin/
build/
doc/
include/
project.h
man/
project.1
src/
main.c
COPYING
Makefile
README
The GNU style is based on the GNU project layout guide; however, it is minified.
project/
man/
project.1
src/
main.c
AUTHORS
COPYING
INSTALL
NEWS
README
configure.ac
The Simple style is a minimal layout for short and sweet projects.
project/
project.c
Makefile
README
The Lib style is a layout for created libraries that compile to a .a and .so file.
project/
include/
project.h
src/
project.c
Makefile
README
The Fasm style is a layout based on the flat assembler.
project/
SOURCE/
main.c
TOOLS/
build.sh
PROJECT.TXT

View File

@@ -15,7 +15,6 @@ typedef struct {
licence_t licence; licence_t licence;
bool lib; bool lib;
bool exe;
bool git; bool git;
bool autotools; bool autotools;
@@ -26,9 +25,9 @@ typedef struct {
bool open_editor; bool open_editor;
struct { struct {
bool nob; bool build_nob;
bool clang_format; bool tools_format;
bool Cleanup; bool tools_Cleanup;
} extra; } extra;
char *project; char *project;

View File

@@ -2,7 +2,7 @@
* *
* 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 licensed under the BSD-3-Clause licence.
* <https://opensource.org/licence/bsd-3-clause> * <https://opensource.org/licence/bsd-3-clause>
*/ */
@@ -29,6 +29,43 @@ int create_project(manifest_t manifest)
if (status) if (status)
return 1; return 1;
if (manifest.bare) {
cfprintf("main.c", "");
cfprintf(
"Makefile",
".POSIX:\nCC ::= gcc\nCFLAGS ::= -std=c23 -Wall -Wextra -Wpedantic\n\nall: %s\n\nclean\n\t$(RM) %s",
manifest.project, manifest.project);
cfprintf("README", "%s", manifest.project);
goto bare_skip;
}
main_source = manifest.flat ? "main.c" : "src/main.c";
cfprintf(main_source, "#include <stdio.h>\n"
"\n"
"int main()\n"
"{\n"
"\tputs(\"Hello, World!\");\n"
"\treturn 0;\n"
"}\n");
char *upr_name = tostrupr(manifest.project);
if (manifest.make) {
cfprintf(
"Makefile",
"PREFIX = /usr/bin\n"
"\n"
"%s_SRCS := $(wildcard src/*.c)\n"
"%s_OBJS := $(patsubst src/%.c,build/obj/%.o,$(%s_SRCS))"
"\n"
"%s := bin/%s"
"\n"
"-include config.mak\n"
"\n"
"ifeq ($(wildcard config.mak),)\n",
upr_name, upr_name, upr_name, upr_name,
manifest.project);
}
bare_skip:
flast = true; flast = true;
switch (manifest.licence) { switch (manifest.licence) {
case MIT: case MIT:

View File

@@ -2,7 +2,7 @@
* *
* 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 licensed under the BSD-3-Clause licence.
* <https://opensource.org/license/bsd-3-clause> * <https://opensource.org/license/bsd-3-clause>
*/ */
@@ -49,6 +49,7 @@ int mkdir_p(const char *path)
int cfprintf(const char *path, const char *format, ...) int cfprintf(const char *path, const char *format, ...)
{ {
int lines = atoi(getenv("LINES"));
char *dirpath; char *dirpath;
const char *slash = strrchr(path, '/'); const char *slash = strrchr(path, '/');
if (slash) { if (slash) {

View File

@@ -2,7 +2,7 @@
* *
* 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 licensed under the BSD-3-Clause licence.
* <https://opensource.org/licence/bsd-3-clause> * <https://opensource.org/licence/bsd-3-clause>
*/ */

View File

@@ -37,8 +37,10 @@ static void usage(int status)
puts("Creates a C project with opinionated defaults"); puts("Creates a C project with opinionated defaults");
puts("When only given the first argument it will detect your name\n"); puts("When only given the first argument it will detect your name\n");
puts("Mandatory arguments to long options are mandatory for short options too"); puts("Mandatory arguments to long options are mandatory for short options too");
print_option("--git", "Initialize git repository (default)");
print_option("--no-git", "Do not initialize git repository"); print_option("--no-git", "Do not initialize git repository");
print_option("-L <licence>", print_option("--lib", "Make this a library");
print_option("-l <licence>",
"Set licence. This list can be found by passing 'list'"); "Set licence. This list can be found by passing 'list'");
print_option("-E", "Open editor after project creation"); print_option("-E", "Open editor after project creation");
puts(" --help display this help text and exit\n"); puts(" --help display this help text and exit\n");
@@ -66,11 +68,11 @@ static inline int parse_extras_token(manifest_t *conf, char *s)
} }
if (!strcmp(s, "nob")) if (!strcmp(s, "nob"))
return conf->extra.nob = true, 0; return conf->extra.build_nob = true, 0;
if (!strcmp(s, "Cleanup")) if (!strcmp(s, "Cleanup"))
return conf->extra.Cleanup = true, 0; return conf->extra.tools_Cleanup = true, 0;
if (!strcmp(s, "format")) if (!strcmp(s, "format"))
return conf->extra.clang_format = true, 0; return conf->extra.tools_format = true, 0;
fprintf(stderr, "Option '%s' is not valid. See %s --extras=list\n", s, fprintf(stderr, "Option '%s' is not valid. See %s --extras=list\n", s,
PROGRAM); PROGRAM);
return 1; return 1;
@@ -85,7 +87,6 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
{ "git", no_argument, 0, 'g' }, { "git", no_argument, 0, 'g' },
{ "no-git", no_argument, 0, 'G' }, { "no-git", no_argument, 0, 'G' },
{ "lib", no_argument, 0, 'L' }, { "lib", no_argument, 0, 'L' },
{ "both", no_argument, 0, 'b' },
{ "autotools", no_argument, 0, 'a' }, { "autotools", no_argument, 0, 'a' },
{ "cmake", no_argument, 0, 'c' }, { "cmake", no_argument, 0, 'c' },
{ "make", no_argument, 0, 'm' }, { "make", no_argument, 0, 'm' },
@@ -120,18 +121,20 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
case 'L': case 'L':
conf->lib = true; conf->lib = true;
break; break;
case 'b':
conf->lib = true;
conf->exe = true;
break;
case 'a': case 'a':
conf->autotools = true; conf->autotools = true;
conf->cmake = false;
conf->make = false;
break; break;
case 'c': case 'c':
conf->cmake = true; conf->cmake = true;
conf->autotools = false;
conf->make = false;
break; break;
case 'm': case 'm':
conf->make = true; conf->make = true;
conf->autotools = false;
conf->cmake = false;
break; break;
case 'B': case 'B':
conf->bare = true; conf->bare = true;
@@ -183,7 +186,6 @@ int get_name(char **output)
size_t chunk_len = strlen(buffer); size_t chunk_len = strlen(buffer);
char *new_output = realloc(*output, output_len + chunk_len + 1); char *new_output = realloc(*output, output_len + chunk_len + 1);
if (!new_output) { if (!new_output) {
free(*output);
pclose(pipe); pclose(pipe);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@@ -218,10 +220,11 @@ int main(int argc, char **argv)
.bare = false, .bare = false,
.flat = false, .flat = false,
.open_editor = false, .open_editor = false,
.lib = false,
.extra.nob = false, .extra.build_nob = false,
.extra.clang_format = false, .extra.tools_format = false,
.extra.Cleanup = false, .extra.tools_Cleanup = false,
}; };
status = parse_standard_options(usage, argc, argv); status = parse_standard_options(usage, argc, argv);