Changeset 5094 for LMDZ6/branches/Amaury_dev/tools/fcm/bin/fcm_internal
- Timestamp:
- Jul 21, 2024, 1:47:00 PM (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
LMDZ6/branches/Amaury_dev/tools/fcm/bin/fcm_internal
r1578 r5094 1 #!/usr/bin/perl 2 # ------------------------------------------------------------------------------ 3 # NAME 4 # fcm_internal 5 # 6 # SYNOPSIS 7 # fcm_internal SUBCOMMAND ARGS 8 # 9 # DESCRIPTION 10 # The fcm_internal command is a frontend for some of the internal commands of 11 # the FCM build system. The subcommand can be "compile", "load" or "archive" 12 # for invoking the compiler, loader and library archiver respectively. If 13 # "compile" is specified, it can be suffixed with ":TYPE" to specify the 14 # nature of the source file. If TYPE is not specified, it is set to F by 15 # default (for Fortran source). For compile and load, the other arguments are 16 # the 1) name of the container package of the source file, 2) the path to the 17 # source file and 3) the target name after compiling or loading the source 18 # file. For compile, the 4th argument is a flag to indicate whether 19 # pre-processing is required for compiling the source file. For load, the 4th 20 # and the rest of the arguments is a list of object files that cannot be 21 # archived into the temporary load library and must be linked into the target 22 # through the linker command. (E.g. Fortran BLOCKDATA program units must be 23 # linked this way.) If archive is specified, the first argument should be the 24 # name of the library archive target and the rest should be the object files 25 # to be included in the archive. This command is invoked via the build system 26 # and should never be called directly by the user. 27 # 28 # COPYRIGHT 29 # (C) Crown copyright Met Office. All rights reserved. 30 # For further details please refer to the file COPYRIGHT.txt 31 # which you should have received as part of this distribution. 32 # ------------------------------------------------------------------------------ 33 34 # Standard pragmas: 1 #!/usr/bin/env perl 2 #------------------------------------------------------------------------------- 3 # Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. 4 # 5 # This file is part of FCM, tools for managing and building source code. 6 # 7 # FCM is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 3 of the License, or 10 # (at your option) any later version. 11 # 12 # FCM is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with FCM. If not, see <http://www.gnu.org/licenses/>. 19 #------------------------------------------------------------------------------- 20 21 use strict; 35 22 use warnings; 36 use strict; 37 38 # FCM component modules 39 use Fcm::Timer; 23 24 use FCM1::Timer qw{timestamp_command}; 40 25 41 26 # Function declarations … … 58 43 my $subcommand = shift @ARGV; 59 44 my ($function, $type) = split /:/, $subcommand; 45 60 46 my ($srcpackage, $src, $target, $requirepp, @objects, @blockdata); 61 47 62 if ($ subcommandeq 'archive') {48 if ($function eq 'archive') { 63 49 ($target, @objects) = @ARGV; 64 50 65 } elsif ($ subcommandeq 'load') {51 } elsif ($function eq 'load') { 66 52 ($srcpackage, $src, $target, @blockdata) = @ARGV; 67 53 … … 129 115 # *C_DEFINE - *C option to declare a pre-processor def 130 116 # *C_INCLUDE - *C option to declare an include directory 117 # *C_MODSEARCH- *C option to declare a module search directory 131 118 # *C_COMPILE - *C option to ask the compiler to perform compile only 132 119 # *CFLAGS - *C user options … … 146 133 my @command = (); 147 134 148 # Only support C and Fortran source files at the moment 149 my $type = $info->{TYPE}; 150 $type = ($info->{SRC} =~ /\.c(\w+)?$/i) ? 'C' : 'F' if not $type; 135 # Guess file type for backward compatibility 136 my $type = $info->{TYPE} ? $info->{TYPE} : &guess_file_type ($info->{SRC}); 151 137 152 138 # Compiler … … 169 155 push @command, (map {$incopt . $_} @incpath); 170 156 157 # Compiled module search path 158 my $modopt = &get_env ($type . 'C_MODSEARCH'); 159 if ($modopt) { 160 push @command, (map {$modopt . $_} @incpath); 161 } 162 171 163 # Other compiler flags 172 164 my $flags = &select_flags ($info, $type . 'FLAGS'); … … 227 219 # reference set up in MAIN. The following environment variables are used: 228 220 # 229 # LD - linker command221 # LD - * linker command 230 222 # LD_OUTPUT - LD option to specify the name of the output file 231 223 # LD_LIBSEARCH - LD option to declare a directory in the library search path … … 237 229 # FCM_BINDIR - destination directory of executable file 238 230 # FCM_TMPDIR - temporary destination directory of executable file 231 # 232 # * If LD is not set, it will attempt to guess the file type and use the 233 # compiler as the linker. 239 234 # ------------------------------------------------------------------------------ 240 235 … … 259 254 260 255 # Linker 261 push @command, &select_flags ($info, 'LD'); 256 my $ld = &select_flags ($info, 'LD'); 257 if (not $ld) { 258 # Guess file type for backward compatibility 259 my $type = $info->{TYPE} ? $info->{TYPE} : &guess_file_type ($info->{SRC}); 260 $ld = &get_env ($type . 'C', 1); 261 } 262 push @command, $ld; 262 263 263 264 # Linker output target (typical -o option) … … 280 281 my $full = catfile ($dir, $file); 281 282 282 if (- r$full) {283 if (-f $full) { 283 284 $file = $full; 284 285 last; … … 387 388 388 389 # Get registered objects into a hash (keys = objects, values = 1) 389 my %objects = map {($_, 1)} split (/\s+/, &get_env ('OBJECTS')); 390 391 my %objects = map {($_, 1)} split (/\s+/, &get_env ('OBJECTS', 1)); 390 392 391 393 # Seach object path for all files … … 404 406 } 405 407 406 for my $dir ( keys %objdir) {408 for my $dir (sort keys %objdir) { 407 409 next unless -d $dir; 408 410 … … 443 445 # ------------------------------------------------------------------------------ 444 446 # SYNOPSIS 447 # $type = &guess_file_type ($filename); 448 # 449 # DESCRIPTION 450 # This function attempts to guess the file type by looking at the extension 451 # of the $filename. Only C and Fortran at the moment. 452 # ------------------------------------------------------------------------------ 453 454 sub guess_file_type { 455 return (($_[0] =~ /\.c(\w+)?$/i) ? 'C' : 'F'); 456 } 457 458 # ------------------------------------------------------------------------------ 459 # SYNOPSIS 445 460 # $flags = &select_flags (\%info, $set); 446 461 # … … 454 469 my ($info, $set) = @_; 455 470 456 (my $srcroot = &basename ($info->{SRC})) =~ s/\.\S+$//;471 my $srcbase = &basename ($info->{SRC}); 457 472 my @names = ($set); 458 push @names, split (/__/, $info->{SRCPACKAGE} . '__' . $srcroot); 459 460 my $string = ''; 461 while (@names) { 462 my $name = join '__', @names; 463 my $var = &get_env ($name); 464 465 if (defined $var) { 466 $string = $var; 467 last; 468 469 } else { 470 pop @names; 471 } 473 push @names, split (/__/, $info->{SRCPACKAGE} . '__' . $srcbase); 474 475 my $string = ''; 476 for my $i (reverse (0 .. $#names)) { 477 my $var = &get_env (join ('__', (@names[0 .. $i]))); 478 479 $var = &get_env (join ('__', (@names[0 .. $i]))) 480 if (not defined ($var)) and $i and $names[-1] =~ s/\.[^\.]+$//; 481 482 next unless defined $var; 483 $string = $var; 484 last; 472 485 } 473 486 … … 580 593 581 594 __END__ 595 596 =head1 NAME 597 598 fcm_internal 599 600 =head1 SYNOPSIS 601 602 fcm_internal SUBCOMMAND ARGS 603 604 =head1 DESCRIPTION 605 606 The fcm_internal command is a frontend for some of the internal commands of 607 the FCM build system. The subcommand can be "compile", "load" or "archive" 608 for invoking the compiler, loader and library archiver respectively. If 609 "compile" or "load" is specified, it can be suffixed with ":TYPE" to 610 specify the nature of the source file. If TYPE is not specified, it is set 611 to C if the file extension begins with ".c". For all other file types, it 612 is set to F (for Fortran source). For compile and load, the other arguments 613 are 1) the name of the container package of the source file, 2) the path to 614 the source file and 3) the target name after compiling or loading the 615 source file. For compile, the 4th argument is a flag to indicate whether 616 pre-processing is required for compiling the source file. For load, the 617 4th and the rest of the arguments is a list of object files that cannot be 618 archived into the temporary load library and must be linked into the target 619 through the linker command. (E.g. Fortran BLOCKDATA program units must be 620 linked this way.) If archive is specified, the first argument should be the 621 name of the library archive target and the rest should be the object files 622 to be included in the archive. This command is invoked via the build system 623 and should never be called directly by the user. 624 625 =head1 COPYRIGHT 626 627 Copyright (C) 2006-2021 British Crown (Met Office) & Contributors. 628 629 =cut
Note: See TracChangeset
for help on using the changeset viewer.