ksherlock / mpw

Macintosh Programmer's Workshop (mpw) compatibility layer
238 stars 21 forks source link

MWC68K and MWCPPC can't find files in include paths #56

Closed ryandesign closed 1 year ago

ryandesign commented 1 year ago

I'm trying to use Metrowerks CodeWarrior MWC68K and MWCPPC compilers with mpw emulator and I'm having trouble getting them to find include files in other directories.

I have a file main.c:

#include "foo.h"

int main(void)
{
    foo();
    return 0;
}

and in a directory "inc" I have a file foo.h:

void foo(void);

First, here's MPW's SC (version 8.8.4f1) and MrC (version 4.1.0f1c1) compilers (from MPW 3.5) handling this successfully:

% mpw SC main.c -i inc/; echo $?
0
% mpw MrC main.c -i inc/; echo $?
0

Interesting that the directory name must end with a slash, but I can deal with that.

Next, here's CodeWarrior's MWC68K and MWCPPC compilers (version 2.3, from CodeWarrior Pro 5) failing to handle it:

 % mpw MWC68K main.c -i inc/; echo $?
### MWC68K OS Error:
# Unable to resolve alias foo.h, OS error -43
### MWC68K Compiler Error:
#   #include "foo.h"
#                  ^
# the file 'foo.h' cannot be opened
#----------------------------------------------------------
File "main.c"; Line 1
#----------------------------------------------------------
# errors caused tool to abort
1
% mpw MWCPPC main.c -i inc/; echo $?
### MWCPPC OS Error:
# Unable to resolve alias foo.h, OS error -43
### MWCPPC Compiler Error:
#   #include "foo.h"
#                  ^
# the file 'foo.h' cannot be opened
#----------------------------------------------------------
File "main.c"; Line 1
#----------------------------------------------------------
# errors caused tool to abort
1

Interesting that if I specify a nonexistent include directory, MWC68K/MWCPPC prints a warning about that:

% mpw MWC68K main.c -i wrong; echo $?
### MWC68K Usage Warning:
# can't locate include directory 'wrong'
### MWC68K OS Error:
# Unable to resolve alias foo.h, OS error -43
### MWC68K Compiler Error:
#   #include "foo.h"
#                  ^
# the file 'foo.h' cannot be opened
#----------------------------------------------------------
File "main.c"; Line 1
#----------------------------------------------------------
# errors caused tool to abort
1

So since that warning is not printed when using the "inc" directory it is finding the "inc" directory but is for some reason still unable to deal with it.

MWC68K/MWCPPC is able to find include files that are in the current directory.

I tested in MPW 3.5 on a Power Mac G3 running Mac OS 9.2.2. There, the syntax appears to be that the directory name must be preceded by (and may be followed by) a colon (i.e. -i :inc or -i :inc:). There, all four compilers were able to find the include file in the directory.

Running in mpw emulator, SC and MrC also accept the -i :inc or -i :inc: syntax, but MRC68K and MRCPPC still are "Unable to resolve alias foo.h".

