Author Topic: Compiling a PM sample with GCC  (Read 38071 times)

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4711
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #15 on: March 30, 2022, 09:26:00 pm »
Hi. I don't have as.exe, on which rpm package it is located?
"yum whatprovides" is not working for me right now, the server is giving me some errors.

cmd.exe gave me the same error.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4711
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #16 on: March 30, 2022, 09:33:51 pm »
Hi

It worked in my other environment. It build the exe and I can see the animation on the icon box.

I just want to know which package contains "as.exe" just to try it out on the other VM, and document it. 

Quote

Operating System/2 Program Maintenance Utility

Version 4.00.001 Oct  4 2001

Copyright (C) IBM Corporation 1988-2001

Copyright (C) Microsoft Corp. 1988-1991

All rights reserved.

   gcc -Zomf -c -O2 walker.c -o walker.obj
   rc -r walker.rc
Operating System/2 Resource Compiler
Version 4.00.011 Oct 10 2000
(C) Copyright IBM Corporation 1988-2000
(C) Copyright Microsoft Corp. 1985-2000
All rights reserved.


Creating binary resource file walker.RES
RC:  RCPP -E -D RC_INVOKED -W4 -f walker.rc -ef C:\OS2\RCPP.ERR -I C:\usr\include\os2tk45 -I C:\usr\include\os2tk45\inc -I C:\usr\include\os2tk45\gl -I C:\usr\include\os2tk45

walker.rc
   gcc -Zomf walker.obj walker.def -o walker.exe
Warning! W1058: file ldH89pwk.: line(20): protmode option not valid for an OS/2 EMX executable
   rc walker.res
Operating System/2 Resource Compiler
Version 4.00.011 Oct 10 2000
(C) Copyright IBM Corporation 1988-2000
(C) Copyright Microsoft Corp. 1985-2000
All rights reserved.


Reading binary resource file walker.res


Writing resources to OS/2 v2.0 Linear .EXE file
Writing 1 DEMAND resource object(s)
  Writing:  5552 bytes in 2 page(s)
    1.1 (1388 bytes)
    2.1 (1388 bytes)
    3.1 (1388 bytes)
    4.1 (1388 bytes)
Writing Extended Attributes:  Default Icon
Writing Extended Attributes:  Checksum

Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #17 on: March 30, 2022, 09:55:34 pm »
Binutils I guess if GCC didn't include it. Installing GCC should really pull in the binutils and libc-devel

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4711
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #18 on: March 30, 2022, 10:18:49 pm »
Hi
I had updated the readme files and comments on the files, and put a very liberal license since it is sample source code. I will upload this version to hobbes if there is no more comments .

Regards.
« Last Edit: March 30, 2022, 10:21:18 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #19 on: March 30, 2022, 10:55:59 pm »
Drop the C_INCLUDE_PATH stuff, it is not needed and will confuse people. While after dropping the C_INCLUDE_PATH line in the compile.cmd, it is not really needed as it should just compile. Perhaps mention the 2&1 tee make.log in the readme under trouble shooting tips or such.
Perhaps change the first line in the makefile to read something like # nmake makefile for those who don't read the readme and start out using gmake.
Might as well remove the protmode line in the def file too.
Thanks

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #20 on: March 30, 2022, 11:17:42 pm »
BTW, it is good practice when using C_INCLUDE_PATH to end it with ;%C_INCLUDE_PATH% in case it has already been set somewhere like if you set up the environment for a different GCC such as Paul's releases.
Same with CPLUS_INCLUDE_PATH and LIBRARY_PATH
As an example, I compiled PMwalker with GCC 9.4.0, part of my environment, (@unixroot=W:)
Code: [Select]
[H:\tmp\PMwalker]set C_INCLUDE_PATH
C_INCLUDE_PATH=W:/USR/local940/lib/gcc/i386-pc-os2-emx/9.4.0/include;W:/USR/local940/include;W:/USR/include;%C_INCLUDE_PATH%;

