Permalink
Browse files

Use xxdi.pl script if vim-common’s xxd is not available

  • Loading branch information...
milot-mirdita committed Nov 2, 2017
1 parent 7d26617 commit 4dda4db3730e043aeb894b030a3846e7abb3a5f2
Showing with 61 additions and 2 deletions.
  1. +11 −2 cmake/MMseqsResourceCompiler.cmake
  2. +50 −0 cmake/xxdi.pl
@@ -1,6 +1,15 @@
find_program(XXD_EXECUTABLE xxd)
if(NOT XXD_EXECUTABLE)
message(FATAL_ERROR "xxd not found in path. It is usually contained in your distributions vim-common package!")
find_program(PERL_EXECUTABLE perl)
if(NOT PERL_EXECUTABLE)
message(FATAL_ERROR "Neither xxd nor perl found in PATH. xxd is usually contained in your distributions vim-common package!")
else()
message("-- xxd not found, using xxdi.pl instead")
set(XXD_EXECUTABLE "${CMAKE_MODULE_PATH}/xxdi.pl")
set(XXD_PARAMS "")
endif()
else()
set(XXD_PARAMS -i)
endif()
find_program(SED_EXECUTABLE sed)
@@ -13,7 +22,7 @@ function(compile_resource INPUT_FILE OUTPUT_FILE)
set(OUTPUT_FILE ${PROJECT_BINARY_DIR}/generated/${INPUT_FILE_NAME}.h PARENT_SCOPE)
add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/generated/${INPUT_FILE_NAME}.h
COMMAND mkdir -p ${PROJECT_BINARY_DIR}/generated
COMMAND ${XXD_EXECUTABLE} -i ${INPUT_FILE} ${PROJECT_BINARY_DIR}/generated/${INPUT_FILE_NAME}.h
COMMAND ${XXD_EXECUTABLE} ${XXD_PARAMS} ${INPUT_FILE} > ${PROJECT_BINARY_DIR}/generated/${INPUT_FILE_NAME}.h
COMMAND ${SED_EXECUTABLE} 's!unsigned char!static const unsigned char!' < ${PROJECT_BINARY_DIR}/generated/${INPUT_FILE_NAME}.h > ${PROJECT_BINARY_DIR}/generated/${INPUT_FILE_NAME}.h.tmp
COMMAND mv -f ${PROJECT_BINARY_DIR}/generated/${INPUT_FILE_NAME}.h.tmp ${PROJECT_BINARY_DIR}/generated/${INPUT_FILE_NAME}.h
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/data/
View
@@ -0,0 +1,50 @@
#!/usr/bin/env perl
#
# xxdi.pl - perl implementation of 'xxd -i' mode
#
# Copyright 2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
# Copyright 2013 Linux Foundation
#
# Released under the GPLv2.
#
# Implements the "basic" functionality of 'xxd -i' in perl to keep build
# systems from having to build/install/rely on vim-core, which not all
# distros want to do. But everyone has perl, so use it instead.
#
use strict;
use warnings;
use File::Slurp qw(slurp);
my $indata = slurp(@ARGV ? $ARGV[0] : \*STDIN);
my $len_data = length($indata);
my $num_digits_per_line = 12;
my $var_name;
my $outdata;
# Use the variable name of the file we read from, converting '/' and '.
# to '_', or, if this is stdin, just use "stdin" as the name.
if (@ARGV) {
$var_name = $ARGV[0];
$var_name =~ s/\//_/g;
$var_name =~ s/\./_/g;
} else {
$var_name = "stdin";
}
$outdata .= "unsigned char $var_name\[] = {";
# trailing ',' is acceptable, so instead of duplicating the logic for
# just the last character, live with the extra ','.
for (my $key= 0; $key < $len_data; $key++) {
if ($key % $num_digits_per_line == 0) {
$outdata .= "\n\t";
}
$outdata .= sprintf("0x%.2x, ", ord(substr($indata, $key, 1)));
}
$outdata .= "\n};\nunsigned int $var_name\_len = $len_data;\n";
binmode STDOUT;
print {*STDOUT} $outdata;

0 comments on commit 4dda4db

Please sign in to comment.