open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
958 stars 157 forks source link

Documentation update - Backslashes with wcl386 -I #662

Closed zoomosis closed 3 years ago

zoomosis commented 3 years ago

Summary:

"wcl386 -I..\foo main.c" works OK running wcl386 on Windows.

"wcl386 -I../foo main.c" does not.

TLDR:

I'd like to write a makefile that works with both the Linux & Windows of WMake.

# src/makefile

INC=-I../foo

main.obj: main.c
        wcl386 $(INC) -fo=$@ -c -bt=nt main.c

.IGNORE
clean: .SYMBOLIC
        rm main.obj
/* src/main.c */
#include "bar.h"
int main(void) { return 0; }
/* foo/bar.h */
#pragma message ("Hello from " __FILE__)

This works in Linux:

Open Watcom Make Version 2.0 beta Feb 16 2021 14:12:57 (64-bit)
Copyright (c) 2002-2021 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
        wcl386 -I../foo -fo=main.obj -c -bt=nt main.c
Open Watcom C/C++ x86 32-bit Compile and Link Utility
Version 2.0 beta Feb 16 2021 14:25:27 (64-bit)
Copyright (c) 2002-2021 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
        wcc386 main.c  -I../foo -fo=main.obj -bt=nt
Open Watcom C x86 32-bit Optimizing Compiler
Version 2.0 beta Feb 16 2021 14:16:34 (64-bit)
Copyright (c) 2002-2021 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
Hello from ../foo/bar.h
main.c: 4 lines, included 52, 0 warnings, 0 errors
Code size: 13

But the Windows version of wcl386 does not understand the forward slash passed to -I:

Open Watcom Make Version 2.0 beta Feb 16 2021 14:12:59 (32-bit)
Copyright (c) 2002-2021 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
        wcl386 -I../foo -fo=main.obj -c -bt=nt main.c
Open Watcom C/C++ x86 32-bit Compile and Link Utility
Version 2.0 beta Feb 16 2021 14:25:28 (32-bit)
Copyright (c) 2002-2021 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
        wcc386 main.c  -I../foo -fo=main.obj -bt=nt
Open Watcom C x86 32-bit Optimizing Compiler
Version 2.0 beta Feb 16 2021 14:16:42 (32-bit)
Copyright (c) 2002-2021 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
main.c(2): Error! E1055: Unable to open 'bar.h'
main.c: 4 lines, included 49, 0 warnings, 1 errors
Error: Compiler returned a bad status compiling "main.c"
Error(F38): (main.obj) does not exist and cannot be made from existing files
Error(E02): Make execution terminated

This is despite forward slashes being accepted by wcl386 in Windows elsewhere on the command-line, eg. "./main.c":

c:\xsrc\fwdslash\src>wcl386 -I..\foo -c ./main.c
Open Watcom C/C++ x86 32-bit Compile and Link Utility
Version 2.0 beta Feb 16 2021 14:25:28 (32-bit)
Copyright (c) 2002-2021 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
        wcc386 .\main.c  -I..\foo
Open Watcom C x86 32-bit Optimizing Compiler
Version 2.0 beta Feb 16 2021 14:16:42 (32-bit)
Copyright (c) 2002-2021 The Open Watcom Contributors. All Rights Reserved.
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
Hello from ..\\foo\\bar.h
.\main.c: 4 lines, included 52, 0 warnings, 0 errors
Code size: 13

And obviously forward slashes are accepted by the preprocessor in Windows when using #include <>.

Can this be fixed?

I've resorted to doing:

# src/makefile2

!ifdef __LINUX__
SEP=/
!else
SEP=\
!endif

INC=-I..$(SEP)foo

main.obj: main.c
        wcl386 $(INC) -fo=$@ -c -bt=nt main.c

.IGNORE
clean: .SYMBOLIC
        rm main.obj

It works but using $(SEP) is ugly and error-prone as the makefile grows.

Thanks!

jmalak commented 3 years ago

standard solution is

wcl386 -I"../foo"

which works on all supported platforms

zoomosis commented 3 years ago

Oh! Perfect! :)

It'd be great if this could be documented in ctools.pdf somewhere.

Thanks again.

jmalak commented 3 years ago

documentation updated