File: buildsystem.html

package info (click to toggle)
petsc 3.23.1%2Bdfsg1-1exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 515,576 kB
  • sloc: ansic: 751,607; cpp: 51,542; python: 38,598; f90: 17,352; javascript: 3,493; makefile: 3,157; sh: 1,502; xml: 619; objc: 445; java: 13; csh: 1
file content (1020 lines) | stat: -rw-r--r-- 67,704 bytes parent folder | download
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

<!DOCTYPE html>


<html lang="en" data-content_root="../" >

  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>BuildSystem &#8212; PETSc 3.23.1 documentation</title>
  
  
  
  <script data-cfasync="false">
    document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
    document.documentElement.dataset.theme = localStorage.getItem("theme") || "light";
  </script>
  
  <!-- Loaded before other Sphinx assets -->
  <link href="../_static/styles/theme.css?digest=bd9e20870c6007c4c509" rel="stylesheet" />
<link href="../_static/styles/bootstrap.css?digest=bd9e20870c6007c4c509" rel="stylesheet" />
<link href="../_static/styles/pydata-sphinx-theme.css?digest=bd9e20870c6007c4c509" rel="stylesheet" />

  
  <link href="../_static/vendor/fontawesome/6.5.1/css/all.min.css?digest=bd9e20870c6007c4c509" rel="stylesheet" />
  <link rel="preload" as="font" type="font/woff2" crossorigin href="../_static/vendor/fontawesome/6.5.1/webfonts/fa-solid-900.woff2" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="../_static/vendor/fontawesome/6.5.1/webfonts/fa-brands-400.woff2" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="../_static/vendor/fontawesome/6.5.1/webfonts/fa-regular-400.woff2" />

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=8f2a1f02" />
    <link rel="stylesheet" type="text/css" href="../_static/copybutton.css?v=76b2166b" />
    <link rel="stylesheet" type="text/css" href="../_static/sphinx-design.min.css?v=87e54e7c" />
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/katex@0.16.10/dist/katex.min.css" />
    <link rel="stylesheet" type="text/css" href="../_static/katex-math.css?v=91adb8b6" />
    <link rel="stylesheet" type="text/css" href="../_static/css/custom.css?v=dbe1606d" />
  
  <!-- Pre-loaded scripts that we'll load fully later -->
  <link rel="preload" as="script" href="../_static/scripts/bootstrap.js?digest=bd9e20870c6007c4c509" />
<link rel="preload" as="script" href="../_static/scripts/pydata-sphinx-theme.js?digest=bd9e20870c6007c4c509" />
  <script src="../_static/vendor/fontawesome/6.5.1/js/all.min.js?digest=bd9e20870c6007c4c509"></script>

    <script src="../_static/documentation_options.js?v=34da53a5"></script>
    <script src="../_static/doctools.js?v=9a2dae69"></script>
    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../_static/clipboard.min.js?v=a7894cd8"></script>
    <script src="../_static/copybutton.js?v=a56c686a"></script>
    <script src="../_static/design-tabs.js?v=f930bc37"></script>
    <script src="../_static/katex.min.js?v=be8ff15f"></script>
    <script src="../_static/auto-render.min.js?v=ad136472"></script>
    <script src="../_static/katex_autorenderer.js?v=bebc588a"></script>
    <script>DOCUMENTATION_OPTIONS.pagename = 'developers/buildsystem';</script>
    <link rel="icon" href="../_static/petsc_favicon.png"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="PETSc Testing System" href="testing.html" />
    <link rel="prev" title="PETSc Style and Usage Guide" href="style.html" />
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <meta name="docsearch:language" content="en"/>
    <meta name="docbuild:last-update" content="2025-04-30T13:10:40-0500 (v3.23.1)"/>
  </head>
  
  
  <body data-bs-spy="scroll" data-bs-target=".bd-toc-nav" data-offset="180" data-bs-root-margin="0px 0px -60%" data-default-mode="">

  
  
  <a id="pst-skip-link" class="skip-link" href="#main-content">Skip to main content</a>
  
  <div id="pst-scroll-pixel-helper"></div>

  
  <button type="button" class="btn rounded-pill" id="pst-back-to-top">
    <i class="fa-solid fa-arrow-up"></i>
    Back to top
  </button>

  
  <input type="checkbox"
          class="sidebar-toggle"
          name="__primary"
          id="__primary"/>
  <label class="overlay overlay-primary" for="__primary"></label>
  
  <input type="checkbox"
          class="sidebar-toggle"
          name="__secondary"
          id="__secondary"/>
  <label class="overlay overlay-secondary" for="__secondary"></label>
  
  <div class="search-button__wrapper">
    <div class="search-button__overlay"></div>
    <div class="search-button__search-container">
<form class="bd-search d-flex align-items-center"
      action="../search.html"
      method="get">
  <i class="fa-solid fa-magnifying-glass"></i>
  <input type="search"
         class="form-control"
         name="q"
         id="search-input"
         placeholder="Search the docs ..."
         aria-label="Search the docs ..."
         autocomplete="off"
         autocorrect="off"
         autocapitalize="off"
         spellcheck="false"/>
  <span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd></span>
</form></div>
  </div>

  <header>
  
    <div class="bd-header navbar navbar-expand-lg bd-navbar">
<div class="bd-header__inner bd-page-width">
  <label class="sidebar-toggle primary-toggle" for="__primary">
    <span class="fa-solid fa-bars"></span>
  </label>
  
  
  <div class="col-lg-3 navbar-header-items__start">
    
      <div class="navbar-item">

  

<a class="navbar-brand logo" href="../index.html">
  
  
  
  
  
    
    
      
    
    
    <img src="../_static/PETSc-TAO_RGB.svg" class="logo__image only-light" alt="PETSc 3.23.1 documentation - Home"/>
    <script>document.write(`<img src="../_static/PETSc-TAO_RGB_white.svg" class="logo__image only-dark" alt="PETSc 3.23.1 documentation - Home"/>`);</script>
  
  
