feat: FASM target

This commit is contained in:
2025-08-22 20:51:25 -04:00
parent 8fb97ffa8f
commit a38010ec62
7 changed files with 108 additions and 60 deletions

View File

@@ -17,8 +17,8 @@ all: build $(YAIT)
build: build:
mkdir -p bin mkdir -p bin
$(YAIT): $(YAIT_SRCS) $(YAIT): $(YAIT_SRCS) config.mak
$(CC) $(CFLAGS) -Iinclude -DCOMMIT=$(shell git rev-list --count --all) $^ -o $@ $(CC) $(CFLAGS) -Iinclude -DCOMMIT=$(shell git rev-list --count --all) $(YAIT_SRCS) -o $@
endif endif

1
TODO
View File

@@ -4,7 +4,6 @@ Todo:
* Project formats * Project formats
* GNU * GNU
* FASM * FASM
* POSIX
* LIBRARY * LIBRARY
end of file TODO end of file TODO

View File

@@ -22,20 +22,9 @@ typedef struct {
bool linenoise; bool linenoise;
} libmap_t; } libmap_t;
typedef enum { typedef enum { MIT, GPL, BSD, UNL, _LICENCE_COUNT_ } licence_t;
MIT,
GPL,
BSD,
UNL,
} licence_t;
typedef enum { typedef enum { POSIX, SIMPLE, GNU, LIBRARY, FASM, _STYLE_COUNT_ } style_t;
POSIX,
SIMPLE,
GNU,
LIBRARY,
FASM,
} style_t;
typedef struct { typedef struct {
libmap_t libraries; libmap_t libraries;

View File

@@ -6,51 +6,80 @@
* <https://opensource.org/licence/bsd-3-clause> * <https://opensource.org/licence/bsd-3-clause>
*/ */
#include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h>
#include "../include/yait.h" #include "../include/yait.h"
#include "util.h" #include "util.h"
#include "contents.h" #include "contents.h"
char buffer[BUFSIZ]; #define emit_progress_file \
fprintf(stderr, "Created files %d\r", a); \
a++
int create_project(manifest_t manifest) int create_project(manifest_t manifest)
{ {
mkdir_p(manifest.project); int status, a = 1;
chdir(manifest.project); char buffer[BUFSIZ];
if (manifest.style == SIMPLE) { status = mkdir_p(manifest.project);
/* This only works if the source if (status)
files's root name is the same as the target on all of the Makefile becuase of how it checks for files. */ return 1;
status = chdir(manifest.project);
if (status)
return 1;
switch (manifest.style) {
case SIMPLE:
cfprintf( cfprintf(
"Makefile", "Makefile",
".POSIX:\nCC ::= gcc\nCFLAGS ::= -Wall --std=c23 -Wpedantic\n\nall: %s", ".POSIX:\nCC ::= gcc\nCFLAGS ::= -Wall --std=c23 -Wpedantic\n\nall: %s",
manifest.project); manifest.project);
fprintf(stderr, "Created files 1\r"); emit_progress_file;
cfprintf("README", "%s", manifest.project); cfprintf("README", "%s", manifest.project);
fprintf(stderr, "Created files 2\r"); emit_progress_file;
snprintf(buffer, BUFSIZ, "%s.c", manifest.project); snprintf(buffer, BUFSIZ, "%s.c", manifest.project);
cfprintf(buffer, ""); cfprintf(buffer, "");
fputs("Created files 3, done.\n", stderr); fprintf(stderr, "Created files %d, done.\n", a);
/* We exit early because the simple flag is an overridding flag. */ break;
return 0;
case POSIX:
cfprintf("Makefile", "");
cfprintf("configure", configure);
cfprintf(".clang-format", "");
cfprintf("README", readme, manifest.name);
cfprintf("src/main.c", "");
snprintf(buffer, BUFSIZ, "include/%s.h", manifest.project);
cfprintf(buffer, "");
snprintf(buffer, BUFSIZ, "man/%s.1", manifest.project);
cfprintf(buffer, ".\\\" %s.1 - Manual page for %s",
manifest.project, manifest.project);
cfprintf("doc/WHATNEXT", what_next);
break;
case FASM:
snprintf(buffer, BUFSIZ, "%s.txt", manifest.project);
for (int i = 0; buffer[i] != '\0'; ++i)
buffer[i] = toupper((unsigned char)buffer[i]);
cfprintf(
buffer,
"<https://github.com/tgrysztar/fasm/blob/master/FASM.TXT>");
cfprintf(
"SOURCE/main.c",
"#include <stdio.h>\n\nint main() {\n\tputs(\"Hei!\");\n\treturn 0;\n}");
cfprintf("TOOLS/build.sh",
"#!/bin/sh\n\ncc SOURCE/main.c -o %s",
manifest.project);
break;
default:
abort();
} }
cfprintf("Makefile", "");
cfprintf("configure", configure);
cfprintf(".clang-format", "");
cfprintf("README", readme, manifest.name);
cfprintf("src/main.c", "");
snprintf(buffer, BUFSIZ, "include/%s.h", manifest.project);
cfprintf(buffer, "");
snprintf(buffer, BUFSIZ, "man/%s.1", manifest.project);
cfprintf(buffer, "");
cfprintf("doc/WHATNEXT", what_next);
return 0; return 0;
} }

View File

@@ -24,15 +24,6 @@
#define print_option(option, description) \ #define print_option(option, description) \
printf(" %-20s %-20s\n", option, description) printf(" %-20s %-20s\n", option, description)
char *str_dup(char *s)
{
char *new = malloc(strlen(s) + 1);
if (!new)
return NULL;
strcpy(new, s);
return new;
}
static void usage(int status) static void usage(int status)
{ {
if (status != 0) { if (status != 0) {
@@ -46,8 +37,10 @@ static void usage(int status)
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("--no-git", "Do not inititize git reposity"); print_option("--no-git", "Do not inititize git reposity");
print_option("--clang", "Add clang-format files and tooling"); print_option("--clang", "Add clang-format files and tooling");
print_option("-L <licence>", "Set licence"); print_option("-L <licence>",
print_option("-l <library>", "Add a library"); "Set licence. This list can be found by passing 'list'");
print_option("-l <library>",
"Add a library. This list can be found by passing 'list'");
print_option("-n <name>", "Set the name of the project"); print_option("-n <name>", "Set the name of the project");
print_option( print_option(
"--style=<style>", "--style=<style>",
@@ -68,14 +61,16 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
{ 0, 0, 0, 0 } }; { 0, 0, 0, 0 } };
// clang-format on // clang-format on
// TODO(vx-clutch): lL // TODO(vx-clutch): libraries
while ((opt = getopt_long(argc, argv, "s:gcn", long_opts, NULL)) != while ((opt = getopt_long(argc, argv, "s:gcn:L:", long_opts, NULL)) !=
-1) { -1) {
switch (opt) { switch (opt) {
case 's': case 's':
if (strcmp(optarg, "list") == 0) { if (strcmp(optarg, "list") == 0) {
fputs("", stderr); puts("posix\nsimple\nGNU\nlib\nfasm");
exit(EXIT_SUCCESS);
} }
conf->style = TOstyle(optarg);
break; break;
case 'g': case 'g':
conf->flags.git = false; conf->flags.git = false;
@@ -86,6 +81,9 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
case 'n': case 'n':
conf->name = str_dup(optarg); conf->name = str_dup(optarg);
break; break;
case 'L':
conf->licence = TOlicence(optarg);
break;
default: default:
return 1; return 1;
} }
@@ -161,6 +159,11 @@ int main(int argc, char **argv)
get_name(&manifest.name); get_name(&manifest.name);
status = create_project(manifest); status = create_project(manifest);
if (status) {
fprintf(stderr, "%s\n", strerror(status));
return EXIT_FAILURE;
}
char buffer[PATH_MAX]; char buffer[PATH_MAX];
getcwd(buffer, PATH_MAX); getcwd(buffer, PATH_MAX);
fprintf(stderr, "Created %s at\n %s\n", manifest.project, buffer); fprintf(stderr, "Created %s at\n %s\n", manifest.project, buffer);

View File

@@ -1,21 +1,46 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <getopt.h> #include <getopt.h>
#include <stdlib.h>
#include "util.h" #include "util.h"
#include "../include/yait.h" #include "../include/yait.h"
licence_t TOlicence(const char *s) licence_t TOlicence(char *s)
{ {
if (strcmp(s, "mit")) if (!strcmp(s, "mit"))
return MIT; return MIT;
if (strcmp(s, "gpl")) if (!strcmp(s, "gpl"))
return GPL; return GPL;
if (strcmp(s, "bsd")) if (!strcmp(s, "bsd"))
return BSD; return BSD;
return UNL; return UNL;
} }
style_t TOstyle(char *s)
{
if (!strcmp(s, "posix"))
return POSIX;
if (!strcmp(s, "simple"))
return SIMPLE;
if (!strcmp(s, "GNU"))
return GNU;
if (!strcmp(s, "lib"))
return LIBRARY;
if (!strcmp(s, "fasm"))
return FASM;
return SIMPLE;
}
char *str_dup(char *s)
{
char *new = malloc(strlen(s) + 1);
if (!new)
return NULL;
strcpy(new, s);
return new;
}
static char *nextchar; static char *nextchar;
int getopt_long(int argc, char *const argv[], const char *optstring, int getopt_long(int argc, char *const argv[], const char *optstring,

View File

@@ -3,11 +3,14 @@
#include "../include/yait.h" #include "../include/yait.h"
licence_t TOlicence(const char *s); licence_t TOlicence(char *s);
style_t TOstyle(char *s);
int getopt_long(int argc, char *const argv[], const char *optstring, int getopt_long(int argc, char *const argv[], const char *optstring,
const struct option *longopts, int *longindex); const struct option *longopts, int *longindex);
char *str_dup(char *s);
int mkdir_p(const char *path); int mkdir_p(const char *path);
int cfprintf(const char *path, const char *format, ...); int cfprintf(const char *path, const char *format, ...);