-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconfigure
executable file
·123 lines (108 loc) · 4.6 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
#! /usr/bin/env perl
use warnings;
use strict;
use version;
use File::Copy;
use Getopt::Long;
use lib 'tools/buildtools';
use ConfigUtil;
# version number
my $major = 0;
my $minor = 1;
my $micro = 0;
# project specified make variables
my %customs =
(
"TARGET" => "lightnet",
"ABBR" => "LN",
"abbr" => "ln",
"EXTRA_BINS" => "tools/il2json",
"EXPORT_HEADERS" => "src/ln_option.h src/ln_msg.h src/ln_util_common.h",
"BUILDTOOLS_DIR" => "tools/buildtools",
"SRC_DIR" => "src",
"SRC_SUB_DIRS" => "op op/auto arch arch/auto",
"SRC_EXTRA_CFLAGS" => '-I$(abspath $(BUILD_DIR))/include/$(TARGET)',
"SRC_REQUIRES" => "tensorlight >= 0.1.0",
"TEST_DIR" => "test",
"TEST_SUB_DIRS" => "",
"TEST_EXTRA_CFLAGS" => '-DLN_TEST_DIR="\"$(CURDIR)\"" -I$(abspath ../$(SRC_DIR))',
"TEST_REQUIRES" => 'check $(SRC_REQUIRES)'
);
# make variables that can be set by configure options
my @options =
(
# [ $opt_name, $var_name, $type, $default, $desc ]
[ "build-dir", "BUILD_DIR", "DIR", "build", "building directory" ],
[ "install-dir", "INSTALL_DIR", "DIR", "/usr/local", "installation directory" ],
[ "prefix", "INSTALL_DIR", "DIR", "/usr/local", "same as --install-dir; who comes later counts" ],
[ "pkgconfig-dir", "PKGCONFIG_DIR", "DIR", '$(INSTALL_DIR)/lib/pkgconfig', "pkgconfig directory" ],
[ "with-cuda", "WITH_CUDA", "BOOL", "no", "set to yes if build with CUDA"],
[ "cuda-install-dir", "CUDA_INSTALL_DIR", "DIR", "/usr/local/cuda", "cuda installation directory"],
[ "with-cudnn", "WITH_CUDNN", "BOOL", "no", "set to yes if build with cudnn library"],
[ "cudnn-install-dir", "CUDNN_INSTALL_DIR", "DIR", "/usr/local/cuda", "cudnn installation directory"],
[ "with-tensorrt", "WITH_TENSORRT", "BOOL", "no", "set to yes if build with TensorRT"],
[ "tensorrt-install-dir", "TENSORRT_INSTALL_DIR", "DIR", "/usr/local", "tensorrt installation directory"],
[ "with-dpu", "WITH_DPU", "BOOL", "no", "set to yes if build with DPU"],
[ "with-python", "WITH_PYTHON", "BOOL", "no", "set to yes if build with Python"],
[ "python-prefix", "PYTHON_PREFIX", "DIR", '$(INSTALL_DIR)', "Python package installation directory; set to your virtualenv directory if using virtualenv"],
[ "python-version", "PYTHON_VERSION", "VERSION", "3", "Python version"],
[ "python-cmd", "PYTHON_CMD", "CMD", "python3", "Python command"],
[ "python-user", "PYTHON_USER", "BOOL", "no", "install Python packages to user's site-package '\$HOME/.local/lib/python<version>/site-packages'" ],
[ "with-plugin", "WITH_PLUGIN", "BOOL", "yes", "set to yes if build with plugin support"],
[ "debug", "DEBUG", "BOOL", "no", "set to yes when debugging" ],
[ "doc", "DOC", "BOOL", "yes", "set to yes if build the documents too" ],
);
# parse configure options
my $options_obj = gen_options(\@options, "Generate configuration makefile for building $customs{TARGET}.");
GetOptions(%{$options_obj->{getopt_args}}) or die $options_obj->{format_usage};
my %opts = %{$options_obj->{options}};
print "configure $customs{TARGET} version $major.$minor.$micro\n";
# check configuration
common_checks(\%opts);
my $output;
$output = `pkg-config --modversion check`;
if (!defined $output or $output eq "") {
err_exit("check is not installed");
}
$output = `pkg-config --modversion tensorlight`;
if (!defined $output or $output eq "") {
err_exit("tensorlight is not installed");
}
sub mkdocs_version {
my $str = shift;
my $version = "";
$version = $1 if $str =~ /version (\d\.\d(\.\d)?)/;
$version;
}
if ($opts{DOC} eq "yes") {
$output = `mkdocs --version`;
if (!defined $output or $output eq "") {
warn_msg("mkdocs is is not installed; documents are not going to be built");
$opts{DOC} = "no";
} elsif (version->parse(mkdocs_version($output)) < version->parse("1.0.0")) {
my $version = mkdocs_version($output);
warn_msg("mkdocs requires mininal version 1.0.0, but get $version; documents are not going to be built");
$opts{DOC} = "no";
}
}
# print configuration
my $config_str = <<EOC;
.SUFFIXES:
MAJOR = $major
MINOR = $minor
MICRO = $micro
EOC
$config_str .= config_to_str(\%opts);
$config_str .= "\n";
set_extra_bins(\%customs);
set_module_files(\%customs, "SRC");
set_module_files(\%customs, "TEST");
$config_str .= config_to_str(\%customs);
my $conf_file = "config.mk";
if (-e $conf_file) {
copy($conf_file, "$conf_file.bak") or die "Cannot copy $conf_file: $!";
}
open my $conf_fh, '>', $conf_file or die "Cannot open $conf_file: $!";
print $conf_fh $config_str;
close $conf_fh;
print $config_str;