diff options
Diffstat (limited to 'bldit.lua')
| -rw-r--r-- | bldit.lua | 103 |
1 files changed, 94 insertions, 9 deletions
@@ -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, } |