</a></div>
    
  </div>
  
  <div class="col-lg-9 navbar-header-items">
    
    <div class="me-auto navbar-header-items__center">
      
        <div class="navbar-item">
<nav class="navbar-nav">
  <ul class="bd-navbar-elements navbar-nav">
    
                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../overview/index.html">
                        Overview
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../install/index.html">
                        Install
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../tutorials/index.html">
                        Tutorials
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../manual/index.html">
                        User-Guide
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../manualpages/index.html">
                        C/Fortran API
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../petsc4py/index.html">
                        petsc4py API
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../faq/index.html">
                        FAQ
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../community/index.html">
                        Community
                      </a>
                    </li>
                

                    <li class="nav-item current active">
                      <a class="nav-link nav-internal" href="index.html">
                        Developers
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../miscellaneous/index.html">
                        Misc.
                      </a>
                    </li>
                
  </ul>
</nav></div>
      
    </div>
    
    
    <div class="navbar-header-items__end">
      
        <div class="navbar-item navbar-persistent--container">
          

 <script>
 document.write(`
   <button class="btn navbar-btn search-button-field search-button__button" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
    <i class="fa-solid fa-magnifying-glass"></i>
    <span class="search-button__default-text">Search</span>
    <span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd class="kbd-shortcut__modifier">K</kbd></span>
   </button>
 `);
 </script>
        </div>
      
      
        <div class="navbar-item">

<script>
document.write(`
  <button class="btn btn-sm navbar-btn theme-switch-button" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip">
    <span class="theme-switch nav-link" data-mode="light"><i class="fa-solid fa-sun fa-lg"></i></span>
    <span class="theme-switch nav-link" data-mode="dark"><i class="fa-solid fa-moon fa-lg"></i></span>
    <span class="theme-switch nav-link" data-mode="auto"><i class="fa-solid fa-circle-half-stroke fa-lg"></i></span>
  </button>
`);
</script></div>
      
        <div class="navbar-item"><ul class="navbar-icon-links navbar-nav"
    aria-label="Icon Links">
        <li class="nav-item">
          
          
          
          
          
          
          
          
          <a href="https://gitlab.com/petsc/petsc" title="GitLab" class="nav-link" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><span><i class="fab fa-gitlab fa-lg" aria-hidden="true"></i></span>
            <span class="sr-only">GitLab</span></a>
        </li>
</ul></div>
      
    </div>
    
  </div>
  
  
    <div class="navbar-persistent--mobile">

 <script>
 document.write(`
   <button class="btn navbar-btn search-button-field search-button__button" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
    <i class="fa-solid fa-magnifying-glass"></i>
    <span class="search-button__default-text">Search</span>
    <span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd class="kbd-shortcut__modifier">K</kbd></span>
   </button>
 `);
 </script>
    </div>
  

  
    <label class="sidebar-toggle secondary-toggle" for="__secondary" tabindex="0">
      <span class="fa-solid fa-outdent"></span>
    </label>
  
</div>

    </div>
  
  </header>

  <div class="bd-container">
    <div class="bd-container__inner bd-page-width">
      
      
      
      <div class="bd-sidebar-primary bd-sidebar">
        

  
  <div class="sidebar-header-items sidebar-primary__section">
    
    
      <div class="sidebar-header-items__center">
        
          <div class="navbar-item">
<nav class="navbar-nav">
  <ul class="bd-navbar-elements navbar-nav">
    
                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../overview/index.html">
                        Overview
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../install/index.html">
                        Install
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../tutorials/index.html">
                        Tutorials
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../manual/index.html">
                        User-Guide
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../manualpages/index.html">
                        C/Fortran API
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../petsc4py/index.html">
                        petsc4py API
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../faq/index.html">
                        FAQ
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../community/index.html">
                        Community
                      </a>
                    </li>
                

                    <li class="nav-item current active">
                      <a class="nav-link nav-internal" href="index.html">
                        Developers
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../miscellaneous/index.html">
                        Misc.
                      </a>
                    </li>
                
  </ul>
</nav></div>
        
      </div>
    
    
    
      <div class="sidebar-header-items__end">
        
          <div class="navbar-item">

<script>
document.write(`
  <button class="btn btn-sm navbar-btn theme-switch-button" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip">
    <span class="theme-switch nav-link" data-mode="light"><i class="fa-solid fa-sun fa-lg"></i></span>
    <span class="theme-switch nav-link" data-mode="dark"><i class="fa-solid fa-moon fa-lg"></i></span>
    <span class="theme-switch nav-link" data-mode="auto"><i class="fa-solid fa-circle-half-stroke fa-lg"></i></span>
  </button>
`);
</script></div>
        
          <div class="navbar-item"><ul class="navbar-icon-links navbar-nav"
    aria-label="Icon Links">
        <li class="nav-item">
          
          
          
          
          
          
          
          
          <a href="https://gitlab.com/petsc/petsc" title="GitLab" class="nav-link" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><span><i class="fab fa-gitlab fa-lg" aria-hidden="true"></i></span>
            <span class="sr-only">GitLab</span></a>
        </li>
</ul></div>
        
      </div>
    
  </div>
  
    <div class="sidebar-primary-items__start sidebar-primary__section">
        <div class="sidebar-primary-item">
<nav class="bd-docs-nav bd-links"
     aria-label="Section Navigation">
  <p class="bd-links__title" role="heading" aria-level="1">Section Navigation</p>
  <div class="bd-toc-item navbar-nav"><ul class="current nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="communication.html">PETSc Developers Communication Channels</a></li>
<li class="toctree-l1 has-children"><a class="reference internal" href="contributing/index.html">Contributing to PETSc</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-1"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="contributing/developingmr.html">Developing a Merge Request</a></li>
<li class="toctree-l2"><a class="reference internal" href="contributing/submittingmr.html">Submitting a Merge Request</a></li>
<li class="toctree-l2"><a class="reference internal" href="contributing/pipelines.html">GitLab CI Pipelines</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="mrmanagement.html">Merge request management</a></li>
<li class="toctree-l1"><a class="reference internal" href="development.html">PETSc Development Environment</a></li>
<li class="toctree-l1"><a class="reference internal" href="style.html">PETSc Style and Usage Guide</a></li>
<li class="toctree-l1 current active"><a class="current reference internal" href="#">BuildSystem</a></li>
<li class="toctree-l1"><a class="reference internal" href="testing.html">PETSc Testing System</a></li>
<li class="toctree-l1"><a class="reference internal" href="documentation.html">Developing PETSc Documentation</a></li>
<li class="toctree-l1 has-children"><a class="reference internal" href="design.html">The Design of PETSc</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-2"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="kernel.html">The PETSc Kernel</a></li>
<li class="toctree-l2"><a class="reference internal" href="objects.html">Basic Object Design and Implementation</a></li>
<li class="toctree-l2"><a class="reference internal" href="callbacks.html">How the Solvers Handle User Provided Callbacks</a></li>
<li class="toctree-l2"><a class="reference internal" href="matrices.html">The Various Matrix Classes</a></li>
<li class="toctree-l2"><a class="reference internal" href="articles.html">Articles about PETSc Design</a></li>
</ul>
</li>
</ul>
</div>
</nav></div>
    </div>
  
  
  <div class="sidebar-primary-items__end sidebar-primary__section">
  </div>
  
  <div id="rtd-footer-container"></div>


      </div>
      
      <main id="main-content" class="bd-main">
        
        
          <div class="bd-content">
            <div class="bd-article-container">
              
              <div class="bd-header-article">
<div class="header-article-items header-article__inner">
  
    <div class="header-article-items__start">
      
        <div class="header-article-item">



<nav aria-label="Breadcrumb">
  <ul class="bd-breadcrumbs">
    
    <li class="breadcrumb-item breadcrumb-home">
      <a href="../index.html" class="nav-link" aria-label="Home">
        <i class="fa-solid fa-home"></i>
      </a>
    </li>
    
    <li class="breadcrumb-item"><a href="index.html" class="nav-link">Developers</a></li>
    
    <li class="breadcrumb-item active" aria-current="page">BuildSystem</li>
  </ul>
</nav>
</div>
      
    </div>
  
  
</div>
</div>
              
              
              
                
<div id="searchbox"></div>
                <article class="bd-article">
                  
  <section class="tex2jax_ignore mathjax_ignore" id="buildsystem">
