Skip to content

Instantly share code, notes, and snippets.

@dylanwh
Last active January 21, 2018 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanwh/c7e18dd44c5a7edaf38df6d196a8ad40 to your computer and use it in GitHub Desktop.
Save dylanwh/c7e18dd44c5a7edaf38df6d196a8ad40 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use 5.10.1;
use strict;
use warnings;
my @flags = qw(
-O0
-fcprop-registers -fdefer-pop -fguess-branch-probability -fif-conversion
-fif-conversion2 -finline -fipa-pure-const -fipa-reference
-fmerge-constants -fomit-frame-pointer -fsplit-wide-types
-ftoplevel-reorder -ftree-ccp -ftree-ch -ftree-copy-prop
-ftree-copyrename -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-fre
-ftree-sink -ftree-sra -ftree-ter
);
my $GCC_CMD = q{
gcc -c
-I/usr/local/lib64/perl5/auto/share/dist/Alien-libcmark_gfm/include
-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -pipe
-Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m64 -mtune=generic -DVERSION=\"0.280301\"
-DXS_VERSION=\"0.280301\" -fPIC "-I/usr/lib64/perl5/CORE" CommonMarkGFM.c
};
$GCC_CMD =~ s/\s+/ /gs;
sub gcc_cmd {
my (@add) = @_;
my $cmd = $GCC_CMD;
$cmd =~ s/-O2/@add/;
return $cmd;
}
my $done = 0;
while (not $done) {
my $gcc_rc = system(gcc_cmd(@flags) . " &>/dev/null");
my $make_rc = system("make install &>/dev/null");
die "failure\n" unless $gcc_rc == 0 && $make_rc == 0;
if (system('perl t/03_render.t') == 0) {
$done = 1;
warn "GOOD flags:\n\t@flags\n";
last;
}
else {
warn "BAD flags:\n\t@flags\n";
pop @flags;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment