santiontanon / mdlz80optimizer

MDL (a Z80 assembler optimizer)
Apache License 2.0
81 stars 6 forks source link

Include file locations in sjasmplus #34

Closed abekermsx closed 2 years ago

abekermsx commented 2 years ago

When including a file with 'include "file.asm"' Sjasmplus first searches in the current directory (the directory where the file with the include directive is located). If the file isn't found, it searches in directories specified with the --inc directive at the commandline. The Sjasmplus documentation fails to mention that if a file is still not found, it will also check the "root" directory of the assembly code.

Currently the mdlz80optimizer only checks the current directory. This probably applies to all directives where files can be specified.

ped7g commented 2 years ago

The Sjasmplus documentation fails to mention that if a file is still not found, it will also check the "root" directory of the assembly code.

https://z00m128.github.io/sjasmplus/documentation.html#po_include

To include another sourcefile into the current. Sourcefiles can be nested 20 levels deep. If the file cannot be found in the current directory (the current directory is the directory the current asm file comes from!) the file will be searched for in the directories specified at the commandline. When angle brackets are used, the commandline directories are searched before the current directory.

The directory used to launch the assembling process is automatically added to the list (as if "-i." was added to command line manually) (v1.14.0 and v1.14.1 don't add it, reverted back for v1.14.2). If you want to start with completely empty include-path list, use "--inc" option early (order matters) without the "=" to empty the current list, like: sjasmplus --inc --inc=path1 --inc=path2 file.asm

it's not root directory of project, but current working dir where you did launch sjasmplus, and it's documented. :) (at least AFAIK that documentation of INCLUDE should be correct and describe all functionality, if you find some other behaviour, that may be bug and feel free to open report in sjasmplus repository so I can take a look what's happening)

abekermsx commented 2 years ago

The directory used to launch the assembling process is automatically added to the list (as if "-i." was added to command line manually) (v1.14.0 and v1.14.1 don't add it, reverted back for v1.14.2). If you want to start with completely empty include-path list, use "--inc" option early (order matters) without the "=" to empty the current list, like: sjasmplus --inc --inc=path1 --inc=path2 file.asm

it's not root directory of project, but current working dir where you did launch sjasmplus, and it's documented. :) (at least AFAIK that documentation of INCLUDE should be correct and describe all functionality, if you find some other behaviour, that may be bug and feel free to open report in sjasmplus repository so I can take a look what's happening)

Ah ok, sorry, I didn't read carefully enough.

santiontanon commented 2 years ago

Thanks both for the clarifications! This should be fixed in commit https://github.com/santiontanon/mdlz80optimizer/commit/9c8c5d44777ef6c6453a1626f81182cd486bb534

The flag for additional includes in mdl is "-I" (like in gcc/g++), but I have also added the "-inc" option as a synonym now.

With this commit, the search order is now configurable for each dialect, and I have set the default as: 1) search in the folder where the file that contains the "include/incbin" statement is 2) the list of search paths specified with "-I"/"-inc" 3) the current working dir from where mdl was launched.

With this change, addressing the "include <...>" syntax from issue 35 should now be easy, and I'll do that next in a subsequent commit. I'll close this issue for now, but if it does not work as expected, feel free to reopen, of course :)