Page 1 of 1

FASM include по двум возможным адресам?

Posted: Tue Oct 05, 2021 8:36 pm
by Kolibrius
Возможно ли в FASM загрузить inc файл если он не найден по одному пути, загрузить его по другому пути.

что-то вроде этого:

Code: Select all

include '../../../macros.inc'
if varible from macros not exist
   include 'rd1/macros.inc'
endif

Re: FASM include по двум возможным адресам?

Posted: Tue Oct 05, 2021 9:00 pm
by dunkaist
The closest to what you are trying to achieve is done via 'include' environment variable, see the corresponding fasm programmer's manual section.

Re: FASM include по двум возможным адресам?

Posted: Wed Oct 06, 2021 9:22 pm
by Kolibrius
If 'include' does not find the file, it interrupts compilation and there is no way to skip error. I think solution is not exist.

Re: FASM include по двум возможным адресам?

Posted: Wed Oct 06, 2021 10:14 pm
by dunkaist
The trick (a documented one though) is to provide several paths to look for the included file.

Code: Select all

$ cat main.asm
include 'blah.inc'
display 'hi, ', NAME
db NAME

$ cat one/blah.inc
NAME equ 'Alice'

$ cat two/blah.inc
NAME equ 'Bob'

$ INCLUDE='one;two' fasm main.asm main
flat assembler  version 1.73.28  (16384 kilobytes memory, x64)
hi, Alice
1 passes, 5 bytes.

$ hexdump -C main
00000000  41 6c 69 63 65                                    |Alice|
00000005

$ INCLUDE='two;one' fasm main.asm main
flat assembler  version 1.73.28  (16384 kilobytes memory, x64)
hi, Bob
1 passes, 3 bytes.

$ hexdump -C main
00000000  42 6f 62                                          |Bob|
00000003

Re: FASM include по двум возможным адресам?

Posted: Thu Oct 07, 2021 6:37 pm
by Kolibrius
i try in asm file use include:

include "../../../macros.inc;/sys/macros.inc"

but FASM shows error:

Re: FASM include по двум возможным адресам?

Posted: Thu Oct 07, 2021 7:11 pm
by dunkaist
In my example INCLUDE='one;two' is an environment variable, and the file is included as include 'blah.inc'. Fasm can handle several paths only when they are provided in an environment variable, not after include keyword.

I see that you are using an absolute path /sys/lang.inc, i.e. you are trying to compile from KolibriOS. Well, KolibriOS doesn't support environment variables. If your aim is to be able to compile your program from both KolibriOS and Windows/Linux, then you can do as follows:
  1. Copy all the standard includes (like macros.inc and lang.inc) to the directory of the main *.asm file of your program.
  2. Include these standard includes without specifying any path, just include 'macros.inc'.
  3. Compile from KolibriOS as usual.
  4. Compile from Windows/Linux specifying INCLUDE environment variable with paths to standard includes.

Re: FASM include по двум возможным адресам?

Posted: Thu Oct 07, 2021 9:57 pm
by Kolibrius
This is way is possible but it not comfortable when it need to use environment variable.

Are there any ways to get operating system type in FASM code? Or version of FASM? Any variable?
That can able to do something like:

Code: Select all

if FASM_OS = 'Kolibri'
    include '/sys/macros.inc'     ; path for build in KOS   
else
    include '../../../macros.inc'  ; path for build in SVN 
endif
But im look documentation and FASM source code on SVN, and not find varibles for detect OS.

Re: FASM include по двум возможным адресам?

Posted: Thu Oct 07, 2021 11:30 pm
by dunkaist
Try this:

Code: Select all

FASM_OS equ KOLIBRIOS

match =KOLIBRIOS, FASM_OS {
  include 'one/blah.inc'
}

match =LINUX, FASM_OS {
  include 'two/blah.inc'
}
https://board.flatassembler.net/topic.php?t=21883

Re: FASM include по двум возможным адресам?

Posted: Sat Oct 09, 2021 10:33 pm
by dunkaist
Same approach but a bit cleaner:

Code: Select all

match =AUTOBUILD,AUTOBUILD {
  include 'one/blah.inc'
}

match =YES, AUTOBUILD {
  include 'two/blah.inc'
}
Compile from KolibriOS as usual, from Linux/Windows with -dAUTOBUILD=YES.

Re: FASM include по двум возможным адресам?

Posted: Mon Oct 18, 2021 10:01 pm
by Kolibrius
I think this is will be work...

Code: Select all

match =NOTHING,AUTOBUILD {
  include ''/sys/lang.inc'
  include ''/sys/macros.inc'
}

match =YES, AUTOBUILD {
  include 'lang.inc'
  include '../../../macros.inc'
}

Re: FASM include по двум возможным адресам?

Posted: Thu Oct 21, 2021 8:27 pm
by Ray
: [quote]is will be[/quote]
такого я ещё не видел)