<span id="ch-buildsystem"></span><h1>BuildSystem<a class="headerlink" href="#buildsystem" title="Link to this heading">#</a></h1>
<p><code class="docutils notranslate"><span class="pre">BuildSystem</span></code> (located in <code class="docutils notranslate"><span class="pre">config/BuildSystem</span></code>) configures PETSc before PETSc is compiled with make.
It is much like <a class="reference external" href="https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.71/html_node/index.html#Top">GNU Autoconf (configure)</a>
but written in Python especially for PETSc.</p>
<section id="what-is-a-build">
<h2>What is a build?<a class="headerlink" href="#what-is-a-build" title="Link to this heading">#</a></h2>
<p>The build stage compiles source to object files, stores them
(usually in archives), and links shared libraries and executables. These
are mechanical operations that reduce to applying a construction rule to
sets of files. The <a class="reference external" href="http://www.gnu.org/software/make/">Make</a> tool is
great at this job.</p>
</section>
<section id="why-is-configure-necessary">
<h2>Why is configure necessary?<a class="headerlink" href="#why-is-configure-necessary" title="Link to this heading">#</a></h2>
<p>The <code class="docutils notranslate"><span class="pre">configure</span></code> program is designed to assemble all information and preconditions
necessary for the build stage. This is a far more complicated task, heavily dependent on
the local hardware and software environment. It is also the source of nearly every build
problem. The most crucial aspect of a configure system is not performance, scalability, or
even functionality, but <em>debuggability</em>. Configuration failure is at least as common as
success, due to broken tools, operating system upgrades, hardware incompatibilities, user
error, and a host of other reasons. Problem diagnosis is the single biggest bottleneck for
development and maintenance time. Unfortunately, current systems are built to optimize the
successful case rather than the unsuccessful. In PETSc, we have developed the
<code class="docutils notranslate"><span class="pre">BuildSystem</span></code> package to remedy the shortcomings of configuration systems such as
Autoconf, CMake, and SCons.</p>
</section>
<section id="why-use-petsc-buildsystem">
<h2>Why use PETSc BuildSystem?<a class="headerlink" href="#why-use-petsc-buildsystem" title="Link to this heading">#</a></h2>
<p>As several configuration tools
currently exist, it is instructive to consider why PETSc would choose to create another
from scratch. Below we list features and design considerations which lead us to prefer
<code class="docutils notranslate"><span class="pre">BuildSystem</span></code> to the alternatives.</p>
<section id="namespacing">
<h3>Namespacing<a class="headerlink" href="#namespacing" title="Link to this heading">#</a></h3>
<p><code class="docutils notranslate"><span class="pre">BuildSystem</span></code> wraps collections of related tests in Python modules, which also hold
the test results. Thus results are accessed using normal Python
namespacing. As rudimentary as this sounds, no namespacing beyond the
use of variable name prefixes is present in Autoconf, CMake, and SCons.
Instead, a flat namespace is used. This
tendency appears again when composing command lines for external tools,
such as the compiler and linker. In the traditional configure tools,
options are aggregated in a single bucket variable, such as <code class="docutils notranslate"><span class="pre">INCLUDE</span></code>
or <code class="docutils notranslate"><span class="pre">LIBS</span></code>, whereas in <code class="docutils notranslate"><span class="pre">BuildSystem</span></code> one can trace the provenance of a flag before it
is added to the command line. CMake also makes the unfortunate decision
to force all link options to resolve to full paths, which causes havoc
with compiler-private libraries.</p>
</section>
<section id="explicit-control-flow">
<h3>Explicit control flow<a class="headerlink" href="#explicit-control-flow" title="Link to this heading">#</a></h3>
<p>The <code class="docutils notranslate"><span class="pre">BuildSystem</span></code> configure modules mentioned above, containing one <code class="docutils notranslate"><span class="pre">Configure</span></code> object
per module, are organized explicitly into a directed acyclic graph
(DAG). The user indicates dependence, an <em>edge</em> in the dependence graph,
with a single call, <code class="docutils notranslate"><span class="pre">requires('path.to.other.test',</span> <span class="pre">self)</span></code>, which not
only structures the DAG, but returns the <code class="docutils notranslate"><span class="pre">Configure</span></code> object. The caller
can then use this object to access the results of the tests run by the
dependency, achieving test and result encapsulation simply.</p>
</section>
<section id="multi-language-tests">
<h3>Multi-language tests<a class="headerlink" href="#multi-language-tests" title="Link to this heading">#</a></h3>
<p><code class="docutils notranslate"><span class="pre">BuildSystem</span></code> maintains an explicit language stack, so that the current language
can be manipulated by the test environment. A compile or link can be run
using any language, complete with the proper compilers, flags,
libraries, etc., with a single call. This automation is crucial
for cross-language tests, which are thinly supported in current
tools. In fact, the design of these tools inhibits this kind of check.
The <code class="docutils notranslate"><span class="pre">check_function_exists()</span></code> call in Autoconf and CMake looks only
for the presence of a particular symbol in a library, and fails in C++
and on Microsoft Windows, whereas the equivalent <code class="docutils notranslate"><span class="pre">BuildSystem</span></code> test can also take a
declaration. The <code class="docutils notranslate"><span class="pre">try_compile()</span></code> test in Autoconf and CMake requires
the entire list of libraries be present in the <code class="docutils notranslate"><span class="pre">LIBS</span></code> variable,
providing no good way to obtain libraries from other tests in a modular
fashion. As another example, if the user has a dependent library that
requires <code class="docutils notranslate"><span class="pre">libstdc++</span></code>, but they are working with a C project, no
straightforward method exists to add this dependency.</p>
</section>
<section id="subpackages">
<h3>Subpackages<a class="headerlink" href="#subpackages" title="Link to this heading">#</a></h3>
<p>The most complicated, yet perhaps most useful, part of <code class="docutils notranslate"><span class="pre">BuildSystem</span></code> is
support for dependent packages. It provides an object scaffolding for
including a 3rd party package (more than 100 are now available) so that
PETSc downloads and builds the package for use by PETSc. The native
configure and build system for the package is used, and special support
exists for Autoconf and CMake packages. No similar system exists in the other
tools, which rely on static declarations, such as <code class="docutils notranslate"><span class="pre">pkg-config</span></code> or
<code class="docutils notranslate"><span class="pre">FindPackage.cmake</span></code> files, that are not tested and often become
obsolete.</p>
</section>
<section id="batch-environments">
<h3>Batch environments<a class="headerlink" href="#batch-environments" title="Link to this heading">#</a></h3>
<p>Most systems, such as Autoconf and CMake, do not actually run tests in a
batch environment, but rather require a direct specification, in CMake a
“platform file”. This requires a human expert to write and maintain the
platform file. Alternatively, <code class="docutils notranslate"><span class="pre">BuildSystem</span></code> submits a dynamically
generated set of tests to the batch system, enabling automatic
cross-configuration and cross-compilation.</p>
</section>
<section id="caching">
<h3>Caching<a class="headerlink" href="#caching" title="Link to this heading">#</a></h3>
<p>Caching often seems like an attractive option since configuration can be
quite time-consuming, and both Autoconf and CMake enable caching by
default. However, no system has the ability to reliably invalidate the
cache when the environment for the configuration changes. For example, a
compiler or library dependency may be upgraded on the system. Moreover,
dependencies between cached variables are not tracked, so that even if
some variables are correctly updated after an upgrade, others which
depend on them may not be. Moreover, CMake mixes together information
which is discovered automatically with that explicitly provided by the
user, which is often not tested.</p>
</section>
<section id="concision">
<h3>Concision<a class="headerlink" href="#concision" title="Link to this heading">#</a></h3>
<p>The cognitive load is usually larger for larger code bases,
and our observation is that the addition of logic to Autoconf
and CMake is often quite cumbersome and verbose as they do not employ a modern,
higher level language. Although <code class="docutils notranslate"><span class="pre">BuildSystem</span></code> itself is not widely used,
it has the advantage of being written in Python, a widely-understood, high-level
language.</p>
</section>
</section>
<section id="high-level-organization">
<h2>High level organization<a class="headerlink" href="#high-level-organization" title="Link to this heading">#</a></h2>
<p>A minimal <code class="docutils notranslate"><span class="pre">BuildSystem</span></code> setup consists of a <code class="docutils notranslate"><span class="pre">config</span></code> directory off the
package root, which contains all the Python necessary to run (in addition
to the <code class="docutils notranslate"><span class="pre">BuildSystem</span></code> source). At minimum, the <code class="docutils notranslate"><span class="pre">config</span></code> directory contains
<code class="docutils notranslate"><span class="pre">configure.py</span></code>, which is executed to run the configure process, and a
module for the package itself. For example, PETSc contains
<code class="docutils notranslate"><span class="pre">config/PETSc/petsc.py</span></code>. It is also common to include a top level
<code class="docutils notranslate"><span class="pre">configure</span></code> file to execute the configure, as this looks like
Autotools,</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python3</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">os</span>
<span class="n">execfile</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="vm">__file__</span><span class="p">),</span> <span class="s1">&#39;config&#39;</span><span class="p">,</span> <span class="s1">&#39;configure.py&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>The <code class="docutils notranslate"><span class="pre">configure.py</span></code> script constructs a tree of configure modules and
executes the configure process over it. A minimal version of this would
be</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">package</span> <span class="o">=</span> <span class="s1">&#39;PETSc&#39;</span>

