diff options
author | Aki <please@ignore.pl> | 2024-08-26 12:51:14 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-08-26 12:51:14 +0200 |
commit | f7d4ad2f7dd6bf64d13896d3409fde9b5437e374 (patch) | |
tree | 61f4de54bd0cb4b7fefdd31310222ee741b07181 | |
parent | 0778c66917daba1a0dc948eacdf86578ec4dd2be (diff) | |
download | headers-f7d4ad2f7dd6bf64d13896d3409fde9b5437e374.zip headers-f7d4ad2f7dd6bf64d13896d3409fde9b5437e374.tar.gz headers-f7d4ad2f7dd6bf64d13896d3409fde9b5437e374.tar.bz2 |
Added installation targets
-rw-r--r-- | Makefile | 22 | ||||
-rwxr-xr-x | headers.lua | 11 | ||||
-rw-r--r-- | headers/db.lua | 25 | ||||
-rw-r--r-- | headers/default_path.lua | 1 |
4 files changed, 49 insertions, 10 deletions
@@ -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 <selection...> (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/" |