I have spent hours trying to figure out how to get conditional include paths functional in CA65 (or really, any conditional string values at all). Is it even possible?
What I want is to be able to define a constant string (which has to be a
.DEFINE due to limitations in CA65) that is the path exclusively for configuration includes for a reusable library. I cannot find a way to define these values via the command line (the
-D VALUE=123 format does not work for strings since it uses the standard
VALUE = 123 format), nor have I found a way to detect if a .DEFINE has already been defined in the actual .inc/.asm/.s files via
.DEFINEDMACRO or any other means to use a default config directory or error if it wasn't specified.
For example, assume my structure is:
MyFile.asm Config/String.inc Library/String.asm Library/Config/String.inc
In this example,
Config/String.inc is my custom configuration file that I want
Library/String.asm to use. However, I want to be able to add code to
Library/String.asm to set the configuration directory to
Config/ OR output a fatal error and immediately exit if a configuration directory is not defined. Since I have not figured out a way to pass the directory and also detect it, I can only currently just blindly use the configuration directory constant/macro (which, if not used, outputs a crap-ton of errors due to the missing include) or hard-code it to use a specific directory, which is definitely not ideal.
How do I set it up so my files can include library files and override the path for them (or have a fatal error) for including config files?
If I use:
.DEFINE CONFIGPATH "../Config/" .IFNDEF CONFIGPATH .FATAL "This always happens" .ENDIF
2: Error: Identifier Expected 1: Note: Macro was defined here 2: Error: Unexpected trailing garbage characters 1: Note: Macro was defined here Fatal error: User error: This always happens
If I use:
.DEFINE CONFIGPATH "../Config/" .IF .NOT .DEFINEDMACRO(CONFIGPATH) .FATAL "This always happens" .ENDIF
2: Error: Identifier Expected 1: Note: Macro was defined here Fatal error: User error: This always happens
If I try to use a macro:
.MACRO INCLUDECONFIGFILE includefile .INCLUDE .CONCAT("../Config/", .STRING(includefile)) .ENDMACRO
CA65 just immediately runs the .INCLUDE, even if I never use the macro, and complains about an invalid string parameter since includefile doesn't actually exist at that point. I can actually detect this macro with
.DEFINEDMACRO, but that does me no good since it doesn't work.
Trying to use a standard macro to just output a string also doesn't work.
Am I missing something?