Skip to content

Conversation

@hun1er
Copy link
Contributor

@hun1er hun1er commented Sep 1, 2025

Summary

Introduce support for .cfg configuration files, allowing developers to define and reuse sets of compiler options.
This simplifies the build process, eliminates long and repetitive command-line strings, and makes managing different build profiles (e.g., debug, release) straightforward.

The primary way to use this feature is through the new -T command line option, which allows you to specify the path to a custom configuration file.

How It Works

The compiler can now load options directly from a .cfg file.
The mechanism for finding and loading these files is as follows:

  1. Custom configuration via -T<your.cfg> (highest priority)

    • If a path to config is provided: When the value contains a directory separator (/ or \),
      the compiler uses the path as-is.
    • If only a name is provided: When the value is a simple name without path separators, the compiler will look for that file inside the target directory located alongside the compiler executable.
      For example, amxxpc -Trelease will cause the compiler to look for <compiler_path>/target/release.cfg.
  2. Default configurations (if -T is not used)
    If no -T option is given, the compiler will search for a default configuration file in the following order:

    • Looks for default.cfg inside the target directory (target/default.cfg).
    • If the above is not found, it looks for pawn.cfg in the same directory as the compiler executable.

Option Precedence

Options are applied in a clear order:

  1. The compiler first loads all options from the determined .cfg file.
  2. It then applies any options specified on the command line.

This means that options on the command line will always override those in the configuration file.

How to Use

Example default.cfg File

Here is a comprehensive example of a target/default.cfg file, demonstrating how various options can be set:

# -----------------------------------------------------------------------------
# Default Compiler Configuration
#
# This file contains default settings for all compilations. 
# Any option here can be overridden by a command-line argument.
# -----------------------------------------------------------------------------


# -- Debugging and Output Verbosity --

# Set the default debug level.
# -d0: No debug info, no checks. For maximum performance.
# -d1: Run-time checks only (bounds, etc.).
# -d2: Full debug info and checks. Best for development.
# -d3: Full debug info, checks, and no peephole optimization.
-d2

# Show stack usage information after a successful compile.
# Use -sui+ to enable or -sui- to disable.
-sui+

# Redirect all error and warning messages to a specified file.
# This is useful for build scripts or IDE integration.
# -e "logs/compiler_errors.log"


# -- File Generation --

# Generate a human-readable assembler (.asm) file instead of a binary (.amx).
# This is useful for low-level debugging.
# -a

# Generate a preprocessor listing (.lst) file instead of compiling.
# This shows the source code after all #includes, #defines, and macros.
# -l

# Generate a cross-reference report (.xml) detailing symbol usage.
# If no filename is given, output is sent to the console.
# -r"reports/plugin_report.xml"


# -- Compilation and Code Generation --

# Enable compact encoding for the output file to reduce its size.
# Use -C+ to enable or -C- to disable.
-C-

# Set the alignment for the data segment and stack in bytes. Must be a power of two.
# The default is typically 4 or 8 bytes.
# -A16

# Set the codepage for the source file.
# Example for Windows Latin-1.
# -c1252


# -- Paths and Files --

# Add paths for the compiler to search for include files (#include <... A.I.>).
# You can specify multiple -i options. Paths with spaces must be quoted.
-i"include"
-i"third_party/amxmodx/include"

# Set a "prefix" file that will be implicitly included at the top of
# every compiled script. Useful for global constants or macros.
#-p"global_definitions.inc"

# Set the base name for the output file.
# If not set, the output name is derived from the source file name.
# -o"bin/my_plugin"

# Set the compiler's active directory.
# This affects where relative paths are resolved from.
-D"D:\MyServer\cstrike\addons\amxmodx\plugins"


# -- Preprocessor and Symbols --

# Define global preprocessor constants, similar to #define.
# A symbol with no value (e.g., "DEBUG_MODE=") defaults to 1.
DEBUG_MODE=
MAX_PLAYERS=32

@github-actions github-actions bot added the enhancement New feature or request label Sep 1, 2025
@hun1er hun1er merged commit fea732e into main Sep 1, 2025
2 checks passed
@hun1er hun1er deleted the feat/config-file branch September 1, 2025 14:20
@Nord1cWarr1or Nord1cWarr1or mentioned this pull request Sep 4, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants