diff options
| author | dacctal <donotcontactmevia@email.invalid> | 2026-10-24 20:00:58 +0000 |
|---|---|---|
| committer | dacctal <donotcontactmevia@email.invalid> | 2026-10-24 20:00:58 +0000 |
| commit | 87e20545c6a04350196b26984d16533434671dab (patch) | |
| tree | 222b362d4b2590268aa1fac3406d0488daadf6da | |
| parent | c37341416b47bec24f32a49219b6f6259f641370 (diff) | |
MAKEFILE IS REDUNDANT
| -rw-r--r-- | .pkgit_status | 1 | ||||
| -rw-r--r-- | bldit.lua | 103 | ||||
| -rwxr-xr-x | make.lua | 20 | ||||
| -rw-r--r-- | src/lua_state.c | 3 | ||||
| -rw-r--r-- | src/recipes.c | 8 |
5 files changed, 118 insertions, 17 deletions
diff --git a/.pkgit_status b/.pkgit_status deleted file mode 100644 index a389a03..0000000 --- a/.pkgit_status +++ /dev/null @@ -1 +0,0 @@ -ffeee
\ No newline at end of file @@ -22,7 +22,7 @@ local bldit = {} bldit.version = "2.0.0" bldit.package_version = bldit.version --- fetchers, entirely made by the developer -- +-- fetchers; entirely made by the developer -- local fetchers = {} fetchers.git = { get_source = function(url, version) return pkgit.run({ @@ -36,28 +36,113 @@ fetchers.git = { | cut --delimiter='/' --fields=3" ):read("*a") end, } --- fetchers, entirely made by the developer -- +-- fetchers; entirely made by the developer -- --- dependencies, completely optional -- +-- dependencies; completely optional -- bldit.dependencies = { luajit = { url = "https://luajit.org/git/luajit.git", version = "v2.1", fetcher = fetchers.git, - recipe = recpies.make + recipe = bldit.recipe } } --- dependencies, completely optional -- +-- dependencies; completely optional -- + +bldit.opts = {} +if user == nil then + bldit.opts.prefix = os.getenv("HOME").."/.local" +else + bldit.opts.prefix = user.dirs.prefix +end +bldit.opts.CC = os.getenv("CC") +if bldit.opts.CC == nil then bldit.opts.CC = "cc" end +bldit.opts.LDFLAGS = os.getenv("LDFLAGS") +if bldit.opts.LDFLAGS == nil then bldit.opts.LDFLAGS = "" end +bldit.opts.CFLAGS = os.getenv("CFLAGS") +if bldit.opts.CFLAGS == nil then + bldit.opts.CFLAGS = "$(pkg-config --cflags luajit) -I./include " + .."-Wno-format-truncation -std=c99 -DVERSION='\"" + ..bldit.version.."\"'" +else bldit.opts.CFLAGS = bldit.opts.CFLAGS + .." $(pkg-config --cflags luajit) -I./include" + .." -Wno-format-truncation -std=c99 -DVERSION='\"" + ..bldit.version.."\"'" +end + +local function build_cmd() + return "mkdir -p obj \n" + .."for f in src/*.c; do \\\n" + .."echo \"\tCC\t$f\" \n" + ..bldit.opts.CC.." -c \"$f\" -o \"obj/$(basename \"${f%.c}\").o\" \\\n" + ..bldit.opts.CFLAGS.." || exit 1 \n" + .."done \n" + ..bldit.opts.CC.." "..bldit.opts.CFLAGS + .." $(pkg-config --libs luajit) " + ..bldit.opts.LDFLAGS.." obj/*.o -o pkgit" +end + +local install_cmd = "echo \"\tINSTALL\t\""..bldit.opts.prefix.."\n" + .."install -d " + ..bldit.opts.prefix.."/bin\n" + .."install -m 755 pkgit " + ..bldit.opts.prefix.."/bin/pkgit\n" + .."install -d " + ..bldit.opts.prefix.."/share/man/man1\n" + .."install -m 644 docs/pkgit.1 " + ..bldit.opts.prefix.."/share/man/man1/pkgit.1" + +local remove_cmd = "echo \"\tUNINSTALL\t\""..bldit.opts.prefix.."\n" + .."rm -f "..bldit.opts.prefix.."/bin/pkgit \n" + .."rm -f "..bldit.opts.prefix.."/share/man/man1/pkgit.1" bldit.recipe = { + clean = function() + print("\tCLEAN") + return os.execute("rm -rf obj && rm -f pkgit") + end, + build = function() - return os.execute("make") + return os.execute(build_cmd()) + end, + + gdb = function() + bldit.opts.CFLAGS = bldit.opts.CFLAGS + .." -g -O0 -Wall -Wextra -Werror -Wvla -pedantic" + return os.execute(build_cmd()) end, + + debug = function() + bldit.opts.CFLAGS = bldit.opts.CFLAGS + .." -g -O0 -Wall -Wextra -Werror -Wvla -pedantic -fsanitize=address" + bldit.opts.LDFLAGS = bldit.opts.LDFLAGS + .." -fsanitize=address" + return os.execute(build_cmd()) + end, + install = function() - return os.execute("make install PREFIX="..user.dirs.prefix) + return os.execute(install_cmd) + end, + + remove = function() + return os.execute(remove_cmd) + end, + + defconfig = function() + return os.execute("if [ \"$(id -u)\" -eq 0 ]; then \\\n" + .."dir=/etc/pkgit; else dir=\"$HOME/.config/pkgit\"; fi; \\\n" + .."echo \"installing default config to $dir ...\"; \\\n" + .."mkdir -p \"$dir/\"; \\\n" + .."cp -r ./config/* \"$dir/\"; \\\n" + .."echo 'default config installed'") end, - uninstall = function() - return os.execute("make uninstall PREFIX="..user.dirs.prefix) + + rmconfig = function() + return os.execute("if [ \"$(id -u)\" -eq 0 ]; then " + .."dir=/etc/pkgit; else dir=\"$HOME/.config/pkgit\"; fi; \\\n" + .."echo \"removing config from $dir ...\"; \\\n" + .."rm -rf \"$dir/\"; \\\n" + .."echo 'config successfully removed'") end, } diff --git a/make.lua b/make.lua new file mode 100755 index 0000000..4a7bbd7 --- /dev/null +++ b/make.lua @@ -0,0 +1,20 @@ +#!/usr/bin/env luajit +local bldit = require("bldit") +bldit.opts.prefix = os.getenv("PREFIX") +if bldit.opts.prefix == nil then + bldit.opts.prefix = os.getenv("HOME").."/.local" +end + +for i,a in ipairs(arg) do + if i >= 1 then + if bldit.recipe[a] == nil then + print("function '"..a.."' doesn't exist") + else + bldit.recipe[a]() + end + end +end + +if arg[1] == nil then + bldit.recipe.build() +end diff --git a/src/lua_state.c b/src/lua_state.c index cf46760..df4839f 100644 --- a/src/lua_state.c +++ b/src/lua_state.c @@ -18,8 +18,7 @@ static void lua_path_push(const char *new_path) { lua_getfield(L, -1, "path"); const char *current_path = lua_tostring(L, -1); - if (!current_path) - current_path = ""; + if (!current_path) current_path = ""; lua_pop(L, 1); lua_pushfstring(L, "%s;%s", current_path, new_path); diff --git a/src/recipes.c b/src/recipes.c index ae3adda..debfa62 100644 --- a/src/recipes.c +++ b/src/recipes.c @@ -162,14 +162,13 @@ bool pkg_build(package_t *pkg) { bool pkg_full_build(package_t *pkg) { if (flags.force) pkg_remove_status(pkg); if (!pkg_enter(pkg)) return false; - if (!pkg_setup(pkg)) return false; + pkg_setup(pkg); if (!pkg_build(pkg)) return false; return true; } bool pkg_install(package_t *pkg) { if (is_pkg_installed(pkg) && !flags.force) return true; - if (flags.force) pkg_remove_status(pkg); if (!pkg_enter(pkg)) return false; try_pkg_fn(pkg_hook_install, pkg, "install", 'i'); return true; @@ -177,10 +176,9 @@ bool pkg_install(package_t *pkg) { bool pkg_full_install(package_t *pkg) { if (is_pkg_installed(pkg) && !flags.force) return true; + if (flags.force) pkg_remove_status(pkg); try_pkg_fn(pkg_fetch_sources, pkg, "fetch", 'f'); - if (!pkg_enter(pkg)) return false; - if (!pkg_setup(pkg)) return false; - if (!pkg_build(pkg)) return false; + if (!pkg_full_build(pkg)) return false; if (!pkg_install(pkg)) return false; return true; } |
