--[[ pkgit - package it! Copyright (C) 2026 dacctal This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ]] local bldit = {} bldit.version = "2.0.0" bldit.package_version = bldit.version -- fetchers; entirely made by the developer -- local fetchers = {} fetchers.git = { get_source = function(url, version) return pkgit.run({ "git clone "..url.." --branch "..version }) end, get_version = function(url) return io.popen( "git -c 'versionsort.suffix=-' \ ls-remote --exit-code --refs --sort='version:refname' \ --tags "..url.." '*.*.*' \ | tail --lines=1 \ | cut --delimiter='/' --fields=3" ):read("*a") end, } -- fetchers; entirely made by the developer -- -- dependencies; completely optional -- bldit.dependencies = { luajit = { url = "https://luajit.org/git/luajit.git", version = "v2.1", fetcher = fetchers.git, recipe = bldit.recipe } } -- 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(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(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, 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, } return bldit