SET (_my_man_page_dir "${CMAKE_CURRENT_BINARY_DIR}/manpages")
SET (_my_man_page "${_my_man_page_dir}/fortune.6")
-SET (_my_man_gen "${CMAKE_CURRENT_SOURCE_DIR}/fortune/gen-fortune-man-page.pl")
+SET (_my_man_gen "${CMAKE_CURRENT_SOURCE_DIR}/fortune/process-fortune-man-template.pl")
SET (_my_args)
LIST(APPEND _my_args "--cookiedir" "${COOKIEDIR}" "--ocookiedir" "${OCOOKIEDIR}" "--output" "${_my_man_page}")
IF ("${NO_OFFENSIVE}")
LIST(APPEND _my_args "--without-offensive")
+ SET(_MY_IN "${CMAKE_CURRENT_SOURCE_DIR}/fortune/fortune_with_offensive.template.man")
+ELSE()
+ SET(_MY_IN "${CMAKE_CURRENT_SOURCE_DIR}/fortune/fortune_without_offensive.template.man")
ENDIF()
+LIST(APPEND _my_args "--input" "${_MY_IN}")
ADD_CUSTOM_COMMAND(
OUTPUT "${_my_man_page}"
COMMAND "${PERL_EXECUTABLE}"
ARGS "${_my_man_gen}" ${_my_args}
- DEPENDS "${_my_man_gen}"
+ DEPENDS "${_my_man_gen}" "${_MY_IN}"
)
SET (_my_man_pages_list)
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use autodie;
+
+use File::Basename qw / dirname /;
+use File::Path qw / mkpath /;
+use Getopt::Long qw/ GetOptions /;
+
+my $input_fn;
+my $output_fn;
+my $cookiedir;
+my $ocookiedir;
+my $no_offensive = 0;
+GetOptions(
+ '--cookiedir=s' => \$cookiedir,
+ '--ocookiedir=s' => \$ocookiedir,
+ '--without-offensive!' => \$no_offensive,
+ '--output=s' => \$output_fn,
+ '--input=s' => \$input_fn,
+) or die "Wrong options - $!";
+
+if ( !defined($input_fn) )
+{
+ die "Please specify --input";
+}
+if ( !defined($output_fn) )
+{
+ die "Please specify --output";
+}
+
+if ( !defined($cookiedir) )
+{
+ die "Please specify cookiedir";
+}
+
+my $OFF = ( !$no_offensive );
+
+if ( $OFF and !defined($ocookiedir) )
+{
+ die "Please specify ocookiedir";
+}
+
+my $dirname = dirname($output_fn);
+if ( $dirname and ( !-e $dirname ) )
+{
+ mkpath($dirname);
+}
+
+# The :raw is to prevent CRs on Win32/etc.
+open my $out, '>:encoding(utf-8)', $output_fn;
+my $text = _utf8_slurp($input_fn);
+
+sub _utf8_slurp
+{
+ my $filename = shift;
+
+ open my $in, '<:encoding(utf8)', $filename
+ or die "Cannot open '$filename' for slurping - $!";
+
+ local $/;
+ my $contents = <$in>;
+
+ close($in);
+
+ return $contents;
+}
+
+die if ( $text =~ s#\Q[[cookiedir_placeholder]]\E#${cookiedir}#gms ) > 1;
+die if ( $text =~ s#\Q[[ocookiedir_placeholder]]\E#${ocookiedir}#gms ) > 1;
+$out->print($text);
+close($out);