Skip to content

Commit

Permalink
Makefile to build release archives
Browse files Browse the repository at this point in the history
  • Loading branch information
mstilkerich committed Sep 5, 2021
1 parent 2f485b1 commit 13fff62
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
testdir/
build/
releases/
.DS_Store
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ifndef MC_SYNTAX
ifneq ($(wildcard /usr/local/share/mc/syntax/Syntax),)
MC_SYNTAX=/usr/local/share/mc/syntax/Syntax
else ifneq ($(wildcard /usr/share/mc/syntax/Syntax),)
MC_SYNTAX=/usr/share/mc/syntax/Syntax
else
$(error Specify MC_SYNTAX to point to the location of the midnight commander syntax file)
endif
endif

RELEASE_VERSION ?= $(shell git tag --points-at HEAD)

# Example usage for non-HEAD version: RELEASE_VERSION=v4.1.0 make tarball
.PHONY: tarball
tarball:
@[ -n "$(RELEASE_VERSION)" ] || { echo "Error: HEAD has no version tag, and no version was set in RELEASE_VERSION"; exit 1; }
rm -rf build/syntax build/skins "releases/mc-solarized-truecolor-$(RELEASE_VERSION)"
mkdir -p "releases/mc-solarized-truecolor-$(RELEASE_VERSION)"
./makeskins.pl --syntaxfile "$(MC_SYNTAX)" --version "$(RELEASE_VERSION)"
mv build/syntax build/skins "releases/mc-solarized-truecolor-$(RELEASE_VERSION)/"
cd releases && zip -r "mc-solarized-truecolor-$(RELEASE_VERSION).zip" "mc-solarized-truecolor-$(RELEASE_VERSION)"
rm -rf "releases/mc-solarized-truecolor-$(RELEASE_VERSION)"
43 changes: 40 additions & 3 deletions makeskins.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Getopt::Long;
use File::Spec;
use File::Path 'make_path';

# Match expression for colors in solarized-template.ini
my $mcAccentColorMatch = qr/red|green|yellow|blue|magenta|cyan|orange|violet/;
Expand Down Expand Up @@ -268,19 +269,25 @@
my $syntaxFile;
my $printColors;
my $contrastLimit;
my $version;
GetOptions(
"syntaxfile=s" => \$syntaxFile,
"contrastlimit=f" => \$contrastLimit,
"printcolors" => \$printColors,
"version=s" => \$version,
) or die("Error in command line arguments\n");

$version //= `git rev-parse HEAD`;
chomp $version;

# Read the template
open(my $TEMPLATEH, '<solarized-template.ini') or die "could not open solarized-template.ini: $!";
my @tmplSkin = <$TEMPLATEH>;
close($TEMPLATEH);

# Open all output files
openOutFiles('solarized-');
-d 'build/skins' or make_path('build/skins') or die 'could not create directory build/skins';
openOutFiles('build/skins/solarized-');

my $section = undef;
my %printToTerm = ();
Expand Down Expand Up @@ -347,6 +354,8 @@
$printToTerm{$variant}{$colorCombo}{$colortype} = [ $fgColor, $bgColor, $reverse, $mcSetting ];
}
}
} elsif ($section eq 'skin' && $line =~ /^\s*description\s*=/) {
printInfoLine(\%variants, $line);
} else {
die "No match [$section]: $line" if $section =~ /$mcColorSectMatch/;
printOutLines(\%variants, $line);
Expand Down Expand Up @@ -414,9 +423,17 @@ sub mapSyntaxFiles {

$synBaseDir = '.' unless $synBaseDir ne '';

-d 'syntax' or mkdir('syntax') or die 'could not create directory syntax: $!';
-d 'build/syntax' or mkdir('build/syntax') or die 'could not create directory build/syntax: $!';
# open out files
openOutFiles('syntax/');
openOutFiles('build/syntax/');

# print Info Line
printInfoLine(
\%variants,
"# Adapted syntax definitions for solarized \$VARIANT skin (\$COLORTYPE, Version \$VERSION)\n",
"# See https://github.com/mstilkerich/mc-solarized-truecolor\n",
"\n",
);

# process lines
my @context; # ( foreground, background ) of current context, undefined outside context
Expand Down Expand Up @@ -557,6 +574,26 @@ sub printOutLines {
}
}

# Prints an info line to all open variant ini files; openOutFiles() must be called first
# In the info line, the placeholders $VERSION, $VARIANT and $COLORTYPE are replaced
sub printInfoLine {
my $variants = shift;

while (my ($variant, $variantdef) = each (%variants)) {
while (my ($colortype, $colordef) = each (%{$variantdef->{'colors'}})) {
foreach my $line (@_) {
my $l = $line;
$l =~ s/\$VERSION/$version/g;
$l =~ s/\$VARIANT/$variant/g;
$l =~ s/\$COLORTYPE/$colortype/g;

my $fh = $colordef->{'fh'};
print $fh $l;
}
}
}
}

# closes all open variant ini files
sub closeOutFiles {
while (my ($variant, $variantdef) = each (%variants)) {
Expand Down
2 changes: 1 addition & 1 deletion solarized-template.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[skin]
description = Solarized skin for Midnight Commander.
description = Solarized $VARIANT skin for Midnight Commander ($COLORTYPE, Version $VERSION)
terminal_default_color = fg;bg

# Color usage
Expand Down

0 comments on commit 13fff62

Please sign in to comment.