Makefile.inc
Overview
Makefile.inc is a build configuration file designed to automate the compilation process of Solidity-based smart contracts into their TVM (TON Virtual Machine) binary representations. It handles tasks such as copying necessary Solidity source files from a parent directory, compiling .sol files into .tvc and .abi.json artifacts, and cleaning up generated build files. This file uses GNU Make syntax for defining build targets, dependencies, and rules, streamlining contract development workflows in the project.
Variables and Their Purpose
.DEFAULT_GOAL := build
Sets the default make target tobuild, so typingmakewill trigger contract compilation.SOLD
Path or command for the Solidity compiler (sold). It is auto-detected via shell commandcommand -v sold, or defaults to../compiler/soldif not found.TVM_CLI
Path or command for the TVM CLI tool, detected similarly toSOLD.TVM_DEBUGGER
Path or command for the TVM debugger.TVM_VERSION
The TVM version string passed to the compiler. Defaults to"gosh".TVCS
List variable expected to contain Solidity contract base filenames (excluding extension). It is intended to be defined externally in folder-specific Makefiles.CPFL
List variable containing filenames of Solidity files to be copied from the parent directory. Also defined in folder-specific Makefiles.SRC_FILES
Derived list of Solidity source files, appending.solextension to items inTVCS.TVC_FILES
Derived list of compiled contract files with.tvcextension fromTVCS.COPIED_FILES
Derived list of Solidity files to copy from parent directory, appending.solextension toCPFL.
Makefile Targets and Rules
clean
Purpose:
Removes all generated build artifacts including.tvc,.abi.json, .code, .debug.json files, and import directories.Commands:
Deletes compiled contract files and metadata.
Deletes import cache directories
.solc_importsand.sold_imports.Prints status messages before and after cleanup.
Usage:
make clean
build
Purpose:
Default target that orchestrates copying necessary files and compiling contracts.Depends on:
copy-filesbuild-contracts
Usage:
make
copy-files
Purpose:
Copies specified Solidity files (COPIED_FILES) from the parent directory to the current directory.Rule:
Uses a pattern rule to copy files from../to./with error checking.Usage:
make copy-filesError Handling:
Prints an error and exits if copying fails.
build-contracts
Purpose:
Compiles all Solidity contracts listed inTVCSinto.tvcand.abi.jsonfiles.Depends on:
All.tvcfiles derived fromTVCS.Usage:
make build-contracts
Pattern Rule: ./%.tvc ./%.abi.json : ./%.sol
Purpose:
Compiles a single Solidity file into TVM bytecode and ABI JSON files.Process:
Invokes the
soldcompiler with the specifiedTVM_VERSION.Outputs are generated in the current directory.
Removes debug and code files after compilation to keep workspace clean.
Prints compilation status.
Error Handling:
Compilation failure triggers error message and exit.Example:
To compileMyContract.sol:make MyContract.tvc
Implementation Details
Automatic Command Resolution:
The use ofcommand -vensures tools likesold,tvm-cli, andtvm-debuggerare located in the system's PATH, otherwise fallback paths within../compiler/are used.Dependency Management:
File dependencies are expressed explicitly so that only changed files are recompiled, optimizing build times.File Copying:
Solidity files defined inCPFLare copied from the parent directory to ensure the build environment has all necessary source files. This supports modular project structures.Clean Separation of Responsibilities:
Copying and compilation are handled as separate targets, making the build process modular and debuggable.
Interaction with Other Parts of the System
Folder-Specific Makefiles:
TVCSandCPFLvariables must be set externally in folder-specific Makefiles, allowing this included Makefile to be reused across multiple contract directories.Compiler Tools:
Relies on external compiler binaries (sold) and tools (tvm-cli,tvm-debugger) that must be installed or available in relative paths.Source Control and Imports:
The.solc_importsand.sold_importsdirectories cleaned by thecleantarget indicate external Solidity dependencies or imported modules managed by the compiler.Build Artifacts:
Generated.tvcand.abi.jsonfiles are essential for deploying contracts to TVM-compatible chains and interfacing with them.
Visual Diagram
flowchart TD
A["Start: make (default = build)"]
A --> B[copy-files]
B --> C{For each file in COPIED_FILES}
C -->|copy ../file.sol to ./file.sol| D[File copied]
D --> E[build-contracts]
E --> F{For each file in TVCS}
F -->|Compile file.sol| G[Run sold compiler]
G --> H[Generate file.tvc and file.abi.json]
H --> I[Remove debug.json and code files]
I --> J[Compilation success]
J --> K[Build complete]
A --> L["clean (manual)"]
L --> M[Remove generated files and import dirs]
M --> N[Clean complete]
This flowchart shows the main workflow: starting a build triggers copying files, then compiling contracts, generating artifacts, and optionally cleaning up generated files.