markdown · 2479 bytes Raw Blame History

Build System Parity

This document explains how to achieve identical builds between fpm and Makefile.

TL;DR

For identical optimized builds:

# Using fpm
fpm build --flag "-O2 -Wall -ffree-line-length-none"

# Using make
make

# Or use the unified build script
./build.sh release

Build Systems

facsimile supports two build systems:

  1. fpm (Fortran Package Manager) - Modern, dependency-aware
  2. Makefile - Traditional, platform-specific optimizations

Key Differences

Aspect fpm Makefile
Dependency Management Automatic Manual (order matters)
Parallel Build Safe, automatic Disabled (.NOTPARALLEL)
Compiler Selection Uses PATH gfortran Detects Homebrew gfortran on macOS
Output Location ./build/gfortran_*/app/fac ./fac
Incremental Builds Efficient Basic
C Code Handling Automatic Explicit gcc compilation

Compiler Flags

Both systems use the same optimization flags for release builds:

  • -O2 - Optimization level 2 (good balance of speed and size)
  • -Wall - Enable all warnings
  • -ffree-line-length-none - Allow long Fortran lines

Binary Size Comparison

With identical flags, both systems produce nearly identical binaries:

  • Makefile build: ~287KB
  • fpm optimized build: ~294KB

The slight difference (~7KB) is due to:

  • Different linking order
  • Metadata differences
  • Path information

Platform-Specific Notes

macOS (Apple Silicon)

  • Makefile automatically finds Homebrew's gfortran in /opt/homebrew
  • fpm uses whatever gfortran is in PATH
  • Ensure Homebrew's gfortran is in PATH for consistency

Linux

  • Both systems work identically
  • No special configuration needed

Debug Builds

# fpm debug build
fpm build --flag "-g -Wall -ffree-line-length-none -fbacktrace -fcheck=bounds"

# Makefile doesn't have debug configuration
# Edit FFLAGS manually if needed

Recommendations

  1. For Development: Use fpm (better incremental builds)
  2. For Distribution:
    • macOS: Use Makefile (better compiler detection)
    • Linux: Either works fine
  3. For CI/CD: Use fpm with explicit flags

Build Script

Use the provided build.sh script for unified building:

./build.sh release  # Optimized build
./build.sh debug    # Debug build (fpm only)
./build.sh clean    # Clean build artifacts

The script automatically detects available build systems and uses appropriate flags for parity.

View source
1 # Build System Parity
2
3 This document explains how to achieve identical builds between fpm and Makefile.
4
5 ## TL;DR
6
7 For identical optimized builds:
8
9 ```bash
10 # Using fpm
11 fpm build --flag "-O2 -Wall -ffree-line-length-none"
12
13 # Using make
14 make
15
16 # Or use the unified build script
17 ./build.sh release
18 ```
19
20 ## Build Systems
21
22 facsimile supports two build systems:
23
24 1. **fpm** (Fortran Package Manager) - Modern, dependency-aware
25 2. **Makefile** - Traditional, platform-specific optimizations
26
27 ## Key Differences
28
29 | Aspect | fpm | Makefile |
30 |--------|-----|----------|
31 | Dependency Management | Automatic | Manual (order matters) |
32 | Parallel Build | Safe, automatic | Disabled (.NOTPARALLEL) |
33 | Compiler Selection | Uses PATH gfortran | Detects Homebrew gfortran on macOS |
34 | Output Location | `./build/gfortran_*/app/fac` | `./fac` |
35 | Incremental Builds | Efficient | Basic |
36 | C Code Handling | Automatic | Explicit gcc compilation |
37
38 ## Compiler Flags
39
40 Both systems use the same optimization flags for release builds:
41
42 - `-O2` - Optimization level 2 (good balance of speed and size)
43 - `-Wall` - Enable all warnings
44 - `-ffree-line-length-none` - Allow long Fortran lines
45
46 ## Binary Size Comparison
47
48 With identical flags, both systems produce nearly identical binaries:
49
50 - Makefile build: ~287KB
51 - fpm optimized build: ~294KB
52
53 The slight difference (~7KB) is due to:
54 - Different linking order
55 - Metadata differences
56 - Path information
57
58 ## Platform-Specific Notes
59
60 ### macOS (Apple Silicon)
61 - Makefile automatically finds Homebrew's gfortran in `/opt/homebrew`
62 - fpm uses whatever gfortran is in PATH
63 - Ensure Homebrew's gfortran is in PATH for consistency
64
65 ### Linux
66 - Both systems work identically
67 - No special configuration needed
68
69 ## Debug Builds
70
71 ```bash
72 # fpm debug build
73 fpm build --flag "-g -Wall -ffree-line-length-none -fbacktrace -fcheck=bounds"
74
75 # Makefile doesn't have debug configuration
76 # Edit FFLAGS manually if needed
77 ```
78
79 ## Recommendations
80
81 1. **For Development**: Use fpm (better incremental builds)
82 2. **For Distribution**:
83 - macOS: Use Makefile (better compiler detection)
84 - Linux: Either works fine
85 3. **For CI/CD**: Use fpm with explicit flags
86
87 ## Build Script
88
89 Use the provided `build.sh` script for unified building:
90
91 ```bash
92 ./build.sh release # Optimized build
93 ./build.sh debug # Debug build (fpm only)
94 ./build.sh clean # Clean build artifacts
95 ```
96
97 The script automatically detects available build systems and uses appropriate flags for parity.