aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordacctal <dacctal@symlinx.net>2026-06-07 05:58:15 +0000
committerdacctal <dacctal@symlinx.net>2026-06-07 05:58:15 +0000
commitea6745dd7ad75c85d0ea4471e9f3357532fb0eb0 (patch)
tree1b5a01898a845f579981303edb0709f9cc95a2f2
parentab3f27fd2fb32a52f76146970823525f044a325c (diff)
tiny fixes & .editorconfig (thx indium)0.1.1
-rw-r--r--.editorconfig9
-rw-r--r--bldit.lua43
-rw-r--r--include/vars.h4
-rw-r--r--src/add_repo.c2
-rw-r--r--src/create_pkg.c103
-rw-r--r--src/fetch_git.c1
-rw-r--r--src/install_pkg.c98
-rw-r--r--src/lua_build.c18
-rw-r--r--src/lua_state.c64
-rw-r--r--src/main.c1
-rw-r--r--src/name_from_url.c9
-rw-r--r--src/vars.c4
12 files changed, 178 insertions, 178 deletions
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..88f5c63
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,9 @@
+root = true
+
+[*]
+indent_style = space
+indent_size = 2
+max_line_length = 80
+
+[Makefile]
+indent_style = tab
diff --git a/bldit.lua b/bldit.lua
index bd39eb8..af22a1a 100644
--- a/bldit.lua
+++ b/bldit.lua
@@ -1,5 +1,5 @@
-bldit_version = "0.1.0"
-package_version = "0.1.0"
+bldit_version = "0.1.1"
+package_version = "0.1.1"
global_dependencies = {
luajit = {
@@ -10,20 +10,27 @@ global_dependencies = {
}
targets = {
- default = {
- build = function(name)
- os.execute("make")
- end,
- install = function(prefix)
- os.execute("make install")
- end,
- },
- quiet = {
- build = function(name)
- local output = io.popen("make"):read("*a")
- end,
- install = function(prefix)
- local output = io.popen("make install"):read("*a")
- end,
- },
+ default = {
+ dependencies = {
+ pipemixer = {
+ url = "https://github.com/heather7283/pipemixer",
+ version = "HEAD",
+ target = "default",
+ },
+ },
+ build = function()
+ os.execute("make")
+ end,
+ install = function()
+ os.execute("make install")
+ end,
+ },
+ quiet = {
+ build = function()
+ local output = io.popen("make"):read("*a")
+ end,
+ install = function()
+ local output = io.popen("make install"):read("*a")
+ end,
+ },
}
diff --git a/include/vars.h b/include/vars.h
index c417b95..3a56ef3 100644
--- a/include/vars.h
+++ b/include/vars.h
@@ -4,8 +4,8 @@
#include <stdbool.h>
#include <stddef.h>
-#define MAX_REPOS 100
-#define MAX_DIRS 10
+#define MAX_REPOS 1000
+#define MAX_DIRS 100
#define MAX_PATH_LEN 1024
typedef struct {
diff --git a/src/add_repo.c b/src/add_repo.c
index 0644f75..db8c46a 100644
--- a/src/add_repo.c
+++ b/src/add_repo.c
@@ -29,6 +29,4 @@ void add_repo(const char *repo, const char *repo_name) {
fprintf(wfile, "%srepositories[\"%s\"] = { url = \"%s\" }\n", previous_repos, repo_name, repo);
fclose(wfile);
}
-
- printf("%s%sAdded %s%s\n", print_pkgit, green, repo_name, color_reset);
} \ No newline at end of file
diff --git a/src/create_pkg.c b/src/create_pkg.c
index 056a3ad..36e9d10 100644
--- a/src/create_pkg.c
+++ b/src/create_pkg.c
@@ -9,66 +9,65 @@
#include "vars.h"
Pkg create_pkg(const char *arg, const char *target) {
- Pkg pkg = {0};
- pkg.target = target;
- pkg.ver = "HEAD";
- pkg.is_local = false;
+ Pkg pkg = {0};
+ pkg.target = target;
+ pkg.ver = "HEAD";
+ pkg.is_local = false;
- cache_repos();
- for (int i = 0; i < cached_repos_count; i++) {
- if (strcmp(cached_repos[i].source_key, arg) == 0) {
- pkg.ver = cached_repos[i].version;
- }
+ for (int i = 0; i < cached_repos_count; i++) {
+ if (strcmp(cached_repos[i].source_key, arg) == 0) {
+ pkg.ver = cached_repos[i].version;
}
+ }
- char* argver = strchr(arg, '@');
- char* new_arg = strdup(arg);
- if (argver) {
- argver += 1;
- pkg.ver = argver;
- int char_location = 0;
- while (arg[char_location] != '@') { char_location++; }
- new_arg[char_location] = '\0';
- }
+ char *new_arg = strdup(arg);
+ if (!new_arg) exit(EXIT_FAILURE);
+ char *argver = strchr(new_arg, '@');
+ if (argver) {
+ pkg.ver = argver + 1;
+ *argver = '\0';
+ }
- init_lua_state();
- cache_repos();
+ bool is_in_repos = false;
+ for (size_t i = 0; i < cached_repos_count; i++) {
+ if (strcmp(new_arg, cached_repos[i].source_key) == 0) {
+ is_in_repos = true;
+ break;
+ }
+ }
- bool is_in_repos = false;
+ if (strncmp(new_arg, "http", 4) == 0) {
+ pkg.url = strdup(new_arg);
+ pkg.name = name_from_url(new_arg);
+ } else if (strcmp(new_arg, ".") == 0) {
+ pkg.url = "";
+ getcwd(pkg.src, MAX_PATH_LEN);
+ pkg.name = name_from_url(pkg.url);
+ pkg.is_local = true;
+ } else if (is_in_repos) {
for (size_t i = 0; i < cached_repos_count; i++) {
- if (strcmp(new_arg, cached_repos[i].source_key) == 0) {
- is_in_repos = true;
- break;
- }
+ if (strcmp(new_arg, cached_repos[i].source_key) == 0) {
+ pkg.url = strdup(cached_repos[i].source_value);
+ break;
+ }
}
+ pkg.name = strdup(new_arg);
+ } else {
+ printf("%s'%s' is not a valid package\n", print_error, new_arg);
+ exit(EXIT_FAILURE);
+ }
- if (strncmp(new_arg, "http", 4) == 0) {
- pkg.url = strdup(new_arg);
- pkg.name = name_from_url(new_arg);
- } else if (strcmp(new_arg, ".") == 0) {
- pkg.url = "";
- getcwd(pkg.src, MAX_PATH_LEN);
- pkg.name = name_from_url(pkg.src);
- pkg.is_local = true;
- } else if (is_in_repos) {
- for (size_t i = 0; i < cached_repos_count; i++) {
- if (strcmp(new_arg, cached_repos[i].source_key) == 0) {
- pkg.url = strdup(cached_repos[i].source_value);
- break;
- }
- }
- pkg.name = strdup(new_arg);
- } else {
- printf("%s'%s' is not a valid package\n", print_error, new_arg);
- exit(EXIT_FAILURE);
- }
+ if (strlen(pkg.name) > 4 && strncmp(pkg.name + strlen(pkg.name) - 4, ".git", 4) == 0) {
+ pkg.name[strlen(pkg.name) - 4] = '\0';
+ }
- cache_install_directories();
- if (!pkg.is_local) {
- char src_dir[MAX_PATH_LEN];
- snprintf(src_dir, sizeof(src_dir), "%s/%s/%s", get_install_dir("src"), pkg.name, pkg.ver);
- snprintf(pkg.src, MAX_PATH_LEN, "%s", src_dir);
- }
+ cache_install_directories();
+ if (!pkg.is_local) {
+ char src_dir[MAX_PATH_LEN];
+ snprintf(src_dir, sizeof(src_dir), "%s/%s/%s", get_install_dir("src"),
+ pkg.name, pkg.ver);
+ snprintf(pkg.src, MAX_PATH_LEN, "%s", src_dir);
+ }
- return pkg;
+ return pkg;
} \ No newline at end of file
diff --git a/src/fetch_git.c b/src/fetch_git.c
index deb94ac..6353678 100644
--- a/src/fetch_git.c
+++ b/src/fetch_git.c
@@ -29,6 +29,7 @@ int fetch_git(Pkg pkg) {
argv[i++] = "--branch";
argv[i++] = pkg.ver;
}
+ argv[i++] = "--recursive";
argv[i++] = pkg.url;
argv[i++] = pkg.src;
argv[i] = NULL;
diff --git a/src/install_pkg.c b/src/install_pkg.c
index 4e3b3c6..8831499 100644
--- a/src/install_pkg.c
+++ b/src/install_pkg.c
@@ -3,63 +3,69 @@
#include <string.h>
#include <unistd.h>
-#include "install_pkg.h"
#include "add_repo.h"
-#include "fetch_src.h"
#include "build.h"
-//#include "copy_install.h"
-//#include "link_install.h"
+#include "fetch_src.h"
+#include "install_pkg.h"
+// #include "copy_install.h"
+// #include "link_install.h"
#include "lua_state.h"
#include "name_from_url.h"
#include "vars.h"
void install_pkg(Pkg pkg) {
- if (!pkg.is_local) {
- printf("%sfetching %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
- fetch_src(pkg);
- if (is_verbose) printf("%sfetched %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
- }
+ if (!pkg.is_local) {
+ printf("%sfetching %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ fetch_src(pkg);
+ if (is_verbose)
+ printf("%sfetched %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ }
- printf("%sbuilding %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
- build(pkg);
- if (is_verbose) printf("%sbuilt %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ printf("%sbuilding %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ build(pkg);
+ if (is_verbose)
+ printf("%sbuilt %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
- printf("%sinstalling %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
- bool install_success = false;
- if (!install_success && repo_install(pkg.url)) install_success = true;
- if (!install_success && bldit_install(pkg.target)) install_success = true;
- if (!install_success && config_install(pkg.src)) install_success = true;
- if (!install_success) {
- printf("%sno install function availible for package: %s\n",
- print_error, pkg.name);
- return;
- }
- //is_auto_installed = true;
- //if (is_auto_installed) {
- // if (is_symlink_install) {
- // link_install(pkg.src);
- // } else {
- // copy_install(pkg.src);
- // }
- //}
- printf("%sinstalled %s%s%s\n", print_success, green, pkg.name, color_reset);
+ printf("%sinstalling %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ bool install_success = false;
+ if (!install_success && repo_install(pkg.name))
+ install_success = true;
+ if (!install_success && bldit_install(pkg.target))
+ install_success = true;
+ if (!install_success && config_install(pkg.src))
+ install_success = true;
+ if (!install_success) {
+ printf("%sno install function availible for package: %s\n", print_error,
+ pkg.name);
+ return;
+ }
+ // is_auto_installed = true;
+ // if (is_auto_installed) {
+ // if (is_symlink_install) {
+ // link_install(pkg.src);
+ // } else {
+ // copy_install(pkg.src);
+ // }
+ // }
+ printf("%sinstalled %s%s%s\n", print_success, green, pkg.name, color_reset);
- bool repo_exists = false;
- for (size_t i = 0; i < cached_repos_count; i++) {
- char *repo_name = name_from_url(cached_repos[i].source_value);
- if (strcmp(repo_name, pkg.name) == 0) {
- repo_exists = true;
- }
- free(repo_name);
+ bool repo_exists = false;
+ for (size_t i = 0; i < cached_repos_count; i++) {
+ char *repo_name = name_from_url(cached_repos[i].source_value);
+ if (strcmp(repo_name, pkg.name) == 0) {
+ repo_exists = true;
}
+ free(repo_name);
+ }
- if (!repo_exists) {
- printf("%sadding %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
- if (pkg.url && strlen(pkg.url) > 0) {
- add_repo(pkg.url, pkg.name);
- }
- printf("%sadded %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
- } else {
- if (is_verbose) printf("%srepo already exists, done\n", print_pkgit);
+ if (!repo_exists) {
+ printf("%sadding %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ if (pkg.url && strlen(pkg.url) > 0) {
+ add_repo(pkg.url, pkg.name);
}
+ printf("%sadded %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ } else {
+ if (is_verbose)
+ printf("%srepo already exists, done\n", print_pkgit);
+ }
} \ No newline at end of file
diff --git a/src/lua_build.c b/src/lua_build.c
index f99a341..de82f83 100644
--- a/src/lua_build.c
+++ b/src/lua_build.c
@@ -6,22 +6,18 @@
#include "vars.h"
bool lua_build(const char *repository, const char *target, const char *path) {
- if (is_verbose) printf("%sattempting to use build function specified in 'repositories.%s'...\n",
- print_pkgit, repository);
+ if (is_verbose) printf(
+ "%sattempting to use build function specified in 'repositories.%s'...\n",
+ print_pkgit, repository
+ );
- if (repo_build(repository)) {
- return true;
- }
+ if (repo_build(repository)) { return true; }
if (is_verbose) printf("%sattempting to use build function specified in 'bldit.lua'...\n", print_pkgit);
- if (bldit(target)) {
- return true;
- }
+ if (bldit(target)) { return true; }
if (is_verbose) printf("%sattempting to use build functions specified in 'build_systems'...\n", print_pkgit);
- if (config_build(path)) {
- return true;
- }
+ if (config_build(path)) { return true; }
return false;
} \ No newline at end of file
diff --git a/src/lua_state.c b/src/lua_state.c
index 14a089a..62bd953 100644
--- a/src/lua_state.c
+++ b/src/lua_state.c
@@ -102,12 +102,12 @@ void install_dependencies(lua_State *L) {
lua_getfield(L, -1, "version");
const char *dep_version = lua_tostring(L, -1);
lua_pop(L, 1);
- const char* arg_version = strcat(strdup("@"), dep_version);
- const char* argument = strcat(strdup(dep_url), arg_version);
+ Pkg pkg = create_pkg(dep_url, "default");
+ pkg.ver = strdup(dep_version);
const int top = lua_gettop(L);
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
- install_pkg(create_pkg(argument, "default"));
+ install_pkg(pkg);
chdir(cwd);
}
lua_settop(L, top);
@@ -132,7 +132,10 @@ bool repo_build(const char *repository) {
lua_getfield(L, -1, "dependencies");
if (!lua_istable(L, -1)) {
- if (is_verbose) printf("%sbldit variable 'dependencies' is not a table.\n", print_warning);
+ if (is_verbose) printf(
+ "%s'repositories' variable 'dependencies' is not a table.\n",
+ print_warning
+ );
} else {
lua_pushnil(L);
install_dependencies(L);
@@ -141,15 +144,16 @@ bool repo_build(const char *repository) {
lua_getfield(L, -1, "build");
if (!lua_isfunction(L, -1)) {
- if (is_verbose) printf("%s'repositories' lua variable 'build' is not a function.\n",
- print_warning);
+ if (is_verbose) printf(
+ "%s'repositories' lua variable 'build' is not a function.\n",
+ print_warning
+ );
lua_pop(L, 3);
return false;
}
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
printf("%s'repositories' build failed: %s\n", print_warning, lua_tostring(L, -1));
- lua_pop(L, 1);
- lua_pop(L, 2);
+ lua_pop(L, 3);
return false;
}
@@ -182,7 +186,6 @@ bool repo_install(const char *repository) {
lua_getfield(L, -1, "install");
if (!lua_isfunction(L, -1)) {
if (is_verbose) printf("%s'repositories' lua variable 'install' is not a function.\n", print_warning);
- } else {
return false;
}
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
@@ -258,6 +261,7 @@ bool bldit(const char *target) {
lua_pushnil(B);
install_dependencies(B);
}
+ lua_pop(B, 1);
lua_getglobal(B, "targets");
if (!lua_istable(B, -1)) {
@@ -268,12 +272,21 @@ bool bldit(const char *target) {
lua_getfield(B, -1, target);
if (!lua_istable(B, -1)) {
- if (is_verbose) printf("%sbldit variable '%s' is not a table.\n", print_warning, target);
+ if (is_verbose) printf("%sbldit variable 'targets.%s' is not a table.\n", print_warning, target);
lua_pop(B, 2);
lua_close(B);
return false;
}
+ lua_getfield(B, -1, "dependencies");
+ if (!lua_istable(B, -1)) {
+ if (is_verbose) printf("%sbldit variable 'targets.%s.dependencies' is not a table.\n", target, print_warning);
+ } else {
+ lua_pushnil(B);
+ install_dependencies(B);
+ }
+ lua_pop(B, 1);
+
lua_getfield(B, -1, "build");
if (!lua_isfunction(B, -1)) {
if (is_verbose) printf("%s'repositories' lua variable 'build' is not a function.\n",
@@ -422,37 +435,6 @@ void cache_repos() {
const char *version = lua_tostring(L, -1);
repo->version = version ? strdup(version) : strdup("HEAD");
lua_pop(L, 1);
- lua_getfield(L, -1, "dependencies");
- if (!lua_istable(L, -1)) {
- lua_pop(L, 2);
- cached_repos_count++;
- continue;
- }
- lua_pushnil(L);
- while (lua_next(L, -2) != 0) {
- const char *depname = lua_tostring(L, -2);
- if (depname && lua_istable(L, -1)) {
- lua_getfield(L, -1, "url");
- const char *dep_url = lua_tostring(L, -1);
- lua_pop(L, 1);
- lua_getfield(L, -1, "version");
- const char *dep_version = lua_tostring(L, -1);
- lua_pop(L, 1);
- Dependency *dep = realloc(repo->dependencies,
- (repo->dep_count + 1) * sizeof(Dependency));
- if (dep) {
- repo->dependencies = dep;
- repo->dependencies[repo->dep_count].url =
- dep_url ? strdup(dep_url) : strdup("");
- repo->dependencies[repo->dep_count].version =
- dep_version ? strdup(dep_version) : strdup("");
- repo->dep_count++;
- }
- }
- lua_pop(L, 1);
- }
-
- lua_pop(L, 1);
lua_pop(L, 1);
cached_repos_count++;
}
diff --git a/src/main.c b/src/main.c
index 534e45c..3c98ba7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,6 +9,7 @@
int main(int argc, char *argv[]) {
init_vars();
setup_pkgit();
+ cache_repos();
cla_parse(argc, argv);
free_lua_state();
return 0;
diff --git a/src/name_from_url.c b/src/name_from_url.c
index 121fddd..0140e1a 100644
--- a/src/name_from_url.c
+++ b/src/name_from_url.c
@@ -6,17 +6,18 @@
char* name_from_url(const char *url) {
size_t len = strlen(url);
- const char *end = url + len;
- while (end > url && *(end-1) == '/') {
+ char* after_git = strdup(url);
+ const char *end = after_git + len;
+ while (end > after_git && *(end-1) == '/') {
end--;
}
const char *last_slash = end;
- while (last_slash > url && *(last_slash-1) != '/') {
+ while (last_slash > after_git && *(last_slash-1) != '/') {
last_slash--;
}
if (last_slash < end) {
return strndup(last_slash, end - last_slash);
} else {
- return strndup(url, end - url);
+ return strndup(after_git, end - after_git);
}
}
diff --git a/src/vars.c b/src/vars.c
index f3ebd70..d98c75f 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -48,7 +48,7 @@ const char* get_install_dir(const char *key) {
return "";
}
-const char *version = "0.1.0";
+const char *version = "0.1.1";
const char *red = "\e[0;31m";
const char *green = "\e[0;32m";
@@ -182,7 +182,7 @@ void init_vars() {
print_warning = print_warning_buf;
static char print_error_buf[256];
- snprintf(print_error_buf, sizeof(print_error_buf), "%s%s[ERROR]%s",
+ snprintf(print_error_buf, sizeof(print_error_buf), "%s%s[ERROR] %s",
print_pkgit, red, color_reset);
print_error = print_error_buf;
}