1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
# Copyright (c) 1997-2024
# Ewgenij Gawrilow, Michael Joswig, and the polymake team
# Technische Universität Berlin, Germany
# https://polymake.org
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version: http://www.gnu.org/licenses/gpl.txt.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#-------------------------------------------------------------------------------
@conf_vars=qw( CXXFLAGS LDFLAGS LIBS );
sub allowed_options {
my ($allowed_options, $allowed_with)=@_;
@$allowed_with{ qw( singular ) }=();
}
sub usage {
print STDERR " --with-singular=PATH installation path of libsingular\n";
}
sub singular_config_approach {
my($singular_config) = @_;
my $singular_prefix;
my $lib_ext=$Config::Config{so};
chomp ($CXXFLAGS=`$singular_config --cflags`);
die "$singular_config failed: $!" if ($?);
# some of these additional libraries might be unnecessary
# but we keep them for backwards compatibility for now
chomp ($LDFLAGS=`$singular_config --libs`);
while ($LDFLAGS =~ s/(?: ^ | \s) -l\w+//x) {
$LIBS .= $&;
}
$LIBS .= " -lfactory -lsingular_resources -lpolys -lomalloc";
# yes we need it twice ...
chomp ($singular_prefix = `$singular_config --prefix`);
chomp $singular_prefix;
$LDFLAGS =~ s/-L(\S+)/-L$1 -Wl,-rpath,$1/g;
my $libdir = $1;
# newer versions of singular need -lsingular_resources while older ones needed -lresources
if (!-e "$libdir/libsingular_resources.${lib_ext}" and -e "$libdir/libresources.${lib_ext}") {
$LIBS =~ s/-lsingular_resources/-lresources/;
}
return $singular_prefix;
}
sub pkg_config_approach {
my ($pkg_config, $options) = @_;
my $pc_singular_prefix;
if (defined (my $singular_path=$options->{singular})) {
$pc_singular_prefix = Cwd::abs_path(`$pkg_config --variable=prefix Singular`);
chomp($pc_singular_prefix);
if ($pc_singular_prefix ne Cwd::abs_path($singular_path)) {
die "libsingular-config not found, using pkg-config with PKG_CONFIG_PATH.\nThe path provided for Singular is: $singular_path\nIt does not agree with the path from pkg-config: $pc_singular_prefix";
}
}
chomp ($CXXFLAGS=`$pkg_config --cflags Singular`);
die "$pkg_config failed: $!" if ($?);
chomp ($LDFLAGS=`$pkg_config --libs-only-other --libs-only-L Singular`);
if (defined ($options->{singular})){
$LDFLAGS =~ s/-L(\S+)/-L$1 -Wl,-rpath,$1/g;
}
chomp ($LIBS=`$pkg_config --libs-only-l Singular`);
return $pc_singular_prefix;
}
sub fail_gracefully {
my ($options)=@_;
my $errorString = "Tried to locate libsingular, but failed due to one of the following reasons:\n";
if(defined (my $singular_path=$options->{singular})){
$errorString .= " Could not find libsingular on path: $singular_path\n";
} else {
$errorString .= " No path for libsingular provided. Did you forget to provide it with --with-singular=PATH?\n";
}
if($pkg_config = Polymake::Configure::find_program_in_path("pkg-config")){
$errorString .= " pkg-config failed to locate package Singular.\n";
} else {
$errorString .= " pkg-config not installed.\n";
}
die $errorString."libsingular not found: neither via 'libsingular-config' nor 'pkg-config Singular'.";
}
sub build_singular_test {
return Polymake::Configure::build_test_program(<<"---", CXXFLAGS => $CXXFLAGS, LDFLAGS => $LDFLAGS, LIBS => $LIBS);
#include <dlfcn.h>
#include "Singular/libsingular.h"
#include <string>
#include <iostream>
int main() {
Dl_info dli;
if (!dladdr((void*)&siInit,&dli)) {
throw std::runtime_error("*** could not find symbol from libsingular ***");
}
char* cpath = omStrDup(dli.dli_fname);
siInit(cpath);
#ifdef HAVE_NTL
std::cout << "Version: " << VERSION << std::endl;
return 0;
#else
std::cout << "Your singular installation was not build with NTL support." << std::endl;
std::cout << "Please reconfigure and rebuild singular with --with-ntl=PATH." << std::endl;
return 1;
#endif
}
---
}
sub proceed {
my ($options)=@_;
my $pkg_config;
$ENV{PKG_CONFIG_PATH} .= ":$options->{singular}/lib/pkgconfig:$options->{singular}/lib64/pkgconfig" if $options->{singular};
my $singular_prefix;
my $singular_config;
my $singular_version;
if ((defined (my $singular_path=$options->{singular}))
and (-x "$options->{singular}/bin/libsingular-config")) {
# The user provided a path and libsingular-config is present.
$singular_config = "$singular_path/bin/libsingular-config";
$singular_prefix = singular_config_approach($singular_config);
} elsif ($pkg_config = Polymake::Configure::find_program_in_path("pkg-config")
and (`$pkg_config --exists Singular`, !$?)){
# We found pkg-config and pkg-config found Singular. If the user provided
# a path, it is verified inside the next method, whether it leads to the
# same Singular installation.
$singular_prefix = pkg_config_approach($pkg_config, $options);
} elsif ($singular_config = Polymake::Configure::find_program_in_path("libsingular-config")) {
# We found a Singular installation on the system that provides
# libsingular-config.
$singular_prefix = singular_config_approach($singular_config);
} else {
fail_gracefully($options);
}
if (defined $Polymake::Configure::GCCversion) {
$CXXFLAGS .= " -Wno-unused-value";
}
if (defined $Polymake::Configure::CLANGversion) {
$CXXFLAGS .= " -Wno-deprecated-register";
}
# remove old -std= versions from CXXFLAGS which would override our c++14
$CXXFLAGS =~ s/-std=(?:c|gnu)\+\+(?:11|0x|03)//g;
$LIBS .= " -ldl" unless $LIBS =~ /-ldl/ or $^O ne "linux";
my $error= build_singular_test();
if ($?==0) {
$error=Polymake::Configure::run_test_program();
if ($?) {
die "Could not run a test program checking for libsingular.\n",
"The complete error log follows:\n\n$error\n",
"Please investigate the reasons and fix the installation.\n";
} else {
chomp $error;
($singular_version) = $error =~ m/Version: ([\d.]+)/;
if (Polymake::Configure::v_cmp($singular_version,"4.0.1") < 0) {
die "Your libsingular version $singular_version is too old, at least 4.0.1 is required.\n";
}
}
} else {
die "Could not compile a test program checking for libsingular.\n",
"The most probable reasons are that the library is installed at a non-standard location,\n",
"is not configured to build a shared module, or missing at all.\n",
"The complete error log follows:\n\n$error\n",
"Please install the library and specify its location using --with-singular option, if needed.\n",
"Please remember to enable shared modules when configuring the libsingular!\n";
}
return "$singular_version @ ".($singular_prefix//"system");
}
|