save
This commit is contained in:
8
IDEA
Normal file
8
IDEA
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
./yait .
|
||||||
|
Creating files 12, done.
|
||||||
|
Changing permissions 2, done.
|
||||||
|
Pulling ncurses, done.
|
||||||
|
Pulling ux, done.
|
||||||
|
Initializing git repository, done.
|
||||||
|
Created yait at
|
||||||
|
/home/vx-clutch/projects/yait
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "manifest.h"
|
#include "manifest.h"
|
||||||
#include "contents.h"
|
#include "contents.h"
|
||||||
@@ -25,18 +26,6 @@
|
|||||||
#define DEFAULT_CLANG_FORMAT true
|
#define DEFAULT_CLANG_FORMAT true
|
||||||
#define DEFAULT_GNU false
|
#define DEFAULT_GNU false
|
||||||
|
|
||||||
int depth = 0;
|
|
||||||
|
|
||||||
static int reset_path(void)
|
|
||||||
{
|
|
||||||
while (depth > 0) {
|
|
||||||
if (chdir("..") != 0)
|
|
||||||
return errno;
|
|
||||||
depth--;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int program_exists(const char *prog)
|
int program_exists(const char *prog)
|
||||||
{
|
{
|
||||||
char *path = getenv("PATH");
|
char *path = getenv("PATH");
|
||||||
@@ -95,10 +84,6 @@ int create_libraries(manifest_t manifest)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = reset_path();
|
|
||||||
if (ret != 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (HAS_LIBRARY(manifest.libraries, LIB_RAYLIB)) {
|
if (HAS_LIBRARY(manifest.libraries, LIB_RAYLIB)) {
|
||||||
REMOVE_LIBRARY(manifest.libraries, LIB_RAYLIB);
|
REMOVE_LIBRARY(manifest.libraries, LIB_RAYLIB);
|
||||||
status = system(
|
status = system(
|
||||||
@@ -131,10 +116,6 @@ int create_licence(manifest_t manifest, char **licence_line_buffer)
|
|||||||
if (manifest.licence == UNLICENCE)
|
if (manifest.licence == UNLICENCE)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int ret = reset_path();
|
|
||||||
if (ret != 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (!licence_line_buffer)
|
if (!licence_line_buffer)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
@@ -160,10 +141,6 @@ int create_licence(manifest_t manifest, char **licence_line_buffer)
|
|||||||
|
|
||||||
int maybe_create_clang_format(manifest_t manifest)
|
int maybe_create_clang_format(manifest_t manifest)
|
||||||
{
|
{
|
||||||
int ret = reset_path();
|
|
||||||
if (ret != 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (!manifest.flag.clang_format)
|
if (!manifest.flag.clang_format)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -177,10 +154,6 @@ int setup_git(manifest_t manifest)
|
|||||||
if (!manifest.flag.git)
|
if (!manifest.flag.git)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
int ret = reset_path();
|
|
||||||
if (ret != 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
int status = system("git init --quiet");
|
int status = system("git init --quiet");
|
||||||
if (status == -1) {
|
if (status == -1) {
|
||||||
fprintf(stderr, "...: %s\n", strerror(errno));
|
fprintf(stderr, "...: %s\n", strerror(errno));
|
||||||
@@ -205,14 +178,9 @@ int create_makefile(manifest_t manifest)
|
|||||||
if (*p >= 'a' && *p <= 'z')
|
if (*p >= 'a' && *p <= 'z')
|
||||||
*p -= 'a' - 'A';
|
*p -= 'a' - 'A';
|
||||||
|
|
||||||
int ret = reset_path();
|
int status = create_file_with_content(strcat(m, "Makefile"),
|
||||||
if (ret != 0) {
|
makefile_template, M, m, M, m, M,
|
||||||
free(M);
|
M, m, M, m, M, m);
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int status = create_file_with_content("Makefile", makefile_template, M,
|
|
||||||
m, M, m, M, M, m, M, m, M, m);
|
|
||||||
|
|
||||||
free(m);
|
free(m);
|
||||||
free(M);
|
free(M);
|
||||||
@@ -221,10 +189,6 @@ int create_makefile(manifest_t manifest)
|
|||||||
|
|
||||||
int create_configure(manifest_t manifest)
|
int create_configure(manifest_t manifest)
|
||||||
{
|
{
|
||||||
int ret = reset_path();
|
|
||||||
if (ret != 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
const char *cc;
|
const char *cc;
|
||||||
if (manifest.flag.use_cpp) {
|
if (manifest.flag.use_cpp) {
|
||||||
cc = "trycc g++\ntrycc CC\ntrycc clang++\n";
|
cc = "trycc g++\ntrycc CC\ntrycc clang++\n";
|
||||||
@@ -268,7 +232,6 @@ int generate_source_code(manifest_t manifest, char *licence_line)
|
|||||||
strerror(status));
|
strerror(status));
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
depth++;
|
|
||||||
|
|
||||||
if (manifest.flag.GNU) {
|
if (manifest.flag.GNU) {
|
||||||
status = create_file_with_content(
|
status = create_file_with_content(
|
||||||
@@ -289,15 +252,24 @@ int create_project(manifest_t manifest)
|
|||||||
|
|
||||||
sanitize(&manifest);
|
sanitize(&manifest);
|
||||||
|
|
||||||
// TODO(vx-clutch): make the path the project root.
|
|
||||||
if (strcmp(manifest.path, ".") != 0) {
|
if (strcmp(manifest.path, ".") != 0) {
|
||||||
|
status = mkdir(manifest.path, 0755);
|
||||||
|
if (status != 0 && errno != EEXIST) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"create_project: failed to create directory '%s': %s\n",
|
||||||
|
manifest.path, strerror(errno));
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = chdir(manifest.path);
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"create_project: failed to create or enter directory: %s\n",
|
"create_project: failed to enter directory '%s': %s\n",
|
||||||
strerror(status));
|
manifest.path, strerror(errno));
|
||||||
return status;
|
return errno;
|
||||||
}
|
}
|
||||||
depth++;
|
} else {
|
||||||
|
manifest.path = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
status = create_makefile(manifest);
|
status = create_makefile(manifest);
|
||||||
@@ -365,7 +337,8 @@ int create_project(manifest_t manifest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO(vx-clutch): Make path absolute.
|
// TODO(vx-clutch): Make path absolute.
|
||||||
fprintf(stderr, "Created %s at\n %s", manifest.project, manifest.path);
|
fprintf(stderr, "Created %s at\n %s", manifest.project,
|
||||||
|
realpath(manifest.path, NULL));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ typedef struct {
|
|||||||
#define ADD_LIBRARY(libs, lib) ((libs) |= (lib))
|
#define ADD_LIBRARY(libs, lib) ((libs) |= (lib))
|
||||||
#define REMOVE_LIBRARY(libs, lib) ((libs) &= ~(lib))
|
#define REMOVE_LIBRARY(libs, lib) ((libs) &= ~(lib))
|
||||||
|
|
||||||
static lib_flags_t TOLibrary(char *src)
|
[[maybe_unused]] static lib_flags_t TOLibrary(char *src)
|
||||||
{
|
{
|
||||||
if (strcmp(src, "raylib"))
|
if (strcmp(src, "raylib"))
|
||||||
return LIB_RAYLIB;
|
return LIB_RAYLIB;
|
||||||
|
|||||||
@@ -85,7 +85,10 @@ static int parse_arguments(manifest_t *conf, int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
ADD_LIBRARY(conf->libraries, TOLibrary(optarg));
|
if (strcmp(optarg, "help"))
|
||||||
|
fprintf(stderr, "raylib\nncurses\ncurl\n");
|
||||||
|
else
|
||||||
|
ADD_LIBRARY(conf->libraries, TOLibrary(optarg));
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(0);
|
usage(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user