Skip to content

Instantly share code, notes, and snippets.

@michaelpeternell
Last active August 29, 2015 14:02
Show Gist options
  • Save michaelpeternell/eec883bf2c2aefd7e709 to your computer and use it in GitHub Desktop.
Save michaelpeternell/eec883bf2c2aefd7e709 to your computer and use it in GitHub Desktop.
Dirty hotfix for broken GNU Cobol / Macports package
#!/usr/bin/perl
#by Michael Peternell
#Created: 2014-May-30
# this fixes the broken open-cobol package on macports on OSX 10.8+
# this is a dirty hack, use at your own risk.
# see also:
# https://sourceforge.net/p/open-cobol/discussion/help/thread/e1b4af35/
use strict;
use Cwd 'abs_path';
use File::Basename;
use File::Copy;
my $cobc_source = <<'EOT';
#!/usr/bin/perl
use strict;
use Cwd 'abs_path';
use File::Basename;
my $dir = abs_path(dirname $0);
my $fix_dir = $dir . "/fix_by_michi_cobol";
$ENV{"PATH"} = $fix_dir . ":" . $ENV{"PATH"};
exec(($fix_dir . "/cobc"), @ARGV);
EOT
my $cobcrun_source = <<'EOT';
#!/usr/bin/perl
use strict;
use Cwd 'abs_path';
use File::Basename;
my $dir = abs_path(dirname $0);
my $fix_dir = $dir . "/fix_by_michi_cobol";
$ENV{"PATH"} = $fix_dir . ":" . $ENV{"PATH"};
exec(($fix_dir . "/cobcrun"), @ARGV);
EOT
my $gcc_source = <<'EOT';
#!/usr/bin/perl
use strict;
use File::Basename;
my @filtered_args;
for my $arg (@ARGV)
{
push @filtered_args, $arg unless $arg =~ /^-R/;
}
exec "/usr/bin/gcc", @filtered_args;
EOT
sub file_put_contents
{
my $fn = shift;
my $contents = shift;
my $fd;
open $fd, ">", $fn or return 0;
print $fd $contents;
close $fd;
my $len = length $contents;
return "0 but true" unless $len;
return $len;
}
my $fix_dir = "/opt/local/bin/fix_by_michi_cobol";
if(-d $fix_dir)
{
print "Error: directory '$fix_dir' already exists!\n";
exit(1);
}
my $cobc_fn_1 = "/opt/local/bin/cobc";
my $cobcrun_fn_1 = "/opt/local/bin/cobcrun";
my $cobc_fn_2 = "/opt/local/bin/fix_by_michi_cobol/cobc";
my $cobcrun_fn_2 = "/opt/local/bin/fix_by_michi_cobol/cobcrun";
my $gcc_fn_2 = "/opt/local/bin/fix_by_michi_cobol/gcc";
#do it
mkdir $fix_dir;
move $cobc_fn_1, $cobc_fn_2;
move $cobcrun_fn_1, $cobcrun_fn_2;
file_put_contents($cobc_fn_1, $cobc_source);
file_put_contents($cobcrun_fn_1, $cobcrun_source);
file_put_contents($gcc_fn_2, $gcc_source);
chmod(0755, $cobc_fn_1, $cobcrun_fn_1, $gcc_fn_2);
@michaelpeternell
Copy link
Author

In the second revision of this gist I added two lines to the install script: use Cwd 'abs_path'; and use File::Basename;. These modules are not strictly needed for installing. But, if they are not available, one of the installed scripts will not work, breaking the cobol-package even more. So, it's a sanity check. If the two modules are not available, there is no point in installing this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment