Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   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
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
#							-*- Autotest -*-

AT_BANNER([Fortran low level compiling/preprocessing macros.])

# Copyright (C) 2000-2001, 2003, 2008-2012 Free Software Foundation,
# Inc.
#
# 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 3 of the License, or
# (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Since the macros which compile are required by most tests, check
# them first.  But remember that looking for a compiler is even more
# primitive, so check those first.


## --------------------- ##
## Fortran 77 Compiler.  ##
## --------------------- ##


AT_CHECK_MACRO([GNU Fortran 77],
[[AC_LANG(Fortran 77)
AC_LANG_COMPILER

: > conftest.f
if AC_TRY_COMMAND([$F77 --version | grep GNU >&2]) \
   || AC_TRY_COMMAND([$F77 -v -c conftest.f 2>&1 | grep "f2c " >&2]); then
  # Be sure to remove files which might be created by compilers that
  # don't support --version, or by the second compile.
  rm -f a.exe a.out conftest.f conftest.$ac_objext
  # Has GNU in --version.
  test "$G77" != yes &&
    AC_MSG_ERROR([failed to recognize GNU Fortran 77 compiler])
else
  # Be sure to remove files which might be created by compilers that
  # don't support --version, or by the second compile.
  rm -f a.exe a.out conftest.f conftest.$ac_objext
  # Has not.
  test "$G77" = yes &&
    AC_MSG_ERROR([incorrectly recognized a GNU Fortran 77 compiler])
fi
]])



## ------------------ ##
## Fortran Compiler.  ##
## ------------------ ##


AT_CHECK_MACRO([GNU Fortran],
[[AC_LANG(Fortran)
AC_LANG_COMPILER

# No Fortran compiler is known not to support "*.f".
AC_FC_SRCEXT([f])

# GNU Fortran is known to support freeform.
AC_FC_FREEFORM([],
               [AC_MSG_WARN([Fortran does not accept free-form source])])
if test "$ac_compiler_gnu" = yes; then
  case $FCFLAGS in
   *-ffree-form*) ;;
   *) AC_MSG_ERROR([failed to recognize GNU Fortran's -ffree-form option]);;
  esac
fi
]])


## ------------------------- ##
## AC_OPENMP and Fortran 77. ##
## ------------------------- ##

AT_SETUP([AC_OPENMP and Fortran 77])

AT_DATA([configure.ac],
[[AC_INIT
AC_PROG_F77
AC_LANG([Fortran 77])
AC_OPENMP
if test "X$ac_cv_prog_f77_openmp" = Xunsupported; then
  AS_EXIT([77])
fi
FFLAGS="$FFLAGS $OPENMP_FFLAGS"
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
]])

AT_DATA([Makefile.in],
[[foo@EXEEXT@: foo.@OBJEXT@
	@F77@ @FFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@

foo.@OBJEXT@: foo.f
	@F77@ @FFLAGS@ -c foo.f
]])

AT_DATA([foo.f],
[[       program main
      end
]])

: "${MAKE=make}"
AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
AT_CHECK_CONFIGURE
AT_CHECK([$MAKE], [], [ignore], [ignore])

AT_CLEANUP


## ---------------------- ##
## AC_OPENMP and Fortran. ##
## ---------------------- ##

AT_SETUP([AC_OPENMP and Fortran])

AT_DATA([configure.ac],
[[AC_INIT
AC_PROG_FC
AC_LANG([Fortran])
AC_OPENMP
if test "X$ac_cv_prog_fc_openmp" = Xunsupported; then
  AS_EXIT([77])
fi
FCFLAGS="$FCFLAGS $OPENMP_FCFLAGS"
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
]])

AT_DATA([Makefile.in],
[[foo@EXEEXT@: foo.@OBJEXT@
	@FC@ @FCFLAGS@ @LDFLAGS@ -o $@ foo.@OBJEXT@

foo.@OBJEXT@: foo.f
	@FC@ @FCFLAGS@ -c foo.f
]])

AT_DATA([foo.f],
[[      program main
      end
]])

: "${MAKE=make}"
AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
AT_CHECK_CONFIGURE
AT_CHECK([$MAKE], [], [ignore], [ignore])

AT_CLEANUP


# We don't test the AC_F77_LIBRARY_LDFLAGS macro on its own because of
# (autoconf.info)Fortran Compiler:
#      The macros `AC_F77_DUMMY_MAIN' and `AC_FC_DUMMY_MAIN' or
#    `AC_F77_MAIN' and `AC_FC_MAIN' are probably also necessary to link
#    C/C++ with Fortran; see below.
#
# and we would need libtool to create shared libraries.

# Further, for any sensible test of the AC_F{77,C}(_DUMMY)?_MAIN macros
# we also need to use AC_F{77,C}_WRAPPERS, in order to be able to actually
# call the functions.

## ------------------------ ##
## AC_F77_DUMMY_MAIN usage. ##
## ------------------------ ##

AT_SETUP([AC_F77_DUMMY_MAIN usage])

AT_CONFIGURE_AC([[
AC_PROG_F77
AC_F77_DUMMY_MAIN([], [AC_MSG_FAILURE([failed to determine F77 dummy main], [77])])
AC_F77_WRAPPERS
AC_PROG_CC
AC_CONFIG_FILES([Makefile])
]])

AT_DATA([Makefile.in],
[[
all: cprogram@EXEEXT@

cprogram@EXEEXT@: cprogram.@OBJEXT@ foobar.@OBJEXT@
	@CC@ @CFLAGS@ @LDFLAGS@ -o $@ cprogram.@OBJEXT@ foobar.@OBJEXT@ @LIBS@ @FLIBS@

.SUFFIXES: .c .f .@OBJEXT@
.f.@OBJEXT@:
	@F77@ @FFLAGS@ -c $<
.c.@OBJEXT@:
	@CC@ @DEFS@ -I. @CPPFLAGS@ @CFLAGS@ -c $<
]])

AT_DATA([foobar.f],
[[C     This is just a purely numeric routine, no I/O needed.
C     Taken from autoconf.texi:Fortran Compiler.
      subroutine foobar (x, y)
      double precision x, y
      y = 3.14159 * x
      return
      end
]])

AT_DATA([cprogram.c],
[[#include <config.h>
#include <math.h>

/* Taken from autoconf.texi:Fortran Compiler. */
#define FOOBAR_F77 F77_FUNC (foobar, FOOBAR)
#ifdef __cplusplus
extern "C"  /* prevent C++ name mangling */
#endif
void FOOBAR_F77 (double *x, double *y);

/* Taken from autoconf.texi:Fortran Compiler.  */
#ifdef F77_DUMMY_MAIN
#  ifdef __cplusplus
     extern "C"
#  endif
   int F77_DUMMY_MAIN () { return 1; }
#endif

int main(int argc, char *argv[])
{
  double x = 2.7183, y;
  FOOBAR_F77 (&x, &y);
  if (fabs (8.539784097 - y) > 1.e-6)
    return 1;
  return 0;
}
]])

AT_CHECK_AUTOCONF
AT_CHECK_AUTOHEADER
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])
dnl AT_CHECK([./cprogram])

AT_CLEANUP


## ----------------------- ##
## AC_FC_DUMMY_MAIN usage. ##
## ----------------------- ##

AT_SETUP([AC_FC_DUMMY_MAIN usage])

AT_CONFIGURE_AC([[
AC_PROG_FC
AC_FC_FIXEDFORM
AC_FC_DUMMY_MAIN([], [AC_MSG_FAILURE([failed to determine FC dummy main], [77])])
AC_FC_WRAPPERS
AC_PROG_CC
AC_CONFIG_FILES([Makefile])
]])

AT_DATA([Makefile.in],
[[
all: cprogram@EXEEXT@

cprogram@EXEEXT@: cprogram.@OBJEXT@ foobar.@OBJEXT@
	@CC@ @CFLAGS@ @LDFLAGS@ -o $@ cprogram.@OBJEXT@ foobar.@OBJEXT@ @LIBS@ @FCLIBS@

.SUFFIXES: .c .f .@OBJEXT@
.f.@OBJEXT@:
	@FC@ @FCFLAGS@ -c $<
.c.@OBJEXT@:
	@CC@ @DEFS@ -I. @CPPFLAGS@ @CFLAGS@ -c $<
]])

AT_DATA([foobar.f],
[[C     This is just a purely numeric routine, no I/O needed.
C     Taken from autoconf.texi:Fortran Compiler.
      subroutine foobar (x, y)
      double precision x, y
      y = 3.14159 * x
      return
      end
]])

AT_DATA([cprogram.c],
[[#include <config.h>
#include <math.h>

/* Taken from autoconf.texi:Fortran Compiler. */
#define FOOBAR_FC FC_FUNC (foobar, FOOBAR)
#ifdef __cplusplus
extern "C"  /* prevent C++ name mangling */
#endif
void FOOBAR_FC(double *x, double *y);

/* Taken from autoconf.texi:Fortran Compiler.  */
#ifdef FC_DUMMY_MAIN
#  ifdef __cplusplus
     extern "C"
#  endif
   int FC_DUMMY_MAIN () { return 1; }
#endif

int main (int argc, char *argv[])
{
  double x = 2.7183, y;
  FOOBAR_FC (&x, &y);
  if (fabs (8.539784097 - y) > 1.e-6)
    return 1;
  return 0;
}
]])

AT_CHECK_AUTOCONF
AT_CHECK_AUTOHEADER
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])
dnl AT_CHECK([./cprogram])

AT_CLEANUP


## ------------------ ##
## AC_F77_MAIN usage. ##
## ------------------ ##

AT_SETUP([AC_F77_MAIN usage])

AT_CONFIGURE_AC([[
AC_PROG_F77
AC_F77_MAIN
AC_F77_WRAPPERS
AC_PROG_CC
AC_CONFIG_FILES([Makefile])
]])

AT_DATA([Makefile.in],
[[
all: cprogram@EXEEXT@

cprogram@EXEEXT@: cprogram.@OBJEXT@ foobar.@OBJEXT@
	@CC@ @CFLAGS@ @LDFLAGS@ -o $@ cprogram.@OBJEXT@ foobar.@OBJEXT@ @LIBS@ @FLIBS@

.SUFFIXES: .c .f .@OBJEXT@
.f.@OBJEXT@:
	@F77@ @FFLAGS@ -c $<
.c.@OBJEXT@:
	@CC@ @DEFS@ -I. @CPPFLAGS@ @CFLAGS@ -c $<
]])

AT_DATA([foobar.f],
[[C     This uses Fortran I/O, so is likely to require Fortran startup.
      subroutine foobar (x)
      integer x
      if (x == 42) then
        write(*,*) 'some output from Fortran sources'
      end if
      end
]])

AT_DATA([cprogram.c],
[[#include <config.h>
#include <stdio.h>

/* Taken from autoconf.texi:Fortran Compiler. */
#define FOOBAR_F77 F77_FUNC (foobar, FOOBAR)
#ifdef __cplusplus
extern "C"  /* prevent C++ name mangling */
#endif
void FOOBAR_F77 (int *x);

/* Taken from autoconf.texi:Fortran Compiler.  */
#ifdef __cplusplus
  extern "C"
#endif
int F77_MAIN (int argc, char *argv[]);

int F77_MAIN (int argc, char *argv[])
{
  int x = 42;
  puts ("output from C main");
  fflush (stdout);
  FOOBAR_F77 (&x);
  puts ("more output from C main");
  return 0;
}
]])

AT_CHECK_AUTOCONF
AT_CHECK_AUTOHEADER
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])
dnl AT_CHECK([./cprogram], [], [output from C main
dnl  some output from Fortran sources
dnl more output from C main
dnl ])

AT_CLEANUP


## ----------------- ##
## AC_FC_MAIN usage. ##
## ----------------- ##

AT_SETUP([AC_FC_MAIN usage])

AT_CONFIGURE_AC([[
AC_PROG_FC
AC_FC_FIXEDFORM
AC_FC_MAIN
AC_FC_WRAPPERS
AC_PROG_CC
AC_CONFIG_FILES([Makefile])
]])

AT_DATA([Makefile.in],
[[all: cprogram@EXEEXT@

cprogram@EXEEXT@: cprogram.@OBJEXT@ foobar.@OBJEXT@
	@CC@ @CFLAGS@ @LDFLAGS@ -o $@ cprogram.@OBJEXT@ foobar.@OBJEXT@ @LIBS@ @FCLIBS@

.SUFFIXES: .c .f .@OBJEXT@
.f.@OBJEXT@:
	@FC@ @FCFLAGS@ -c $<
.c.@OBJEXT@:
	@CC@ @DEFS@ -I. @CPPFLAGS@ @CFLAGS@ -c $<
]])

AT_DATA([foobar.f],
[[C     This uses Fortran I/O, so is likely to require Fortran startup.
      subroutine foobar (x)
      integer x
      if (x == 42) then
        write (*,*) 'some output from Fortran sources'
      end if
      end
]])

AT_DATA([cprogram.c],
[[#include <config.h>
#include <stdio.h>

/* Taken from autoconf.texi:Fortran Compiler. */
#define FOOBAR_FC FC_FUNC (foobar, FOOBAR)
#ifdef __cplusplus
extern "C"  /* prevent C++ name mangling */
#endif
void FOOBAR_FC (int *x);

/* Taken from autoconf.texi:Fortran Compiler.  */
#ifdef __cplusplus
  extern "C"
#endif
int FC_MAIN (int argc, char *argv[]);

int FC_MAIN (int argc, char *argv[])
{
  int x = 42;
  puts ("output from C main");
  fflush (stdout);
  FOOBAR_FC (&x);
  puts ("more output from C main");
  return 0;
}
]])

AT_CHECK_AUTOCONF
AT_CHECK_AUTOHEADER
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])
dnl AT_CHECK([./cprogram], [], [output from C main
dnl  some output from Fortran sources
dnl more output from C main
dnl ])

AT_CLEANUP


## ------------------ ##
## AC_F77_FUNC usage. ##
## ------------------ ##

AT_SETUP([AC_F77_FUNC usage])

AT_CONFIGURE_AC([[
AC_PROG_F77
AC_F77_FUNC([foobar])
AC_SUBST([foobar])
AC_PROG_CC
AC_CONFIG_FILES([cprogram.c:cprogram.in])
AC_CONFIG_FILES([Makefile])
]])

AT_DATA([Makefile.in],
[[
all: cprogram@EXEEXT@

cprogram@EXEEXT@: cprogram.@OBJEXT@ foobar.@OBJEXT@
	@CC@ @CFLAGS@ @LDFLAGS@ -o $@ cprogram.@OBJEXT@ foobar.@OBJEXT@ @LIBS@ @FLIBS@

.SUFFIXES: .c .f .@OBJEXT@
.f.@OBJEXT@:
	@F77@ @FFLAGS@ -c $<
.c.@OBJEXT@:
	@CC@ @DEFS@ -I. @CPPFLAGS@ @CFLAGS@ -c $<
]])

AT_DATA([foobar.f],
[[      subroutine foobar (x)
      integer x
      x = 42
      return
      end
]])

AT_DATA([cprogram.in],
[[#include <config.h>
#include <math.h>

#ifdef __cplusplus
extern "C"  /* prevent C++ name mangling */
#endif
void @foobar@ (int *x);

/* Taken from autoconf.texi:Fortran Compiler.  */
#ifdef F77_DUMMY_MAIN
#  ifdef __cplusplus
     extern "C"
#  endif
   int F77_DUMMY_MAIN () { return 1; }
#endif

int main(int argc, char *argv[])
{
  int x;
  @foobar@ (&x);
  if (x != 42)
    return 1;
  return 0;
}
]])

