From f7d4ad2f7dd6bf64d13896d3409fde9b5437e374 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 26 Aug 2024 12:51:14 +0200 Subject: Added installation targets --- Makefile | 22 +++++++++++++++++++++- headers.lua | 11 ++--------- headers/db.lua | 25 +++++++++++++++++++++++++ headers/default_path.lua | 1 + 4 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 headers/db.lua create mode 100644 headers/default_path.lua diff --git a/Makefile b/Makefile index 28eceec..01478ad 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,26 @@ +LUA_VERSION=5.4 +DESTDIR= +PREFIX=/usr/local +PREFIX_EXEC=$(PREFIX) +BINDIR=$(PREFIX_EXEC)/bin +DATADIR=$(PREFIX)/share +LUA_LMOD=$(DATADIR)/lua/$(LUA_VERSION) +HEADERS_DB=$(DATADIR)/headers + all: test test: busted -.PHONY: all test +install: + install -m755 -DT headers.lua $(DESTDIR)$(BINDIR)/headers + install -m644 -Dt $(DESTDIR)$(LUA_LMOD)/headers headers/*.lua + install -m644 -Dt $(DESTDIR)$(HEADERS_DB) db/*.lua + sed -i 's|db/|$(HEADERS_DB)/|' $(DESTDIR)$(LUA_LMOD)/headers/default_path.lua + +uninstall: + rm -f $(DESTDIR)$(BINDIR)/headers + rm -rf $(DESTDIR)$(LUA_LMOD)/headers + rm -rf $(DESTDIR)$(HEADERS_DB) + +.PHONY: all test install uninstall diff --git a/headers.lua b/headers.lua index 290aca3..dc2c333 100755 --- a/headers.lua +++ b/headers.lua @@ -1,18 +1,11 @@ #!/usr/bin/env lua local args = require "pl.lapp" [[ Prints list of headers from a standard or available standards - -d (string default 'db/') Directory where definitions are placed + -d (optional string) Directory where definitions are placed (optional string) Standard to display the headers for ]] local dir = require "pl.dir" -local parser = require "headers.parser".new() -local definitions = dir.getfiles(args.d, "*.lua") -for _, filename in pairs(definitions) do - local handle = io.open(filename) - local data = handle:read("a") - handle:close() - parser:parse(data) -end +local parser = require "headers.db".parse_all(args.d) if #args.selection > 0 then local headers = parser:get_headers(args.selection) if not headers then diff --git a/headers/db.lua b/headers/db.lua new file mode 100644 index 0000000..1404608 --- /dev/null +++ b/headers/db.lua @@ -0,0 +1,25 @@ +local dir = require "pl.dir" +local default = require "headers.default_path" +local parser = require "headers.parser" +local db = {} + + +function db.path (override) + return override or os.getenv "HEADERS_DB_PATH" or default +end + + +function db.parse_all (override) + local parser = parser.new() + local definitions = dir.getfiles(db.path(override), "*.lua") -- Will grab anything and error out in +5 + for _, filename in pairs(definitions) do + local handle = io.open(filename) + local data = handle:read"a" + handle:close() + parser:parse(data) + end + return parser +end + + +return db diff --git a/headers/default_path.lua b/headers/default_path.lua new file mode 100644 index 0000000..bb1cb8a --- /dev/null +++ b/headers/default_path.lua @@ -0,0 +1 @@ +return "db/" -- cgit v1.1