[H:\tmp\PMwalker]set CPLUS_INCLUDE_PATH
CPLUS_INCLUDE_PATH=W:/USR/local940/include/c++/9.4.0;W:/USR/local940/include/c++/9.4.0/i386-pc-os2-emx;W:/USR/local940/include/c++/9.4.0/backward;W:/USR/local940/include;W:/USR/include;%CPLUS_INCLUDE_PATH%;

[H:\tmp\PMwalker]set LIBRARY_PATH
LIBRARY_PATH=W:/USR/local940/lib/gcc/i386-pc-os2-emx/9.4.0;W:/USR/local940/lib;W:/USR/lib;%LIBRARY_PATH%;

[H:\tmp\PMwalker]gcc --version
gcc (GCC) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4711
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #21 on: March 31, 2022, 06:01:13 pm »
Thanks Dave, Lars

I learned that gcc does not work with the OS/2 toolkit header files, and that the "os2tk45" package is not the right one, it is "libc-devel" for those files.

I'm uploading here the changes to the sample with the comments suggested by Dave. Later I will upload it to hobbes if there is no any additional change.

Maybe in the future I will try the same sample with gmake and some other PM samples with gcc.

Regards
« Last Edit: March 31, 2022, 06:05:49 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Lars

  • Hero Member
  • *****
  • Posts: 1271
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #22 on: March 31, 2022, 11:32:50 pm »
Hi Martin,

just as a side note: for a 32-bit application, the HEAPSIZE keyword in the DEF file is completely superfluous (it has no effect for 32-bit applications). But it won't hurt either, it will just be ignored by any 32-bit linker. It is a remnant of 16-bit linkers (and the original source code dates back to 16-bit times).

The STACKSIZE keyword however is relevant. 8 kBytes is very small stack for a PM application. It's obviously ok for this application but it should definitely be bigger for a "normal sized" PM application. Maybe 64 kByte would be a better choice.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #23 on: April 01, 2022, 03:06:05 am »
Hi Martin, looks good. Unless you'd rather have a Gnu makefile, upload it.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4711
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #24 on: April 01, 2022, 04:12:54 am »
Hi Martin,

just as a side note: for a 32-bit application, the HEAPSIZE keyword in the DEF file is completely superfluous (it has no effect for 32-bit applications). But it won't hurt either, it will just be ignored by any 32-bit linker. It is a remnant of 16-bit linkers (and the original source code dates back to 16-bit times).

The STACKSIZE keyword however is relevant. 8 kBytes is very small stack for a PM application. It's obviously ok for this application but it should definitely be bigger for a "normal sized" PM application. Maybe 64 kByte would be a better choice.

Hi Lars

Do you mean to put the DEF file like this?
Quote
; WALKER defintion file

NAME            WALKER  WINDOWAPI

DESCRIPTION     'Walker utility, 2022'
STACKSIZE       64512
EXPORTS         ClientWndProc

It keeps compiling and working here.
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #25 on: April 01, 2022, 06:29:15 am »
Hi Martin, the stack should probably be an even hex number, in this case 64k equals 65536 or 0x10000H.
There's other ways to set the stack size such as the -Zstack option, -Zstack 0x2000 gives 8MB stack. I usually just go with the default, which is pretty big now a days, though I can't remember how big. In the EMX days it was on the small side.
Generally executables don't need a def file, though they are handy for adding bldlevel info and in the case of a PM app like this, the WINDOWAPI forces it to be a PM app rather then cmd line. It is possible to morph into a PM app as well, you end up with a console window along the PM window.
I think a lot of this def file is from the 16 bit days and can be simplified to,
Code: [Select]
; WALKER defintion file

NAME            WALKER WIDOWAPI

DESCRIPTION     'Walker utility (C) Lee S. Fields, 1989'

