English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 04 July 2020, 16:00   #1
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Include file path priorities for assemblers

Let's assume your shell is in the current work directory, called "cwd". When I assemble a source text in "cwd/pathto/source.asm", from where would you expect that an include-file referenced by
        include "incfile.i"

is taken?
From "cwd/incfile.i" or from "cwd/pathto/incfile.i"? Remember, the assembler is called from "cwd" and there is no include-path specified.

There was a bug in vasm's last release and I'm trying to do it correctly now.
phx is offline  
Old 04 July 2020, 16:12   #2
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
I would like it to be fetched from both positions : if first one is not found, try the other.
The order does not seem important.
meynaf is offline  
Old 04 July 2020, 16:13   #3
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Quote:
Originally Posted by meynaf View Post
The order does not seem important.
It is important if a file with this name is in both locations, with different contents.
thomas is offline  
Old 04 July 2020, 16:30   #4
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Yes, order may be important. That was also the bug in the last release. Then I fixed it by reading from the "compile-directory" only, which means "cwd/pathto" in this case. But today I noticed that I have sources which expect include files in "cwd" to be found.

So there are the following possibilities:

1. Read from cwd/pathto only.
2. Read from cwd only.
3. Read first from cwd/pathto, then from cwd when missing.
4. Read first from cwd, then from cwd/pathto when missing.

Of course, there may also be further include paths, specified by -I option or "incdir" directive, which have to be searched before or after the path from above. This is also still undecided.

EDIT: Usually I would check some other Amiga assemblers for comparison, but I'm currently on holiday and my selection of assemblers is quite limited...

Last edited by phx; 04 July 2020 at 16:32. Reason: Addition
phx is offline  
Old 04 July 2020, 17:14   #5
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
Usually, I use "incdir" directives in PhxAssGUI, and never had that problem yet. But I would prefer to try "pathto/" first and "cwd" only as second.

Btw, is there a rule that "pathto" has to be a subdir or relative to "cwd"? Would an absolute path cause a failure?
PeterK is offline  
Old 04 July 2020, 17:22   #6
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by thomas View Post
It is important if a file with this name is in both locations, with different contents.
What i meant with the order being unimportant, is that this decision in the asm isn't very sensitive. You will always find situations in which the order would have been better the other way...

Anyway, thinking about it i'd prefer current directory first, then path to the source itself. This way it becomes possible to put default files in source dir, then override them with other files from current dir (you can have as many dirs as you want, each one with a different version).
meynaf is offline  
Old 04 July 2020, 18:46   #7
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by PeterK View Post
Btw, is there a rule that "pathto" has to be a subdir or relative to "cwd"? Would an absolute path cause a failure?
An absolute path is unambigious and references one specific file. This will always work.

Usually you don't want absolute paths in your source, because you might want to assemble it on a different machine at some point.

Quote:
Originally Posted by meynaf View Post
Anyway, thinking about it i'd prefer current directory first, then path to the source itself. This way it becomes possible to put default files in source dir, then override them with other files from current dir
Strange. I would tend to prefer what PeterK said: first look into cwd/pathto, where my source is, and then look in cwd. For a similar reason as you mentioned: to override the default in cwd with source-specific headers in the source-directory.

Devpac seems to confirm that. I just found Devpac on an E-UAE file system. Devpac checks cwd/pathto first, then cwd.

PhxAss, on the other hand, only looks in cwd.
phx is offline  
Old 04 July 2020, 19:41   #8
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
Quote:
Originally Posted by phx View Post
An absolute path is unambigious and references one specific file. This will always work.

Usually you don't want absolute paths in your source, because you might want to assemble it on a different machine at some point.
The Compiler (PhxAssGUI, PhxAss) and its include files are in a directory on my SYS: partition and it seems that this is also the "CWD", but all my source code is in project drawers on another disk and all the OS includes are somewhere else with an Assign "INCLUDE:".