Toolbox trace ```sh % mpw --trace-toolbox MWC68K -i inc/ main.c a9a0 GetResource(434f4445 ('CODE'), 0000) a049 HPurge(00f7c00c) a9a0 GetResource(44415441 ('DATA'), 0000) a9a3 ReleaseResource(00f7c010) a746 GetToolTrapAddress($a89f (_Unimplemented)) a346 GetOSTrapAddress($a198 (_HWPriv)) a198 HWTrap(0001) FlushInstructionCache() a346 GetOSTrapAddress($a1ad (_Gestalt)) a746 GetToolTrapAddress($a89f (_Unimplemented)) a346 GetOSTrapAddress($a1ad (_Gestalt)) a746 GetToolTrapAddress($a89f (_Unimplemented)) a11e NewPtr(00000078) a86e InitGraf($00f5d316) a9a0 GetResource(61637572 ('acur'), 0000) -> -192 a9a0 GetResource(61637572 ('acur'), 0001) -> -192 a9a0 GetResource(61637572 ('acur'), 0002) -> -192 a346 GetOSTrapAddress($a1ad (_Gestalt)) a746 GetToolTrapAddress($a89f (_Unimplemented)) a746 GetToolTrapAddress($a89f (_Unimplemented)) a346 GetOSTrapAddress($a0ad (Unknown)) a1ad Gestalt('fold') -> -5551 a746 GetToolTrapAddress($a89f (_Unimplemented)) a346 GetOSTrapAddress($a0ad (Unknown)) a1ad Gestalt('alis') a746 GetToolTrapAddress($a89f (_Unimplemented)) a346 GetOSTrapAddress($a0ad (Unknown)) a1ad Gestalt('os ') a746 GetToolTrapAddress($a89f (_Unimplemented)) a346 GetOSTrapAddress($a0ad (Unknown)) a1ad Gestalt('alis') a11e NewPtr(00008000) a122 NewHandle(00000000) a122 NewHandle(00000000) a122 NewHandle(00000000) a122 NewHandle(00000000) a122 NewHandle(00000000) a122 NewHandle(00000000) a122 NewHandle(00000000) a122 NewHandle(00000000) a024 SetHandleSize(00f7c014, 00000014) a029 HLock(00f7c014) a02a HUnlock(00f7c014) a024 SetHandleSize(00f7c018, 0000000a) a029 HLock(00f7c018) a02a HUnlock(00f7c018) a024 SetHandleSize(00f7c01c, 0000000e) a029 HLock(00f7c01c) a02a HUnlock(00f7c01c) a024 SetHandleSize(00f7c020, 00000106) a029 HLock(00f7c020) a02a HUnlock(00f7c020) a024 SetHandleSize(00f7c024, 000001da) a029 HLock(00f7c024) a02a HUnlock(00f7c024) a024 SetHandleSize(00f7c028, 0000003e) a029 HLock(00f7c028) a02a HUnlock(00f7c028) a024 SetHandleSize(00f7c02c, 0000000e) a029 HLock(00f7c02c) a02a HUnlock(00f7c02c) a024 SetHandleSize(00f7c030, 0000000c) a029 HLock(00f7c030) a02a HUnlock(00f7c030) a975 TickCount() aa52 HighLevelHFSDispatch(0001) FSMakeFSSpec(0000, 00000000, ., 00fffb4a) a823 AliasDispatch($000c) ResolveAliasFile(/Volumes/Shared/testinc) a260 HFSDispatch(00000009, 00fffb90) PBGetCatInfo(/Volumes/Shared/testinc) a975 TickCount() aa52 HighLevelHFSDispatch(0001) FSMakeFSSpec(0000, 00000000, inc/, 00fffb2a) a823 AliasDispatch($000c) ResolveAliasFile(/Volumes/Shared/testinc/inc) a260 HFSDispatch(00000009, 00fffb70) PBGetCatInfo(/Volumes/Shared/testinc/inc) a975 TickCount() aa52 HighLevelHFSDispatch(0001) FSMakeFSSpec(0000, 00000000, main.c, 00fffc86) a823 AliasDispatch($000c) ResolveAliasFile(/Volumes/Shared/testinc/main.c) a20c GetFileInfo($00fff87a) GetFileInfo(/Volumes/Shared/testinc/main.c) a975 TickCount() a122 NewHandle(00000001) a975 TickCount() a024 SetHandleSize(00f7c034, 00000014) a025 GetHandleSize(00f7c034) -> 20 a024 SetHandleSize(00f7c014, 00000014) a069 HGetState(00f7c034) a029 HLock(00f7c034) a029 HLock(00f7c014) a02a HUnlock(00f7c014) a06a HSetState(00f7c034, 0000) a975 TickCount() a024 SetHandleSize(00f7c034, 0000000a) a025 GetHandleSize(00f7c034) -> 10 a024 SetHandleSize(00f7c018, 0000000a) a069 HGetState(00f7c034) a029 HLock(00f7c034) a029 HLock(00f7c018) a02a HUnlock(00f7c018) a06a HSetState(00f7c034, 0000) a975 TickCount() a024 SetHandleSize(00f7c034, 0000000e) a025 GetHandleSize(00f7c034) -> 14 a024 SetHandleSize(00f7c01c, 0000000e) a069 HGetState(00f7c034) a029 HLock(00f7c034) a029 HLock(00f7c01c) a02a HUnlock(00f7c01c) a06a HSetState(00f7c034, 0000) a975 TickCount() a024 SetHandleSize(00f7c034, 00000106) a025 GetHandleSize(00f7c034) -> 262 a024 SetHandleSize(00f7c020, 00000106) a069 HGetState(00f7c034) a029 HLock(00f7c034) a029 HLock(00f7c020) a02a HUnlock(00f7c020) a06a HSetState(00f7c034, 0000) a975 TickCount() a024 SetHandleSize(00f7c034, 000001da) a025 GetHandleSize(00f7c034) -> 474 a024 SetHandleSize(00f7c024, 000001da) a069 HGetState(00f7c034) a029 HLock(00f7c034) a029 HLock(00f7c024) a02a HUnlock(00f7c024) a06a HSetState(00f7c034, 0000) a975 TickCount() a024 SetHandleSize(00f7c034, 0000003e) a025 GetHandleSize(00f7c034) -> 62 a024 SetHandleSize(00f7c028, 0000003e) a069 HGetState(00f7c034) a029 HLock(00f7c034) a029 HLock(00f7c028) a02a HUnlock(00f7c028) a06a HSetState(00f7c034, 0000) a975 TickCount() a024 SetHandleSize(00f7c034, 0000000e) a025 GetHandleSize(00f7c034) -> 14 a024 SetHandleSize(00f7c02c, 0000000e) a069 HGetState(00f7c034) a029 HLock(00f7c034) a029 HLock(00f7c02c) a02a HUnlock(00f7c02c) a06a HSetState(00f7c034, 0000) a975 TickCount() a024 SetHandleSize(00f7c034, 0000000c) a025 GetHandleSize(00f7c034) -> 12 a024 SetHandleSize(00f7c030, 0000000c) a069 HGetState(00f7c034) a029 HLock(00f7c034) a029 HLock(00f7c030) a02a HUnlock(00f7c030) a06a HSetState(00f7c034, 0000) a023 DisposeHandle(00f7c034) a23c CmpString(MWCIncludes, Command) -> 1 a23c CmpString(MWCIncludes, CWCIncludes) -> 1 a23c CmpString(MWCIncludes, MWCIncludes) aa52 HighLevelHFSDispatch(0001) FSMakeFSSpec(0000, 00000000, /Users/rschmidt/mpw/3.5/Interfaces/CIncludes/, 00fffb4a) a823 AliasDispatch($000c) ResolveAliasFile(/Users/rschmidt/mpw/3.5/Interfaces/CIncludes) a260 HFSDispatch(00000009, 00fffb90) PBGetCatInfo(/Users/rschmidt/mpw/3.5/Interfaces/CIncludes) aa52 HighLevelHFSDispatch(0001) FSMakeFSSpec(0000, 00000000, main.c, 00fffe26) a823 AliasDispatch($000c) ResolveAliasFile(/Volumes/Shared/testinc/main.c) a260 HFSDispatch(00000009, 00fffa44) PBGetCatInfo(/Volumes/Shared/testinc/main.c) aa52 HighLevelHFSDispatch(0001) FSMakeFSSpec(0000, 00000000, ., 00fffe26) a823 AliasDispatch($000c) ResolveAliasFile(/Volumes/Shared/testinc) a260 HFSDispatch(00000009, 00fffa44) PBGetCatInfo(/Volumes/Shared/testinc) aa52 HighLevelHFSDispatch(0001) FSMakeFSSpec(0000, 00000004, main.c.o, 00fffe26) a975 TickCount() aa52 HighLevelHFSDispatch(0007) FSpGetFInfo(/Volumes/Shared/testinc/main.c, 00fff4fa) aa52 HighLevelHFSDispatch(0002) FSpOpenDF(main.c, 01, fff50a) open(/Volumes/Shared/testinc/main.c, 0000) a011 GetEOF(00fff4a0) a88f OSDispatch(001d) TempNewHandle(00000039, 00fff4c6) a064 MoveHHi(00f7c038) a029 HLock(00f7c038) a002 Read(00fff49c) read(0006, 00f7c300, 00000038) a001 Close(00fff4a4) a064 MoveHHi(00f7c038) a029 HLock(00f7c038) a122 NewHandle(00000006) a025 GetHandleSize(00f7c038) -> 57 a975 TickCount() a975 TickCount() a88f OSDispatch(001d) TempNewHandle(00070000, 00fff5b2) a064 MoveHHi(00f7c040) a029 HLock(00f7c040) a975 TickCount() a88f OSDispatch(001d) TempNewHandle(00020000, 00fff5aa) a064 MoveHHi(00f7c044) a029 HLock(00f7c044) a975 TickCount() a88f OSDispatch(001d) TempNewHandle(00008000, 00fff5a2) a064 MoveHHi(00f7c048) a029 HLock(00f7c048) a975 TickCount() a88f OSDispatch(001d) TempNewHandle(00008000, 00fff59a) a064 MoveHHi(00f7c04c) a029 HLock(00f7c04c) a975 TickCount() a88f OSDispatch(001d) TempNewHandle(00008000, 00fff592) a064 MoveHHi(00f7c050) a029 HLock(00f7c050) a975 TickCount() a88f OSDispatch(001d) TempNewHandle(00002710, 00fff5de) a975 TickCount() a122 NewHandle(00000100) a975 TickCount() a122 NewHandle(00005800) a064 MoveHHi(00f7c05c) a029 HLock(00f7c05c) a975 TickCount() a88f OSDispatch(001d) TempNewHandle(00000100, 00fff5e6) a975 TickCount() a88f OSDispatch(001d) TempNewHandle(00009c40, 00fff5e4) a975 TickCount() a88f OSDispatch(001d) TempNewHandle(00002710, 00fff5e4) a975 TickCount() a88f OSDispatch(001d) TempNewHandle(00001388, 00fff5e4) a975 TickCount() a975 TickCount() a11e NewPtr(00004000) a975 TickCount() a11e NewPtr(00000fa0) a975 TickCount() a11e NewPtr(00000fa0) aa52 HighLevelHFSDispatch(0001) FSMakeFSSpec(0000, 00000004, foo.h, 00fff12c) a823 AliasDispatch($000c) ResolveAliasFile(/Volumes/Shared/testinc/foo.h) -> -43 a11e NewPtr(00000190) a02e BlockMove(00f7c940, 00f7b200, 0000003c) ### MWC68K OS Error: # Unable to resolve alias foo.h, OS error -43 a9a0 GetResource(53545223 ('STR#'), 2710) a02e BlockMove(00cb04b2, 00fff06c, 0000001f) ### MWC68K Compiler Error: # #include "foo.h" # ^ # the file 'foo.h' cannot be opened #---------------------------------------------------------- File "main.c"; Line 1 #---------------------------------------------------------- a975 TickCount() a975 TickCount() a975 TickCount() a975 TickCount() a975 TickCount() a975 TickCount() a975 TickCount() a975 TickCount() a023 DisposeHandle(00f7c060) a023 DisposeHandle(00f7c064) a023 DisposeHandle(00f7c068) a023 DisposeHandle(00f7c06c) a025 GetHandleSize(00f7c03c) -> 6 a06a HSetState(00f7c038, 0000) a023 DisposeHandle(00f7c038) a023 DisposeHandle(00f7c040) a023 DisposeHandle(00f7c044) a023 DisposeHandle(00f7c048) a023 DisposeHandle(00f7c04c) a023 DisposeHandle(00f7c050) a023 DisposeHandle(00f7c054) a023 DisposeHandle(00f7c058) a023 DisposeHandle(00f7c05c) a025 GetHandleSize(00f7c03c) -> 6 a023 DisposeHandle(00f7c03c) a975 TickCount() a975 TickCount() a01f DisposePtr(00c9c000) a01f DisposePtr(00c9a000) a01f DisposePtr(00c9b000) a023 DisposeHandle(00f7c014) a023 DisposeHandle(00f7c018) a023 DisposeHandle(00f7c01c) a023 DisposeHandle(00f7c020) a023 DisposeHandle(00f7c024) a023 DisposeHandle(00f7c028) a023 DisposeHandle(00f7c02c) a023 DisposeHandle(00f7c030) # errors caused tool to abort a01f DisposePtr(00f7c200) a9a0 GetResource(44415441 ('DATA'), 0000) a9a3 ReleaseResource(00f7c074) ```
ryandesign commented 1 year ago

I notice that SC/MrC checks for foo.h in the current directory, fails to find it, then checks in inc and finds it. MWC68K/MWCPPC starts the same way but after failing to find it in the current directory it gives up; it doesn't check anywhere else.

The current directory is the implicit first directory to search. If I run MWC68K/MWCPPC with -cwd explicit -i inc to tell it to search only the directories I specify (and not to search the current directory) then it works. If I specify another bogus include directory first (-cwd explicit -i wrong -i inc) then it again only looks in the first specified directory and doesn't look in the second directory where it would have found it.

I wonder if this comment in OS::FSMakeFSSpec (in toolbox/os_highlevel.cpp) might be the reason:

// todo -- if the file does not exist (but the path is otherwise valid), create the spec but return fnfErr.