or better, something like,
Code: [Select]
; WALKER defintion file

NAME            WALKER WINDOWAPI

DESCRIPTION     '@#OS2World:4.00#@##1## 31 Mar 2022 21:17:32     ARCAOS-444::::::v4.0@@Moving icon test program'

Which gives,

Code: [Select]
H:\tmp\PMwalker>bldlevel walker.exe
Build Level Display Facility Version 6.12.675 Sep 25 2001
(C) Copyright IBM Corporation 1993-2001
Signature:       @#OS2World:4.00#@##1## 31 Mar 2022 21:17:32     ARCAOS-444::::::v4.0@@Moving icon test program
Vendor:          OS2World
Revision:        4.00
Date/Time:       31 Mar 2022 21:17:32
Build Machine:   ARCAOS-444
FixPak Version:  v4.0
File Version:    4.0
Description:     Moving icon test program

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4711
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #26 on: April 01, 2022, 02:30:56 pm »
Thanks, I was wondering where to add the bldlevel stuff.

I had updated the release. With the changes on the DEF file, it keeps compiling.
What happens if I had removed the "STACKSIZE" and keep compiling it as "gcc -Zomf" without the "-Zstack ", what stacksize does it assign?

More questions. Will it be recommended to use GNU make instead of nmake? Maybe trying to focus on compiling with more open source tools. Will it be better to use cmake?

Regards
« Last Edit: April 01, 2022, 03:32:56 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #27 on: April 01, 2022, 04:28:05 pm »
From the GCC 3.3.5 changelog,
Code: [Select]
2005-08-21: knut st. osmundsen <bird-gccos2-spam@anduin.net>
    - emxbind, emxomfld:
        o Default stack size set to 1MB.
          The old defaults were 8MB (emxbind) and 8KB (emxomfld).
Not sure if Bitwise changed it since.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4787
  • Karma: +99/-1
    • View Profile
Re: Compiling a PM sample with GCC
« Reply #28 on: April 01, 2022, 04:50:43 pm »
More questions. Will it be recommended to use GNU make instead of nmake? Maybe trying to focus on compiling with more open source tools. Will it be better to use cmake?

Regards

Cmake is probably overkill, plus I don't know it much.
Converting the makefile to GNU make.
Make uses tabs for separators so change the spaces to a tab and it almost works, with a simple make command ending with,
...
Code: [Select]
Writing Extended Attributes:
Default Icon
Writing Extended Attributes:  Checksum
gcc     walker.c walker.exe   -o walker
ld.exe: malformed input file (not rel or archive) walker.exe
make: *** [walker] Error 1

make walker.exe works. Seems GNU make helpfully creates a minimal compile rule for walker.
Changing the line "walker : walker.exe" to "all : walker.exe" fixes that.
make clean fails as GNU make is using sh.exe as a shell. Can change the shell (set MAKESHELL=cmd.exe) or use rm -rf which seems better, so we get this (comments need updating)
Code: [Select]
# nmake makefile
#
# Tools used:
#  Compile::Resource Compiler
#  Compile::GNU C
#  Make: nmake
all : walker.exe

walker.exe : walker.obj walker.res walker.def
        gcc -Zomf walker.obj walker.def -o walker.exe
        rc walker.res

walker.obj : walker.c walker.h
        gcc -Zomf -c -O2 walker.c -o walker.obj

walker.res : walker.rc step1.ico step2.ico step3.ico
        rc -r walker.rc

clean :
        rm -rf *exe *RES *obj

Now the makefile works with GNU make and still works with nmake. Remember those are tabs rather then a bunch of spaces.


Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4711
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC
« Reply #29 on: April 01, 2022, 05:54:09 pm »
Thanks Dave.
It worked for me with GNU Make 3.81 k2 (2017-11-10), that's the last one for OS/2, right?

I'm attaching the changes.

Regards
« Last Edit: April 01, 2022, 05:57:20 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.