Ignore:
Timestamp:
Jul 21, 2024, 1:47:00 PM (4 months ago)
Author:
abarral
Message:

Fix r5093: ship new fcm source

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
     21use strict;
    3522use warnings;
    36 use strict;
    37 
    38 # FCM component modules
    39 use Fcm::Timer;
     23
     24use FCM1::Timer qw{timestamp_command};
    4025
    4126# Function declarations
     
    5843  my $subcommand = shift @ARGV;
    5944  my ($function, $type) = split /:/, $subcommand;
     45
    6046  my ($srcpackage, $src, $target, $requirepp, @objects, @blockdata);
    6147 
    62   if ($subcommand eq 'archive') {
     48  if ($function eq 'archive') {
    6349    ($target, @objects) = @ARGV;
    6450
    65   } elsif ($subcommand eq 'load') {
     51  } elsif ($function eq 'load') {
    6652    ($srcpackage, $src, $target, @blockdata) = @ARGV;
    6753
     
    129115#   *C_DEFINE   - *C option to declare a pre-processor def
    130116#   *C_INCLUDE  - *C option to declare an include directory
     117#   *C_MODSEARCH- *C option to declare a module search directory
    131118#   *C_COMPILE  - *C option to ask the compiler to perform compile only
    132119#   *CFLAGS     - *C user options
     
    146133  my @command = ();
    147134
    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});
    151137
    152138  # Compiler
     
    169155  push @command, (map {$incopt . $_} @incpath);
    170156
     157  # Compiled module search path
     158  my $modopt  = &get_env ($type . 'C_MODSEARCH');
     159  if ($modopt) {
     160    push @command, (map {$modopt . $_} @incpath);
     161  }
     162
    171163  # Other compiler flags
    172164  my $flags = &select_flags ($info, $type . 'FLAGS');
     
    227219#   reference set up in MAIN. The following environment variables are used:
    228220#
    229 #   LD           - linker command
     221#   LD           - * linker command
    230222#   LD_OUTPUT    - LD option to specify the name of the output file
    231223#   LD_LIBSEARCH - LD option to declare a directory in the library search path
     
    237229#   FCM_BINDIR   - destination directory of executable file
    238230#   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.
    239234# ------------------------------------------------------------------------------
    240235
     
    259254
    260255    # 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;
    262263
    263264    # Linker output target (typical -o option)
     
    280281          my $full = catfile ($dir, $file);
    281282
    282           if (-r $full) {
     283          if (-f $full) {
    283284            $file = $full;
    284285            last;
     
    387388
    388389    # 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));
    390392
    391393    # Seach object path for all files
     
    404406  }
    405407
    406   for my $dir (keys %objdir) {
     408  for my $dir (sort keys %objdir) {
    407409    next unless -d $dir;
    408410
     
    443445# ------------------------------------------------------------------------------
    444446# 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
     454sub guess_file_type {
     455  return (($_[0] =~ /\.c(\w+)?$/i) ? 'C' : 'F');
     456}
     457
     458# ------------------------------------------------------------------------------
     459# SYNOPSIS
    445460#   $flags = &select_flags (\%info, $set);
    446461#
     
    454469  my ($info, $set) = @_;
    455470
    456   (my $srcroot = &basename ($info->{SRC})) =~ s/\.\S+$//;
     471  my $srcbase = &basename ($info->{SRC});
    457472  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;
    472485  }
    473486
     
    580593
    581594__END__
     595
     596=head1 NAME
     597
     598fcm_internal
     599
     600=head1 SYNOPSIS
     601
     602    fcm_internal SUBCOMMAND ARGS
     603
     604=head1 DESCRIPTION
     605
     606The fcm_internal command is a frontend for some of the internal commands of
     607the FCM build system. The subcommand can be "compile", "load" or "archive"
     608for invoking the compiler, loader and library archiver respectively. If
     609"compile" or "load" is specified, it can be suffixed with ":TYPE" to
     610specify the nature of the source file. If TYPE is not specified, it is set
     611to C if the file extension begins with ".c". For all other file types, it
     612is set to F (for Fortran source). For compile and load, the other arguments
     613are 1) the name of the container package of the source file, 2) the path to
     614the source file and 3) the target name after compiling or loading the
     615source file. For compile, the 4th argument is a flag to indicate whether
     616pre-processing is required for compiling the source file.  For load, the
     6174th and the rest of the arguments is a list of object files that cannot be
     618archived into the temporary load library and must be linked into the target
     619through the linker command. (E.g. Fortran BLOCKDATA program units must be
     620linked this way.) If archive is specified, the first argument should be the
     621name of the library archive target and the rest should be the object files
     622to be included in the archive. This command is invoked via the build system
     623and should never be called directly by the user.
     624
     625=head1 COPYRIGHT
     626
     627Copyright (C) 2006-2021 British Crown (Met Office) & Contributors.
     628
     629=cut
Note: See TracChangeset for help on using the changeset viewer.