This commit is contained in:
2025-11-04 21:14:47 -05:00
parent 45a305aec4
commit 116fb662c8
10 changed files with 134 additions and 24 deletions

View File

@@ -2,7 +2,7 @@
PACKAGE := yait
SRCS := $(wildcard src/*.c) $(wildcard lib/*.c)
OBJS := $(patsubst src/%.c,build/obj/%.o,$(SRCS))
OBJS := $(patsubst %.c,build/obj/%.o,$(SRCS))
BIN := bin/$(PACKAGE)
@@ -21,23 +21,29 @@ all:
@exit 1
else
all: build $(BIN) doc
all: $(BIN)
build:
mkdir -p bin
mkdir -p build/obj
bin:
@mkdir -p bin
build/obj/%.o: src/%.c config.mak
$(CC) $(FLAGS) $(CFLAGS) -c $< -o $@
build/obj:
@mkdir -p build/obj/src
@mkdir -p build/obj/lib
$(BIN): $(OBJS)
$(CC) $(FLAGS) $(CFLAGS) $^ -o $@
build/obj/%.o: %.c config.mak | build/obj
@printf " CC %s\n" $(notdir $@)
@$(CC) $(FLAGS) $(CFLAGS) -c $< -o $@
$(BIN): $(OBJS) | bin
@printf " LINK %s\n" "$(notdir $@)"
@$(CC) $(FLAGS) $(CFLAGS) $^ -o $@
endif
install: $(BIN)
cp $(BIN) $(PREFIX)
endif
doc:
$(MAKE) -C doc all
@@ -54,10 +60,10 @@ distclean: clean
$(RM) $(TARBALL)
$(MAKE) -C doc clean
release: clean all
release: distclean all
tar -czf $(TARBALL) $(RELEASE_FILES)
test:
@$(BIN) --version > /dev/null 2>&1 && echo "intact"|| echo "defective"
@$(BIN) --version > /dev/null 2>&1 && echo "intact" || echo "defective"
.PHONY: all clean distclean install uninstall build release doc
.PHONY: all clean distclean install uninstall doc

4
TODO
View File

@@ -2,7 +2,7 @@ GCK yait --- TODO
Todo:
* fix 't' so that it handles names correctly
* write all templates
* fix 't' so that it handles names correctly and special in-file characters
* write all templates sources
end of file TODO

20
src/flat.c Normal file
View File

@@ -0,0 +1,20 @@
// SPDX-License-Identifer: BSD-3-Clause
/*
* A uemacs derided and inspired layout and format for smaller projects;
* such as, a small library, or CLI.
*/
#include <lib/fs.h>
#include <lib/say.h>
#include <template.h>
#include "flat.h"
int generate_flat(char *package, char *author, int year, char *license,
char *desc)
{
char *main;
asprintf(&main, "%s.c", package);
fs_write("Makefile", templ_flat_MAKEFILE, package);
fs_write(main, templ_main, license);
return 0;
}

8
src/flat.h Normal file
View File

@@ -0,0 +1,8 @@
// SPDX-License-Identifier: BSD-3-Clause
#ifndef FLAT_H_
#define FLAT_H_
int generate_flat(char *package, char *author, int year, char *license,
char *desc);
#endif

View File

@@ -1,6 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause
#ifndef LICENCES_H
#define LICENCES_H
#ifndef LICENCES_H_
#define LICENCES_H_
const char *fBSD = "\
BSD 3-Clause License\n\

View File

@@ -1,6 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause
#ifndef SHELL_H
#define SHELL_H
#ifndef SHELL_H_
#define SHELL_H_
int write_shell(char *package, char *license, int year, char *author, char *m);

View File

@@ -3,7 +3,6 @@
* Copyright (C) 2025, GCK.
* Written by vx-clutch (vx-clutch)
*/
#include <config.h>
#include <errno.h>
#include <getopt.h>
@@ -23,12 +22,14 @@
#include "shell.h"
#include "license.h"
#include <template.h>
typedef enum { MIT, GPL, BSD, UNL } license_t;
static const struct option longopts[] = {
{ "author", required_argument, 0, 'a' },
{ "license", required_argument, 0, 'l' },
{ "flat", no_argument, 0, 'f' },
{ 0, 0, 0, 0 }
};
@@ -96,6 +97,7 @@ int main(int argc, char **argv)
int lose = 0;
char *m = str_dup("Does a thing"), *package;
bool shell = false;
bool flat = false;
char *author = get_name();
exit_status = EXIT_SUCCESS;
int year = get_year();
@@ -147,6 +149,9 @@ int main(int argc, char **argv)
case 'S':
shell = true;
break;
case 'f':
flat = true;
break;
default:
lose = 1;
}
@@ -175,9 +180,30 @@ int main(int argc, char **argv)
if (chdir(project_dir))
fatalfa(errno);
switch (license) {
case MIT:
fs_write("COPYING", fMIT, year, author);
break;
case GPL:
fs_write("COPYING", fGPL);
break;
case BSD:
fs_write("COPYING", fBSD, year, author);
break;
case UNL:
default:
fs_write("COPYING", fUNL);
}
fs_write("README", templ_README, author, package, package, m, year,
author, author, package);
fs_write("README-dev", templ_README_dev, year, author);
package, author, package);
if (flat)
exit_status =
generate_flat(package, author, year, license_str, m);
else
exit_status =
generate_regular(package, author, year, license_str, m);
return exit_status;
}

View File

@@ -1,4 +1,4 @@
Format_Index: p
Format_Index: p
# SPDX-License-Identifier: BSD-3-Clause
PACKAGE := %s

View File

@@ -1,4 +1,4 @@
Format_Index: a, p, p, d, y, a, a, p
Format_Index: a, p, p, d, y, p, a, p
This is the README file for the %s %s distribution.
%s %s

50
t/main.x Normal file
View File

@@ -0,0 +1,50 @@
Format_Index: l, y, a, d, a
// SPDX-License-Identifier: %s
/*
* Copyright (C) %d, %s.
* Written by YOU (you@example.com)
*/
#include <stdlib.h>
static int exit_status;
static void print_help();
static void print_version();
int main(int argc, char **argv)
{
exit_status = EXIT_SUCCESS;
return exit_status;
}
static void print_help()
{
printf("Usage: %%s [OPTION]...\n", PROGRAM);
fputs("\
%s.\n",
stdout);
puts("");
fputs("\
--help display this help and exit\n\
--version display version information and exit\n",
stdout);
/*
puts("");
fputs("\
--foo Enable the foo directive\n",
stdout);
*/
exit(exit_status);
}
static void print_version()
{
printf("%%s %%s %%d\n", prog_name, VERSION, COMMIT);
printf("Copyright (C) %%d %s.\n", YEAR);
puts("This is free software: you are free to change and redistribute it.");
puts("There is NO WARRANTY, to the extent permitted by law.");
exit(exit_status);
}