forked from zhaozhixu/TensorLight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·125 lines (112 loc) · 3.33 KB
/
configure
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
#! /usr/bin/env perl
use warnings;
use strict;
use File::Copy;
use File::Path;
my $usage = <<EOF;
Usage: $0 [<option>[=<value>]...]
Generate configuration makefile for building TensorLight.
options:
-h, --help print this information
--target=<name> target name, default is tensorlight
--abbr=<abbr> abbreviation for target name, default is tl
--build-dir=<path> building directory, default is build
--install-dir=<path> installation directory, default is /usr/local
--pkgconfig-dir=<path> pkgconfig directory, default is
/usr/local/lib/pkgconfig
--with-cuda=<value> set to yes if build with CUDA, default is no
--cuda-install-dir=<path> cuda installation directory, default is
/usr/local/cuda
--debug=<value> set to yes when debugging, default is no
EOF
# default options
my %opts = (
"TARGET" => "tensorlight",
"ABBR" => "tl",
"BUILD_DIR" => "build",
"INSTALL_DIR" => "/usr/local",
"PKGCONFIG_DIR" => "/usr/local/lib/pkgconfig",
"WITH_CUDA" => "no",
"CUDA_INSTALL_DIR" => "/usr/local/cuda",
"DEBUG" => "no",
);
# parse arguments
while (@ARGV > 0) {
my $arg = shift @ARGV;
if ($arg eq "-h" or $arg eq "--help") {
print $usage;
exit;
}
if (not $arg =~ /^--(\S+)$/) {
&err_exit("wrong format in argument \"$arg\"");
}
my ($opt, $value) = split /=/, $1;
if (not defined $value or $value eq "") {
&err_exit("option \"$arg\" doesn't have a value");
}
$opt =~ s/(\S+)/\U$1/gi;
$opt =~ s/-/_/g;
if (not exists $opts{$opt}) {
&err_exit("invalid option \"$arg\"");
}
$opts{$opt} = $value;
}
# check configuration
# TODO: check versions
my $output;
$output = `gcc --version`;
if (!defined $output or $output eq "") {
&err_exit("gcc not installed");
}
$output = `make --version`;;
if (!defined $output or $output eq "") {
&err_exit("make not installed");
}
$output = `pkg-config --version`;;
if (!defined $output or $output eq "") {
&err_exit("pkg-config not installed");
}
$output = `pkg-config --modversion check`;;
if (!defined $output or $output eq "") {
&err_exit("check not installed");
}
if ($opts{WITH_CUDA} eq "yes") {
$output = `nvcc --version`;;
if (!defined $output or $output eq "") {
&err_exit("nvcc not installed");
}
}
# get current version
my ($major, $minor, $micro);
my $version_h = "src/tl_tensor.h";
open my $version_h_fh, '<', $version_h or die "Cannot open $version_h: $!";
while (<$version_h_fh>) {
$major = $1 if /MAJOR_VERSION \((\d)\)/;
$minor = $1 if /MINOR_VERSION \((\d)\)/;
$micro = $1 if /MICRO_VERSION \((\d)\)/;
}
close $version_h_fh;
if (not defined $major or not defined $minor or not defined $micro) {
&err_exit("cannot find version macros in $version_h, maybe a bug?");
}
# print configuration to config.mk
my $config_str = <<EOF;
.SUFFIXES:
MAJOR = $major
MINOR = $minor
MICRO = $micro
EOF
foreach my $key (sort keys %opts) {
$config_str .= "$key ?= $opts{$key}\n";
print "$key = $opts{$key}\n";
}
my $conf_file = "config.mk";
open my $conf_fh, '>', $conf_file or die "Cannot open $conf_file: $!";
print $conf_fh $config_str;
close $conf_fh;
# subroutines
sub err_exit {
my $msg = $_[0];
print STDERR "Error: $msg\n";
exit 1;
}