AT_CHECK_AUTOCONF
AT_CHECK_AUTOHEADER
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])
dnl AT_CHECK([./cprogram])

AT_CLEANUP


## ----------------- ##
## AC_FC_FUNC usage. ##
## ----------------- ##

AT_SETUP([AC_FC_FUNC usage])

AT_CONFIGURE_AC([[
AC_PROG_FC
AC_FC_FUNC([foobar])
AC_SUBST([foobar])
AC_PROG_CC
AC_CONFIG_FILES([cprogram.c:cprogram.in])
AC_CONFIG_FILES([Makefile])
]])

AT_DATA([Makefile.in],
[[
all: cprogram@EXEEXT@

cprogram@EXEEXT@: cprogram.@OBJEXT@ foobar.@OBJEXT@
	@CC@ @CFLAGS@ @LDFLAGS@ -o $@ cprogram.@OBJEXT@ foobar.@OBJEXT@ @LIBS@ @FCLIBS@

.SUFFIXES: .c .f .@OBJEXT@
.f.@OBJEXT@:
	@FC@ @FCFLAGS@ -c $<
.c.@OBJEXT@:
	@CC@ @DEFS@ -I. @CPPFLAGS@ @CFLAGS@ -c $<
]])

AT_DATA([foobar.f],
[[      subroutine foobar (x)
      integer x
      x = 42
      return
      end
]])

AT_DATA([cprogram.in],
[[#include <config.h>
#include <math.h>

#ifdef __cplusplus
extern "C"  /* prevent C++ name mangling */
#endif
void @foobar@ (int *x);

/* Taken from autoconf.texi:Fortran Compiler.  */
#ifdef FC_DUMMY_MAIN
#  ifdef __cplusplus
     extern "C"
#  endif
   int FC_DUMMY_MAIN () { return 1; }
#endif

int main(int argc, char *argv[])
{
  int x;
  @foobar@ (&x);
  if (x != 42)
    return 1;
  return 0;
}
]])

AT_CHECK_AUTOCONF
AT_CHECK_AUTOHEADER
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])
dnl AT_CHECK([./cprogram])
AT_CLEANUP


## ------------------- ##
## AC_FC_SRCEXT usage. ##
## ------------------- ##

AT_SETUP([AC_FC_SRCEXT usage])

AT_DATA([configure.ac],
[[AC_INIT
AC_PROG_FC
FCFLAGS_NOFREE=$FCFLAGS
AC_SUBST([FCFLAGS_NOFREE])
AC_FC_FREEFORM
# Unconditionally require .f to work.
AC_FC_SRCEXT([f])
# For each other extension, fail gracefully if it does not work:
# Not all compilers support all extensions/language versions.
m4@&t@_foreach([ext], [f77, f90, f95, f03, f08],
  [AC_FC_SRCEXT(ext, ext[_object='foo]ext[.$(OBJEXT)'], ext[_object=])
   AC_SUBST(ext[_object])])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
]])

AT_DATA([Makefile.in],
[[OBJEXT = @OBJEXT@

all: prog@EXEEXT@
prog@EXEEXT@: foof.@OBJEXT@ @f77_object@ @f90_object@ \
	      @f95_object@ @f03_object@ @f08_object@
	@FC@ @FCFLAGS@ -o $@ foof.@OBJEXT@ @f77_object@ @f90_object@ \
			     @f95_object@ @f03_object@ @f08_object@

.SUFFIXES: .f .f77 .f90 .f95 .f03 .f08 .@OBJEXT@
.f.@OBJEXT@:
	@FC@ -c @FCFLAGS_NOFREE@ @FCFLAGS_f@ $<
.f77.@OBJEXT@:
	@FC@ -c @FCFLAGS_NOFREE@ @FCFLAGS_f77@ $<
.f90.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_f90@ $<
.f95.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_f95@ $<
.f03.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_f03@ $<
.f08.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_f08@ $<
]])

AT_DATA([foof.f],
[[      program main
      end
]])

AT_DATA([foof77.f77],
[[      subroutine foof77
      end
]])

AT_DATA([foof90.f90],
[[subroutine foof90
end
]])

AT_DATA([foof95.f95],
[[subroutine foof95
end
]])

AT_DATA([foof03.f03],
[[subroutine foof03
end
]])

AT_DATA([foof08.f08],
[[subroutine foof08
end
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])

AT_CLEANUP


## ---------------------- ##
## AC_FC_PP_SRCEXT usage. ##
## ---------------------- ##

AT_SETUP([AC_FC_PP_SRCEXT usage])

AT_DATA([configure.ac],
[[AC_INIT
AC_PROG_FC
# Unconditionally require .f and .F to work.
AC_FC_PP_SRCEXT([f])
AC_FC_PP_SRCEXT([F])
# For each other extension, fail gracefully if it does not work:
# Not all compilers support all extensions/language versions.
m4@&t@_foreach([ext], [f77, f90, f95, f03, f08],
  [AC_FC_PP_SRCEXT(ext, ext[_object='foo]ext[.$(OBJEXT)'], ext[_object=])
   AC_SUBST(ext[_object])])
m4@&t@_foreach([ext], [F77, F90, F95, F03, F08],
  [AC_FC_PP_SRCEXT(ext, ext[_object='bar]ext[.$(OBJEXT)'], ext[_object=])
   AC_SUBST(ext[_object])])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
]])

AT_DATA([Makefile.in],
[[OBJEXT = @OBJEXT@

all: prog@EXEEXT@
prog@EXEEXT@: foof.@OBJEXT@ @f77_object@ @f90_object@ \
	      @f95_object@ @f03_object@ @f08_object@ \
	      barF.@OBJEXT@ @F77_object@ @F90_object@ \
	      @F95_object@ @F03_object@ @F08_object@
	@FC@ @FCFLAGS@ -o $@ foof.@OBJEXT@ @f77_object@ @f90_object@ \
			     @f95_object@ @f03_object@ @f08_object@ \
			     barF.@OBJEXT@ @F77_object@ @F90_object@ \
			     @F95_object@ @F03_object@ @F08_object@

.SUFFIXES: .f .f77 .f90 .f95 .f03 .f08 .F .F77 .F90 .F95 .F03 .F08 .@OBJEXT@
.f.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_f@ $<
.f77.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_f77@ $<
.f90.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_f90@ $<
.f95.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_f95@ $<
.f03.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_f03@ $<
.f08.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_f08@ $<
.F.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_F@ $<
.F77.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_F77@ $<
.F90.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_F90@ $<
.F95.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_F95@ $<
.F03.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_F03@ $<
.F08.@OBJEXT@:
	@FC@ -c @FCFLAGS@ @FCFLAGS_F08@ $<
]])

for ext in f77 f90 f95 f03 f08; do
  cat > foo$ext.$ext <<EOF
      subroutine foo$ext
#if 0
this is not correct fortran
#endif
      end
EOF
done

for ext in F F77 F90 F95 F03 F08; do
  cat > bar$ext.$ext <<EOF
      subroutine bar$ext
#if 0
this is not correct fortran
#endif
      end
EOF
done

AT_DATA([foof.f],
[[      program main
#if 0
this is not correct fortran
#endif
      end
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])

AT_CLEANUP


## --------------- ##
## AC_FC_FREEFORM. ##
## --------------- ##

AT_SETUP([AC_FC_FREEFORM])

AT_DATA([configure.ac],
[[AC_INIT
AC_PROG_FC
AC_FC_FREEFORM
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
]])

AT_DATA([Makefile.in],
[[prog: prog.@OBJEXT@
	@FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@

.SUFFIXES: .f .@OBJEXT@
.f.@OBJEXT@:
	@FC@ @FCFLAGS@ -c $<
]])

AT_DATA([prog.f],
[[program main
end
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])
dnl AT_CHECK([./prog])

AT_CLEANUP


## --------------------------------- ##
## AC_FC_FREEFORM with AC_FC_SRCEXT. ##
## --------------------------------- ##

AT_SETUP([AC_FC_FREEFORM with AC_FC_SRCEXT])

AT_DATA([configure.ac],
[[AC_INIT
AC_FC_SRCEXT([f90], [], [AS_EXIT([77])])
AC_PROG_FC
AC_FC_FREEFORM
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
]])

AT_DATA([Makefile.in],
[[prog: prog.@OBJEXT@
	@FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@

.SUFFIXES: .f90 .@OBJEXT@
.f90.@OBJEXT@:
	@FC@ @FCFLAGS@ -c @FCFLAGS_f90@ $<
]])

AT_DATA([prog.f90],
[[program main
end
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])
dnl AT_CHECK([./prog])

AT_CLEANUP


## ---------------- ##
## AC_FC_FIXEDFORM. ##
## ---------------- ##

AT_SETUP([AC_FC_FIXEDFORM])

AT_DATA([configure.ac],
[[AC_INIT
AC_PROG_FC
AC_FC_FIXEDFORM
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
]])

AT_DATA([Makefile.in],
[[prog: prog.@OBJEXT@
	@FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@

.SUFFIXES: .f .@OBJEXT@
.f.@OBJEXT@:
	@FC@ @FCFLAGS@ -c $<
]])

AT_DATA([prog.f],
[[      program main
C      fixed-form style comment
       end
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])
dnl AT_CHECK([./prog])

AT_CLEANUP


## ---------------------------------- ##
## AC_FC_FIXEDFORM with AC_FC_SRCEXT. ##
## ---------------------------------- ##

AT_SETUP([AC_FC_FIXEDFORM with AC_FC_SRCEXT])

AT_DATA([configure.ac],
[[AC_INIT
AC_PROG_FC
AC_FC_SRCEXT([f90], [], [AS_EXIT([77])])
AC_FC_FIXEDFORM
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
]])

AT_DATA([Makefile.in],
[[prog: prog.@OBJEXT@
	@FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@

.SUFFIXES: .f90 .@OBJEXT@
.f90.@OBJEXT@:
	@FC@ @FCFLAGS@ -c @FCFLAGS_f90@ $<
]])

AT_DATA([prog.f90],
[[      program main
C      fixed-form style comment
       end
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])
dnl AT_CHECK([./prog])

AT_CLEANUP


## ------------------ ##
## AC_FC_LINE_LENGTH. ##
## ------------------ ##

AT_SETUP([AC_FC_LINE_LENGTH])

AT_DATA([Makefile.in],
[[prog@EXEEXT@: prog.@OBJEXT@
	@FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@

.SUFFIXES: .f .@OBJEXT@
.f.@OBJEXT@:
	@FC@ @FCFLAGS@ -c @FCFLAGS_f@ $<

clean:
	rm -f *.@OBJEXT@ prog@EEXEXT@
]])

line_80=\
'subroutine foo(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11)'
line_132=\
'subroutine foo(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,'\
'arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19)'
line_254=\
'subroutine foo(arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,'\
'arg12,arg13,arg14,arg15,arg16,arg17,arg18,arg19,arg20,arg21,arg22,arg23,'\
'arg24,arg25,arg26,arg27,arg28,arg29,arg30,arg31,arg32,arg33,arg34,arg35,'\
'arg36,arg37,arg38,arg39,arg40)'

for len in 80 132 254
do
  if test $len -eq 254; then arg=unlimited; else arg=$len; fi
  eval long_line=\$line_$len

  # Try free-form first, it has a bigger chance of succeeding.
  for fixed_or_free in FREEFORM FIXEDFORM
  do

    cat >configure.ac <<EOF
AC_INIT
AC_PROG_FC
AC_FC_SRCEXT([f])
AC_FC_$fixed_or_free
AC_FC_LINE_LENGTH([$arg])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
EOF

    cat >prog.f <<EOF
       $long_line
       end subroutine
       program main
       end program
EOF

    AT_CHECK_AUTOCONF
    AT_CHECK_CONFIGURE
    : "${MAKE=make}"
    AT_CHECK([$MAKE], [], [ignore], [ignore])
    dnl AT_CHECK([./prog])
    AT_CHECK([$MAKE clean], [], [ignore], [ignore])

  done
done

AT_CLEANUP


## ------------------- ##
## AC_FC_CHECK_BOUNDS. ##
## ------------------- ##

AT_SETUP([AC_FC_CHECK_BOUNDS])

AT_DATA([Makefile.in],
[[prog@EXEEXT@: prog.@OBJEXT@
	@FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@

.SUFFIXES: .f .@OBJEXT@
.f.@OBJEXT@:
	@FC@ @FCFLAGS@ -c @FCFLAGS_f@ $<

clean:
	rm -f *.@OBJEXT@ prog@EEXEXT@
]])

cat >configure.ac <<EOF
AC_INIT
AC_PROG_FC
AC_FC_SRCEXT([f])
AC_FC_CHECK_BOUNDS
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
EOF

AT_DATA([prog.f],
[[
      subroutine copy(a,b,n)
      integer a(:), b(:), n, i
      do i = 1, n
         a(i) = b(i)
      end do
      end subroutine

      program main
      integer, parameter :: n = 20
      integer a(1:n), b(1:n-1), i
      interface
         subroutine copy(a,b,n)
         integer a(:), b(:), i
         end subroutine
      end interface

      call copy(a,b,n)
      end program
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])
AT_CHECK([./prog || exit 1], [1], [ignore], [ignore])
AT_CHECK([$MAKE clean], [], [ignore], [ignore])

AT_CLEANUP


## ------------------ ##
## AC_FC_MODULE_FLAG. ##
## ------------------ ##

AT_SETUP([AC_FC_MODULE_FLAG])

AT_DATA([Makefile.in],
[[OBJEXT = @OBJEXT@
EXEEXT = @EXEEXT@
LIBS = @LIBS@
ac_empty = @ac_empty@
FC = @FC@
FC_MODEXT = @FC_MODEXT@
FC_MODINC = @FC_MODINC@
FCFLAGS = @FCFLAGS@
FCFLAGS_f = @FCFLAGS_f@

prog$(EXEEXT): sub/mod.$(OBJEXT) prog.$(OBJEXT)
	$(FC) $(FCFLAGS) -o $@ prog.$(OBJEXT) sub/mod.$(OBJEXT) $(LIBS)

sub/mod.$(OBJEXT): sub/mod.f
	cd sub && $(FC) $(FCFLAGS) -c $(FCFLAGS_f) mod.f

# Depend on the object, for the module dependency.
prog.$(OBJEXT): prog.f sub/mod.$(OBJEXT)
	$(FC) $(FCFLAGS) $(FC_MODINC). $(FC_MODINC)sub -c $(FCFLAGS_f) $<

clean:
	-test -z "$(FC_MODEXT)" || rm -f *.$(FC_MODEXT) sub/*.$(FC_MODEXT)
	-rm -f *.$(OBJEXT) sub/*.$(OBJEXT) prog$(EXEEXT)
]])

AT_DATA([configure.ac],
[[AC_INIT
AC_PROG_FC
AC_FC_SRCEXT([f])
AC_FC_MODULE_FLAG
if test -n "$FC_MODINC"; then
  FCFLAGS="$FCFLAGS $FC_MODINC. ${FC_MODINC}sub"
fi
AC_FC_MODULE_EXTENSION
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
]])

mkdir sub

AT_DATA([sub/mod.f],
[[      module foobar
      end module foobar
]])

AT_DATA([prog.f],
[[      program main
      use foobar
      end program
]])

AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [stdout], [stderr])
# Both the FCFLAGS setting from configure.ac, and the Makefile rule
# should add to the module search path.
AT_CHECK([grep 'sub .*sub ' stdout stderr], [], [ignore])
AT_CHECK([./prog], [], [ignore], [ignore])
AT_CHECK([$MAKE clean], [], [ignore], [ignore])

AT_CLEANUP