I think that PhxAssGUI loads my "source.asm" from an absolute project path, but without a ChangeDir (couldn't see that in SnoopDos) and so "CWD" stays in the PhxAss program directory.

I must admit, I've never written my own include files, but if I had a file "source.i" at the same location where "source.asm" was loaded from would an "include source.i" try to load it from the project drawer or from the program directory (CWD)?

Tested it: PhxAss looks into its program dir (CWD) and the /include subdir and then into INCLUDE:, but never into the project drawer where "source.asm" was loaded from. That's where I would like to see it searching first.

Last edited by PeterK; 04 July 2020 at 19:59.
PeterK is offline  
Old 04 July 2020, 20:00   #9
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by PeterK View Post
The Compiler (PhxAssGUI, PhxAss) and its include files are in a directory on my SYS: partition and it seems that this is also the "CWD"
Yes. Most likely.

Quote:
I think that PhxAssGUI loads my "source.asm" with an absolute path, but without a ChangeDir
Correct. The assembler should not change your CWD.

Quote:
if I had a file "source.i" at the same location where "source.asm" was loaded from would an "include source.i" try to load it from the project drawer or from the program directory (CWD)?
As I mentioned in the last reply PhxAss unfortunately only looks in the CWD when you specified a relative path. So you would need an INCDIR directive or option. Devpac would do what you want.


Regarding vasm: I hope I fixed everything for the next release. Here the search priority is now:
  1. Path where the source text is located.
  2. Current Work Directory.
  3. Paths defined by -I options on the command line.
  4. Paths defined by INCDIR.
phx is offline  
Old 04 July 2020, 20:11   #10
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by phx View Post
Strange. I would tend to prefer what PeterK said: first look into cwd/pathto, where my source is, and then look in cwd. For a similar reason as you mentioned: to override the default in cwd with source-specific headers in the source-directory.
That means source dir does not contain all the necessary files to assemble the code and there is no incdir of any sort to fetch includes. Looks weird to me.
On the other hand, if you have a mysource.s using myinclude.i and both are in source dir, good luck to try another version of that include without copying files if source dir prevails.


Quote:
Originally Posted by phx View Post
Devpac seems to confirm that. I just found Devpac on an E-UAE file system. Devpac checks cwd/pathto first, then cwd.
Devpac being an integrated environment, source dir is more meaningful than current dir. Rare are people who will use it as a command-line asm.


Quote:
Originally Posted by phx View Post
PhxAss, on the other hand, only looks in cwd.
It does not need to do otherwise. PhxAss has PHXOPTIONS config file which can contain
incpath
. This does the job nicely.
meynaf is offline  
Old 05 July 2020, 00:45   #11
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by meynaf View Post
That means source dir does not contain all the necessary files to assemble the code and there is no incdir of any sort to fetch includes. Looks weird to me.
The base directory may contain some general files, and the sub-directories the specialised ones, which still include files from the base.

As you said yourself you will always find situations where one or another order seems better. So the best I can do is to follow the behaviour of other assemblers. And Devpac is often a good choice.
phx is offline  
Old 05 July 2020, 14:06   #12
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
As I understand meynaf's comment, he wants to be able to replace some sort of "sourceproperties.i" of a ported source code, which may depend on the original environment, target system or being compiler specific, by his own local preferences without editing "sourceproperties.i".

That could be a reason to look into "CWD" first, but if there is such an include file coming together with the source, will it still compile correctly if you ignore it silently and use your own substitute?
PeterK is offline  
Old 05 July 2020, 21:21   #13
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by PeterK View Post
That could be a reason to look into "CWD" first
True. But you can find these reasons for both variants.

Quote:
but if there is such an include file coming together with the source, will it still compile correctly if you ignore it silently and use your own substitute?
Depends on the completeness of your substitute, I guess. I'm not sure what you want to say.

Unfortunately there is still no option to define an include path which has higher priority than the CWD or the source-directory. This can be a problem.

I just checked Devpac again, and an include path specified with INCDIR on the command line has lower priority, just like in vasm. And also in PhxAss an INCPATH option will not take priority over CWD. So... I won't change that.
phx is offline  
Old 05 July 2020, 21:35   #14
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
I'm sure you will make the right decision, although I'm still not a vasm user.
PeterK is offline  
Old 06 July 2020, 08:42   #15
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by phx View Post
The base directory may contain some general files, and the sub-directories the specialised ones, which still include files from the base.
Usually in this case there is some "include" directory in the tree, and some kind of incdir somewhere as well.
In addition, it is usually a good practice to avoid having files with exact same name in a project.
Anyway, if we have a naming conflict we can't resolve, source in the subdir could include subdir/inc.i instead of just inc.i if there is another inc.i in the root dir.


Quote:
Originally Posted by phx View Post
As you said yourself you will always find situations where one or another order seems better. So the best I can do is to follow the behaviour of other assemblers. And Devpac is often a good choice.
So if first one makes a mistake, all others must replicate it ?
I'd say that if the two options are valid, the answer is : make it configurable. You already know how to behave in Devpac compatibility mode. Same in Phxass mode, probably.


Quote:
Originally Posted by PeterK View Post
As I understand meynaf's comment, he wants to be able to replace some sort of "sourceproperties.i" of a ported source code, which may depend on the original environment, target system or being compiler specific, by his own local preferences without editing "sourceproperties.i".
Another example : let's say we have some program using ym2149.i (i do really have such file ). Now we write another ym2149.i using better - but untested - algorithm. We don't want to replace our old lib before this new one works fully. So we want to test it, and thus we go in the dir it is located, and attempt to assemble our program from there. Now if cwd/pathto prevails, no way we can do that without renaming or copying files around.


Quote:
Originally Posted by phx View Post
I just checked Devpac again, and an include path specified with INCDIR on the command line has lower priority, just like in vasm. And also in PhxAss an INCPATH option will not take priority over CWD. So... I won't change that.
If the option is for global, reusable includes, then it must have lower priority.
But there are probably other cases...
meynaf is offline  
Old 06 July 2020, 11:20   #16
PeterK
Registered User
 
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
Quote:
Originally Posted by meynaf View Post
Another example : let's say we have some program using ym2149.i (i do really have such file ). Now we write another ym2149.i using better - but untested - algorithm. We don't want to replace our old lib before this new one works fully. So we want to test it, and thus we go in the dir it is located, and attempt to assemble our program from there. Now if cwd/pathto prevails, no way we can do that without renaming or copying files around ...
I have no Yamaha sound chip for experiments here, but I prefer to make a complete backup copy of a source before I start editing it in place. Better you have a copy of the sound chip, too.

Yes, an option for the priority of the includes could be a solution.
PeterK is offline  
Old 06 July 2020, 11:54   #17
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by PeterK View Post
I have no Yamaha sound chip for experiments here, but I prefer to make a complete backup copy of a source before I start editing it in place. Better you have a copy of the sound chip, too.

Yes, an option for the priority of the includes could be a solution.
Actually the include file - which contains code for the emulation of said sound chip so you don't need it for experiments - is located in a path every program can access (PhxAss INCPATH in config). So all my ST ports can use same chip emulation. Testing another way just needs putting the new version in current dir.
But Vasm does not have INCPATH so the choice of priorities is perhaps more important for it - having it as an option would address all cases.
meynaf is offline  
Old 06 July 2020, 21:30   #18
Antiriad_UK
OCS forever!
 
Antiriad_UK's Avatar
 
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 418
Quote:
Originally Posted by phx View Post
Let's assume your shell is in the current work directory, called "cwd". When I assemble a source text in "cwd/pathto/source.asm", from where would you expect that an include-file referenced by
        include "incfile.i"

is taken?
From "cwd/incfile.i" or from "cwd/pathto/incfile.i"? Remember, the assembler is called from "cwd" and there is no include-path specified.

There was a bug in vasm's last release and I'm trying to do it correctly now.
I’d expect it to read from cwd/pathto. I.e everything is relative from the file being assembled rather than what the shell working directory is. If not found then check the folder specified in the -I option.

It gets more confusing when including a file within a file because then the nested included file only looks in the first include local folder. For example I included your pro tracker player from another file in a different folder and it couldn’t find the custom.i include.

I think my assumptions are this way due to working in C in visual studio where it works like this. But of course it could just be that that environment is changing shell folder before compiling each file.
Antiriad_UK is offline  
Old 07 July 2020, 13:28   #19
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by meynaf View Post
Testing another way just needs putting the new version in current dir.
Exactly. The current work directory, or source directory, has priority over all other include paths. That's what you would expect and that's how all assemblers work (also PhxAss and vasm).

The only difference between PhxAss and vasm is PhxAss' inability to search for include files relative to the source directory, when it doesn't match CWD.

Quote:
But Vasm does not have INCPATH so the choice of priorities is perhaps more important for it
The command line option is called -I and does the same. Or are you refering to INCPATH from the PHXOPTS environment? The only advantage is that you don't have to specify it on the command line. But what are Makefiles for?

Quote:
Originally Posted by Antiriad_UK View Post
I’d expect it to read from cwd/pathto. I.e everything is relative from the file being assembled rather than what the shell working directory is.
Agreed. That's what vasm implements now.

Quote:
If not found then check the folder specified in the -I option.
Yes. But only after checking all paths relative to the CWD (in case relative to the source-directory fails).

Quote:
It gets more confusing when including a file within a file because then the nested included file only looks in the first include local folder.
I wouldn't want to change that behaviour. Might cause some surprises.
phx is offline  
Old 07 July 2020, 15:01   #20
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by phx View Post
Exactly. The current work directory, or source directory, has priority over all other include paths. That's what you would expect and that's how all assemblers work (also PhxAss and vasm).
Hopefully global include paths don't take over, it could sometimes have been very annoying


Quote:
Originally Posted by phx View Post
The only difference between PhxAss and vasm is PhxAss' inability to search for include files relative to the source directory, when it doesn't match CWD.
Well, there is still the incpath option from the command line to cover that case.

In most cases work dir and source dir are the same. I don't have a single project that needs to specify a subdir in the command. I could, however, have some sources included in main one, that are in a subdir.


Quote:
Originally Posted by phx View Post
The command line option is called -I and does the same. Or are you refering to INCPATH from the PHXOPTS environment?
I was referring to
INCPATH
taken from
ENV:PhxAss/PHXOPTIONS
.


Quote:
Originally Posted by phx View Post
The only advantage is that you don't have to specify it on the command line.
Which is quite a great advantage for me. I get into the dir, type
phxass source.s
, work done. Or i just double-click the .s and type
phxass
before it...


Quote:
Originally Posted by phx View Post
But what are Makefiles for?
Makefiles are for C.

I have written many small tools (50+) that are single source over the years (for decode, extract, test, things like that) ; a makefile for each would be overkill.


Quote:
Originally Posted by Antiriad_UK View Post
It gets more confusing when including a file within a file because then the nested included file only looks in the first include local folder.
Quote:
Originally Posted by phx View Post
I wouldn't want to change that behaviour. Might cause some surprises.
Wait, are you saying that if i
include somedir/othersource.s
and that this second source includes something, the asm won't look in this second file's dir ?

And now the situation becomes more complicated because you can have a whole tree of directories : a.s includes b/c.s, c.s includes d/e.s, and e.s includes f.s so where could f.s possibly fetch its files ? Could be current dir (command line), dir of a.s, b/ (dir of c.s), b/d/ (dir of e.s), etc.
It looks to me as if considering the source's dir is like opening a can of worms...
meynaf is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
C Include file with hardware registers sparhawk Coders. General 4 20 November 2019 20:59
Picasso iV ROM file path PeterK support.WinUAE 11 01 April 2018 02:00
Use file requester to specify path in Shell? Foebane support.Apps 5 01 January 2017 15:32
Macro68k compatible cross assemblers kamelito Coders. Asm / Hardware 3 28 October 2015 10:38
NDK 3.1 Include file problem. Thorham Coders. General 4 04 February 2011 20:58

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 15:55.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.19154 seconds with 15 queries