<span class="k">def</span><span class="w"> </span><span class="nf">configure</span><span class="p">(</span><span class="n">configure_options</span><span class="p">):</span>
  <span class="c1"># Command line arguments take precedence (but don&#39;t destroy argv[0])</span>
  <span class="n">sys</span><span class="o">.</span><span class="n">argv</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[:</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">configure_options</span> <span class="o">+</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
  <span class="n">framework</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">Framework</span><span class="p">([</span><span class="s1">&#39;--configModules=&#39;</span><span class="o">+</span><span class="n">package</span><span class="o">+</span><span class="s1">&#39;.Configure&#39;</span><span class="p">,</span> <span class="s1">&#39;--optionsModule=&#39;</span><span class="o">+</span><span class="n">package</span><span class="o">+</span><span class="s1">&#39;.compilerOptions&#39;</span><span class="p">]</span><span class="o">+</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="n">loadArgDB</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span>
  <span class="n">framework</span><span class="o">.</span><span class="n">setup</span><span class="p">()</span>
  <span class="n">framework</span><span class="o">.</span><span class="n">configure</span><span class="p">(</span><span class="n">out</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span>
  <span class="n">framework</span><span class="o">.</span><span class="n">storeSubstitutions</span><span class="p">(</span><span class="n">framework</span><span class="o">.</span><span class="n">argDB</span><span class="p">)</span>
  <span class="n">framework</span><span class="o">.</span><span class="n">printSummary</span><span class="p">()</span>
  <span class="n">framework</span><span class="o">.</span><span class="n">argDB</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">force</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span>
  <span class="n">framework</span><span class="o">.</span><span class="n">logClear</span><span class="p">()</span>
  <span class="n">framework</span><span class="o">.</span><span class="n">closeLog</span><span class="p">()</span>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
  <span class="n">configure</span><span class="p">([])</span>
</pre></div>
</div>
<p>The PETSc <code class="docutils notranslate"><span class="pre">configure.py</span></code> is quite a bit longer than this, as it
performs specialized command line processing, error handling, and
integrating logging with the rest of PETSc.</p>
<p>The <code class="docutils notranslate"><span class="pre">config/package/Configure.py</span></code> module determines how the tree of
<code class="docutils notranslate"><span class="pre">Configure</span></code> objects is built and how the configure information is output.
The <code class="docutils notranslate"><span class="pre">configure()</span></code> method of the module will be run by the <code class="docutils notranslate"><span class="pre">Framework</span></code>
object created at the top level. A minimal <code class="docutils notranslate"><span class="pre">configure()</span></code> method would look
like</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">configure</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  <span class="bp">self</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">header</span>          <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="o">.</span><span class="n">arch</span><span class="o">+</span><span class="s1">&#39;/include/&#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">project</span><span class="o">+</span><span class="s1">&#39;conf.h&#39;</span>
  <span class="bp">self</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">makeMacroHeader</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="o">.</span><span class="n">arch</span><span class="o">+</span><span class="s1">&#39;/conf/&#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">project</span><span class="o">+</span><span class="s1">&#39;variables&#39;</span>
  <span class="bp">self</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">makeRuleHeader</span>  <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="o">.</span><span class="n">arch</span><span class="o">+</span><span class="s1">&#39;/conf/&#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">project</span><span class="o">+</span><span class="s1">&#39;rules&#39;</span>

  <span class="bp">self</span><span class="o">.</span><span class="n">Dump</span><span class="p">()</span>
  <span class="bp">self</span><span class="o">.</span><span class="n">logClear</span><span class="p">()</span>
  <span class="k">return</span>
</pre></div>
</div>
<p>The <code class="docutils notranslate"><span class="pre">Dump</span></code> method runs over the tree of configure modules, and outputs
the data necessary for building, usually employing the
<code class="docutils notranslate"><span class="pre">addMakeMacro()</span></code>, <code class="docutils notranslate"><span class="pre">addMakeRule()</span></code> and <code class="docutils notranslate"><span class="pre">addDefine()</span></code> methods. These
methods funnel output to the include and make files defined by the
framework object, and set at the beginning of this <code class="docutils notranslate"><span class="pre">configure()</span></code>
method. There is also some simple information that is often used, which
we define in the initializer,</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">framework</span><span class="p">):</span>
  <span class="n">config</span><span class="o">.</span><span class="n">base</span><span class="o">.</span><span class="n">Configure</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">framework</span><span class="p">)</span>
  <span class="bp">self</span><span class="o">.</span><span class="n">Project</span>      <span class="o">=</span> <span class="s1">&#39;PETSc&#39;</span>
  <span class="bp">self</span><span class="o">.</span><span class="n">project</span>      <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Project</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
  <span class="bp">self</span><span class="o">.</span><span class="n">PROJECT</span>      <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Project</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span>
  <span class="bp">self</span><span class="o">.</span><span class="n">headerPrefix</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">PROJECT</span>
  <span class="bp">self</span><span class="o">.</span><span class="n">substPrefix</span>  <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">PROJECT</span>
  <span class="bp">self</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">Project</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">Project</span>
  <span class="k">return</span>
</pre></div>
</div>
<p>More sophisticated configure assemblies, like PETSc, output some other
custom information, such as information about the machine, configure
process, and a script to recreate the configure run.</p>
<p>The <code class="docutils notranslate"><span class="pre">Package</span></code> configure module has two other main functions. First, top
level options can be defined in the <code class="docutils notranslate"><span class="pre">setupHelp()</span></code> method,</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">setupHelp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">help</span><span class="p">):</span>
  <span class="kn">import</span><span class="w"> </span><span class="nn">nargs</span>
  <span class="n">help</span><span class="o">.</span><span class="n">addArgument</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Project</span><span class="p">,</span> <span class="s1">&#39;-prefix=&lt;path&gt;&#39;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">.</span><span class="n">Arg</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s1">&#39;Specify location to install &#39;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">Project</span><span class="o">+</span><span class="s1">&#39; (eg. /usr/local)&#39;</span><span class="p">))</span>
  <span class="n">help</span><span class="o">.</span><span class="n">addArgument</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Project</span><span class="p">,</span> <span class="s1">&#39;-load-path=&lt;path&gt;&#39;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">.</span><span class="n">Arg</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">(),</span> <span class="s1">&#39;modules&#39;</span><span class="p">),</span> <span class="s1">&#39;Specify location of auxiliary modules&#39;</span><span class="p">))</span>
  <span class="n">help</span><span class="o">.</span><span class="n">addArgument</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Project</span><span class="p">,</span> <span class="s1">&#39;-with-shared-libraries&#39;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">.</span><span class="n">ArgBool</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;Make libraries shared&#39;</span><span class="p">))</span>
  <span class="n">help</span><span class="o">.</span><span class="n">addArgument</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Project</span><span class="p">,</span> <span class="s1">&#39;-with-dynamic-loading&#39;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">.</span><span class="n">ArgBool</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;Make libraries dynamic&#39;</span><span class="p">))</span>
  <span class="k">return</span>
</pre></div>
</div>
<p>This uses the <code class="docutils notranslate"><span class="pre">BuildSystem</span></code> help facility that is used to define options
for all configure modules. The first argument groups these options into
a section named for the package. The second task is to build the tree of
modules for the configure run, using the <code class="docutils notranslate"><span class="pre">setupDependencies()</span></code> method.
A simple way to do this is by explicitly declaring dependencies,</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">setupDependencies</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">framework</span><span class="p">):</span>
    <span class="n">config</span><span class="o">.</span><span class="n">base</span><span class="o">.</span><span class="n">Configure</span><span class="o">.</span><span class="n">setupDependencies</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">framework</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">setCompilers</span>  <span class="o">=</span> <span class="n">framework</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="s1">&#39;config.setCompilers&#39;</span><span class="p">,</span>                <span class="bp">self</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">arch</span>          <span class="o">=</span> <span class="n">framework</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Project</span><span class="o">+</span><span class="s1">&#39;.utilities.arch&#39;</span><span class="p">,</span>       <span class="bp">self</span><span class="o">.</span><span class="n">setCompilers</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">projectdir</span>    <span class="o">=</span> <span class="n">framework</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Project</span><span class="o">+</span><span class="s1">&#39;.utilities.projectdir&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">compilers</span>     <span class="o">=</span> <span class="n">framework</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="s1">&#39;config.compilers&#39;</span><span class="p">,</span>                   <span class="bp">self</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">types</span>         <span class="o">=</span> <span class="n">framework</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="s1">&#39;config.types&#39;</span><span class="p">,</span>                       <span class="bp">self</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">headers</span>       <span class="o">=</span> <span class="n">framework</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="s1">&#39;config.headers&#39;</span><span class="p">,</span>                     <span class="bp">self</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">functions</span>     <span class="o">=</span> <span class="n">framework</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="s1">&#39;config.functions&#39;</span><span class="p">,</span>                   <span class="bp">self</span><span class="p">)</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">libraries</span>     <span class="o">=</span> <span class="n">framework</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="s1">&#39;config.libraries&#39;</span><span class="p">,</span>                   <span class="bp">self</span><span class="p">)</span>

    <span class="bp">self</span><span class="o">.</span><span class="n">compilers</span><span class="o">.</span><span class="n">headerPrefix</span>  <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">headerPrefix</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">types</span><span class="o">.</span><span class="n">headerPrefix</span>      <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">headerPrefix</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">headers</span><span class="o">.</span><span class="n">headerPrefix</span>    <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">headerPrefix</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">functions</span><span class="o">.</span><span class="n">headerPrefix</span>  <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">headerPrefix</span>
    <span class="bp">self</span><span class="o">.</span><span class="n">libraries</span><span class="o">.</span><span class="n">headerPrefix</span>  <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">headerPrefix</span>
</pre></div>
</div>
<p>The <code class="docutils notranslate"><span class="pre">projectdir</span></code> and <code class="docutils notranslate"><span class="pre">arch</span></code> modules define the project root
directory and a build name so that multiple independent builds can be
managed. The <code class="docutils notranslate"><span class="pre">Framework.require()</span></code> method creates an edge in the
dependency graph for configure modules, and returns the module object so
that it can be queried after the configure information is determined.
Setting the header prefix routes all the defines made inside those
modules to our package configure header. We can also automatically
create configure modules based upon what we see on the filesystem,</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="n">utility</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">&#39;config&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">Project</span><span class="p">,</span> <span class="s1">&#39;utilities&#39;</span><span class="p">)):</span>
  <span class="p">(</span><span class="n">utilityName</span><span class="p">,</span> <span class="n">ext</span><span class="p">)</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</span><span class="n">utility</span><span class="p">)</span>
  <span class="k">if</span> <span class="ow">not</span> <span class="n">utilityName</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">utilityName</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;#&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">ext</span> <span class="o">==</span> <span class="s1">&#39;.py&#39;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">utilityName</span> <span class="o">==</span> <span class="s1">&#39;__init__&#39;</span><span class="p">:</span>
    <span class="n">utilityObj</span>                    <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">Project</span><span class="o">+</span><span class="s1">&#39;.utilities.&#39;</span><span class="o">+</span><span class="n">utilityName</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>
    <span class="n">utilityObj</span><span class="o">.</span><span class="n">headerPrefix</span>       <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">headerPrefix</span>
    <span class="n">utilityObj</span><span class="o">.</span><span class="n">archProvider</span>       <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">arch</span>
    <span class="n">utilityObj</span><span class="o">.</span><span class="n">languageProvider</span>   <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">languages</span>
    <span class="n">utilityObj</span><span class="o">.</span><span class="n">precisionProvider</span>  <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">scalartypes</span>
    <span class="n">utilityObj</span><span class="o">.</span><span class="n">installDirProvider</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">installdir</span>
    <span class="n">utilityObj</span><span class="o">.</span><span class="n">externalPackagesDirProvider</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">externalpackagesdir</span>
    <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">utilityName</span><span class="o">.</span><span class="n">lower</span><span class="p">(),</span> <span class="n">utilityObj</span><span class="p">)</span>
</pre></div>
</div>
<p>The provider modules customize the information given to the module based
upon settings for our package. For example, PETSc can be compiled with a
scalar type that is single, double, or quad precision, and thus has a
<code class="docutils notranslate"><span class="pre">precisionProvider</span></code>. If a package does not have this capability, the
provider setting can be omitted.</p>
</section>
<section id="main-objects">
<h2>Main objects<a class="headerlink" href="#main-objects" title="Link to this heading">#</a></h2>
<section id="framework">
<h3>Framework<a class="headerlink" href="#framework" title="Link to this heading">#</a></h3>
<p>The <code class="docutils notranslate"><span class="pre">config.framework.Framework</span></code> object serves as the central control
for a configure run. It maintains a graph of all the configure modules
involved, which is also used to track dependencies between them. It
initiates the run, compiles the results, and handles the final output.
It maintains the help list for all options available in the run. The
<code class="docutils notranslate"><span class="pre">setup()</span></code> method performs generic <code class="docutils notranslate"><span class="pre">Script</span></code> setup and then is called
recursively on all the child modules. The <code class="docutils notranslate"><span class="pre">cleanup()</span></code> method performs
the final output and logging actions,</p>
<ul class="simple">
<li><p>Substitute files</p></li>
<li><p>Output configure header</p></li>
<li><p>Log filesystem actions</p></li>
</ul>
<p>Children may be added to the Framework using <code class="docutils notranslate"><span class="pre">addChild()</span></code> or
<code class="docutils notranslate"><span class="pre">getChild()</span></code>, but the far more frequent method is to use
<code class="docutils notranslate"><span class="pre">require()</span></code>. Here a module is requested, as in <code class="docutils notranslate"><span class="pre">getChild()</span></code>, but it
is also required to run before another module, usually the one executing
the <code class="docutils notranslate"><span class="pre">require()</span></code>. This provides a simple local interface to establish
dependencies between the child modules, and provides a partial order on
the children to the Framework.</p>
<p>A backwards compatibility mode is provided for which the user specifies
a configure header and set of files to experience substitution,
mirroring the common usage of Autoconf. Slight improvements have been
made in that all defines are now guarded, various prefixes are allowed
for defines and substitutions, and C specific constructs such as
function prototypes and typedefs are removed to a separate header.
However, this is not the intended future usage. The use of configure
modules by other modules in the same run provides a model for the
suggested interaction of a new build system with the Framework. If a
module requires another, it merely executes a <code class="docutils notranslate"><span class="pre">require()</span></code>. For
instance, the PETSc configure module for hypre requires information
about MPI, and thus contains</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="bp">self</span><span class="o">.</span><span class="n">mpi</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">framework</span><span class="o">.</span><span class="n">require</span><span class="p">(</span><span class="s2">&quot;config.packages.MPI&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span>
</pre></div>
</div>
<p>Notice that passing self for the last arguments means that the MPI
module will run before the hypre module. Furthermore, we save the
resulting object as <code class="docutils notranslate"><span class="pre">self.mpi</span></code> so that we may interrogate it later.
hypre can initially test whether MPI was indeed found using
<code class="docutils notranslate"><span class="pre">self.mpi.found</span></code>. When hypre requires the list of MPI libraries in
order to link a test object, the module can use <code class="docutils notranslate"><span class="pre">self.mpi.lib</span></code>.</p>
</section>
<section id="base">
<h3>Base<a class="headerlink" href="#base" title="Link to this heading">#</a></h3>
<p>The <code class="docutils notranslate"><span class="pre">config.base.Configure</span></code> is the base class for all configure
objects. It handles several types of interaction. First, it has hooks
that allow the Framework to initialize it correctly. The Framework will
first instantiate the object and call <code class="docutils notranslate"><span class="pre">setupDependencies()</span></code>. All
<code class="docutils notranslate"><span class="pre">require()</span></code> calls should be made in that method. The Framework will
then call <code class="docutils notranslate"><span class="pre">configure()</span></code>. If it succeeds, the object will be marked as
configured. Second, all configure tests should be run using
<code class="docutils notranslate"><span class="pre">executeTest()</span></code> which formats the output and adds metadata for the
log.</p>
<p>Third, all tests that involve preprocessing, compiling, linking, and
running operator through <code class="docutils notranslate"><span class="pre">base</span></code>. Two forms of this check are provided
for each operation. The first is an “output” form which is intended to
provide the status and complete output of the command. The second, or
“check” form will return a success or failure indication based upon the
status and output. The routines are</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">outputPreprocess</span><span class="p">(),</span> <span class="n">checkPreprocess</span><span class="p">(),</span> <span class="n">preprocess</span><span class="p">()</span>
<span class="n">outputCompile</span><span class="p">(),</span>    <span class="n">checkCompile</span><span class="p">()</span>
<span class="n">outputLink</span><span class="p">(),</span>       <span class="n">checkLink</span><span class="p">()</span>
<span class="n">outputRun</span><span class="p">(),</span>        <span class="n">checkRun</span><span class="p">()</span>
</pre></div>
</div>
<p>The language used for these operation is managed with a stack, similar
to Autoconf, using <code class="docutils notranslate"><span class="pre">pushLanguage()</span></code> and <code class="docutils notranslate"><span class="pre">popLanguage()</span></code>. We also
provide special forms used to check for valid compiler and linker flags,
optionally adding them to the defaults.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">checkCompilerFlag</span><span class="p">(),</span> <span class="n">addCompilerFlag</span><span class="p">()</span>
<span class="n">checkLinkerFlag</span><span class="p">(),</span>   <span class="n">addLinkerFlag</span><span class="p">()</span>
</pre></div>
</div>
<p>You can also use <code class="docutils notranslate"><span class="pre">getExecutable()</span></code> to search for executables.</p>
<p>After configure tests have been run, various kinds of output can be
generated.A #define statement can be added to the configure header using
<code class="docutils notranslate"><span class="pre">addDefine()</span></code>, and <code class="docutils notranslate"><span class="pre">addTypedef()</span></code> and <code class="docutils notranslate"><span class="pre">addPrototype()</span></code> also put
information in this header file. Using <code class="docutils notranslate"><span class="pre">addMakeMacro()</span></code> and
<code class="docutils notranslate"><span class="pre">addMakeRule()</span></code> will add make macros and rules to the output makefiles
specified in the framework. In addition we provide <code class="docutils notranslate"><span class="pre">addSubstitution()</span></code>
and <code class="docutils notranslate"><span class="pre">addArgumentSubstitution()</span></code> to mimic the behavior of Autoconf if
necessary. The object may define a <code class="docutils notranslate"><span class="pre">headerPrefix</span></code> member, which will
be appended, followed by an underscore, to every define which is output
from it. Similarly, a <code class="docutils notranslate"><span class="pre">substPrefix</span></code> can be defined which applies to
every substitution from the object. Typedefs and function prototypes are
placed in a separate header in order to accommodate languages such as
Fortran whose preprocessor can sometimes fail at these statements.</p>
</section>
</section>
</section>


                </article>
              
              
              
              
              
                <footer class="prev-next-footer">
                  
<div class="prev-next-area">
    <a class="left-prev"
       href="style.html"
       title="previous page">
      <i class="fa-solid fa-angle-left"></i>
      <div class="prev-next-info">
        <p class="prev-next-subtitle">previous</p>
        <p class="prev-next-title">PETSc Style and Usage Guide</p>
      </div>
    </a>
    <a class="right-next"
       href="testing.html"
       title="next page">
      <div class="prev-next-info">
        <p class="prev-next-subtitle">next</p>
        <p class="prev-next-title">PETSc Testing System</p>
      </div>
      <i class="fa-solid fa-angle-right"></i>
    </a>
</div>
                </footer>
              
            </div>
            
            
              
                <div class="bd-sidebar-secondary bd-toc"><div class="sidebar-secondary-items sidebar-secondary__inner">


  <div class="sidebar-secondary-item">
<div
    id="pst-page-navigation-heading-2"
    class="page-toc tocsection onthispage">
    <i class="fa-solid fa-list"></i> On this page
  </div>
  <nav class="bd-toc-nav page-toc" aria-labelledby="pst-page-navigation-heading-2">
    <ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#what-is-a-build">What is a build?</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#why-is-configure-necessary">Why is configure necessary?</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#why-use-petsc-buildsystem">Why use PETSc BuildSystem?</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#namespacing">Namespacing</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#explicit-control-flow">Explicit control flow</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#multi-language-tests">Multi-language tests</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#subpackages">Subpackages</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#batch-environments">Batch environments</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#caching">Caching</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#concision">Concision</a></li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#high-level-organization">High level organization</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#main-objects">Main objects</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#framework">Framework</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#base">Base</a></li>
</ul>
</li>
</ul>
  </nav></div>

  <div class="sidebar-secondary-item">

  
  <div class="tocsection editthispage">
    <a href="https://gitlab.com/petsc/petsc/-/edit/release/doc/developers/buildsystem.md">
      <i class="fa-solid fa-pencil"></i>
      
      
        
          Edit on GitLab
        
      
    </a>
  </div>
</div>

  <div class="sidebar-secondary-item">

  <div class="tocsection sourcelink">
    <a href="../_sources/developers/buildsystem.md.txt">
      <i class="fa-solid fa-file-lines"></i> Show Source
    </a>
  </div>
</div>

</div></div>
              
            
          </div>
          <footer class="bd-footer-content">
            
          </footer>
        
      </main>
    </div>
  </div>
  
  <!-- Scripts loaded after <body> so the DOM is not blocked -->
  <script src="../_static/scripts/bootstrap.js?digest=bd9e20870c6007c4c509"></script>
<script src="../_static/scripts/pydata-sphinx-theme.js?digest=bd9e20870c6007c4c509"></script>

  <footer class="bd-footer">
<div class="bd-footer__inner bd-page-width">
  
    <div class="footer-items__start">
      
        <div class="footer-item">

  <p class="copyright">
    
      © Copyright 1991-2025, UChicago Argonne, LLC and the PETSc Development Team.
      <br/>
    
  </p>
</div>
      
        <div class="footer-item">

  <p class="sphinx-version">
    Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.3.7.
    <br/>
  </p>
</div>
      
    </div>
  
  
  
    <div class="footer-items__end">
      
        <div class="footer-item">
<p class="theme-version">
  Built with the <a href="https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html">PyData Sphinx Theme</a> 0.15.1.
</p></div>
      
        <div class="footer-item"><p class="last-updated">
  Last updated on 2025-04-30T13:10:40-0500 (v3.23.1).
  <br/>
</p></div>
      
    </div>
  
</div>

  </footer>
  </body>
</html>