Configuration file added.
parent
06cea3694e
commit
656a640738
4
Makefile
4
Makefile
|
@ -8,6 +8,7 @@ SHAREDIR := $(PREFIX)/share
|
|||
INCLUDEDIR := $(PREFIX)/include
|
||||
MANDIR := $(SHAREDIR)/man
|
||||
LIBEXECDIR := $(PREFIX)/libexec
|
||||
SYSCONFDIR := $(PREFIX)/etc
|
||||
VERSION := 0.3.0
|
||||
|
||||
CC := cc
|
||||
|
@ -54,7 +55,7 @@ assemble-apk.sh.uninstall:
|
|||
|
||||
src/config.cr: src/config.cr.in src
|
||||
@echo '[01;32m SED > [01;37msrc/config.cr[00m'
|
||||
$(Q)sed -e 's&@PREFIX@&$(PREFIX)&;s&@BINDIR@&$(BINDIR)&;s&@LIBDIR@&$(LIBDIR)&;s&@SHAREDIR@&$(SHAREDIR)&;s&@INCLUDEDIR@&$(INCLUDEDIR)&;s&@MANDIR@&$(MANDIR)&;s&@LIBEXECDIR@&$(LIBEXECDIR)&;s&@VERSION@&$(VERSION)&;' src/config.cr.in > 'src/config.cr'
|
||||
$(Q)sed -e 's&@PREFIX@&$(PREFIX)&;s&@BINDIR@&$(BINDIR)&;s&@LIBDIR@&$(LIBDIR)&;s&@SHAREDIR@&$(SHAREDIR)&;s&@INCLUDEDIR@&$(INCLUDEDIR)&;s&@MANDIR@&$(MANDIR)&;s&@LIBEXECDIR@&$(LIBEXECDIR)&;s&@SYSCONFDIR@&$(SYSCONFDIR)&;s&@VERSION@&$(VERSION)&;' src/config.cr.in > 'src/config.cr'
|
||||
$(Q)chmod +x 'src/config.cr'
|
||||
|
||||
|
||||
|
@ -183,6 +184,7 @@ help:
|
|||
@echo ' - [01;34mINCLUDEDIR [37m ${INCLUDEDIR}[00m'
|
||||
@echo ' - [01;34mMANDIR [37m ${MANDIR}[00m'
|
||||
@echo ' - [01;34mLIBEXECDIR [37m ${LIBEXECDIR}[00m'
|
||||
@echo ' - [01;34mSYSCONFDIR [37m ${SYSCONFDIR}[00m'
|
||||
@echo ' - [01;34mVERSION [37m ${VERSION}[00m'
|
||||
@echo ''
|
||||
@echo '[01;37mProject targets: [00m'
|
||||
|
|
|
@ -4,6 +4,7 @@ version=0.3.0
|
|||
|
||||
variables+=(
|
||||
LIBEXECDIR '$(PREFIX)/libexec'
|
||||
SYSCONFDIR '$(PREFIX)/etc'
|
||||
VERSION "$version"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
# These values are changed by `make` at build-time.
|
||||
OWN_LIBEXEC_DIR = "@LIBEXECDIR@/package"
|
||||
SYSCONF_DIR = "@SYSCONFDIR@"
|
||||
|
||||
module Package
|
||||
Version = "@VERSION@"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require "specfileparser"
|
||||
|
||||
require "./exception.cr"
|
||||
|
||||
require "./config.cr"
|
||||
|
@ -224,5 +226,21 @@ class Package::Context
|
|||
|
||||
read_recipe recipe_file_name if repo
|
||||
end
|
||||
|
||||
def read_configuration(filename : String)
|
||||
specs = SpecFileParser.parse(filename).not_nil!
|
||||
|
||||
specs.assignments.each do |key, value|
|
||||
puts key, value
|
||||
case key
|
||||
when "packages-directory"
|
||||
@packages_directory = value.as_s
|
||||
when "sources-directory"
|
||||
@sources_directory = value.as_s
|
||||
when "prefixes"
|
||||
@prefixes = value.as_a_or_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
15
src/main.cr
15
src/main.cr
|
@ -11,6 +11,9 @@ context = Context.new()
|
|||
context.packaging_backend = "apk"
|
||||
context.repositories << "."
|
||||
|
||||
configuration_file = "#{SYSCONF_DIR}/package.cfg"
|
||||
configuration_file_requested = false
|
||||
|
||||
requested_recipes = [] of String
|
||||
download_only = false
|
||||
do_not_clean = false
|
||||
|
@ -29,6 +32,11 @@ OptionParser.parse! do |parser|
|
|||
context.repositories << dir
|
||||
}
|
||||
|
||||
parser.on("-c FILE", "--conf FILE", "Use a configuration file other than the default one.") { |file|
|
||||
configuration_file = file
|
||||
configuration_file_requested = true
|
||||
}
|
||||
|
||||
parser.on("-D", "--download-only", "Only download sources, do not build.") {
|
||||
download_only = true
|
||||
}
|
||||
|
@ -58,6 +66,13 @@ OptionParser.parse! do |parser|
|
|||
end
|
||||
end
|
||||
|
||||
if File.exists? configuration_file
|
||||
context.read_configuration configuration_file
|
||||
elsif configuration_file_requested
|
||||
STDERR.puts "ERROR: configuration file '#{configuration_file}' does not exist"
|
||||
exit 1
|
||||
end
|
||||
|
||||
found_recipes = requested_recipes.map do |name|
|
||||
puts context.find_recipe(name)
|
||||
context.find_recipe(name) || name
|
||||
|
|
Reference in New Issue