PCem

[Patch] MinGW Configure

[Patch] MinGW Configure

Posted: Tue 23 Jan, 2018 6:48 am

by darksabre76

Hello all, this is my first attempt at a patch for anything. This patch allows MSYS2 (and MinGW, though I have not been able to confirm this) to get past the './configure' step. This still does not allow a full "./configure && make && make install' on MSYS2/MinGW yet, but I am working toward that, because I'd love to see a more unified build guide.

Re: [Patch] MinGW Configure

Posted: Sat 27 Jan, 2018 12:41 pm

by SarahWalker

You need to modify configure.ac. configure is autogenerated when running autoreconf or autoconf, and any changes to it will get wiped out.

Re: [Patch] MinGW Configure

Posted: Sun 28 Jan, 2018 4:17 am

by darksabre76

That is something I didn't even think of. Okay then, let me take a look at that and then update the patch... at some point.

Re: [Patch] MinGW Configure

Posted: Wed 31 Jan, 2018 1:34 am

by darksabre76

Okay, I finally figured out the things with the configure.ac and makefile.am files. I was able to do "./configure --enable-networking --enable-debug && ./make" in an MSYS2 environment and it produced a working executable. I have attached it to this post.

I tried my best to make sure that this ONLY affected the Windows builds so that nothing would spill over an affect the Linux ones. I'd like to ask for some help making sure that the Linux builds and standard MinGW builds both still work with this patch. At the moment, I cannot test either of those reliably.

EDIT: Newest attachment in top post.

Re: [Patch] MinGW Configure

Posted: Wed 31 Jan, 2018 5:51 am

by shermanp

I've tried this in my MSYS2 environment, and if kind of works, but definitely still has issues.

I cloned a fresh pcem build in a separate directory to separate it from my main build, and applied the supplied patch.

'./configure' works fine and creates makefiles.

A couple of problems with the makefiles however:

First, the Makefiles have the command 'make' as their MAKE variable, whereas the MSYS2 (and I assume legacy MinGW) uses the binary 'mingw32-make'. The best solution would be to see if one can configure the MAKE variable from configure.ac.

Which fails with the following message: "mingw32-make: *** No rule to make target 'pcem', needed by '../pcem'. Stop."

Note that by this point the binary is created.

The other thing I noticed that the created binary behaves like the Linux binary, with no top menu bar, but a right-click menu instead.

Re: [Patch] MinGW Configure

Posted: Wed 31 Jan, 2018 6:27 am

by darksabre76

Hmm, interesting observations. I was sure that the regular "make" would do the right thing. Maybe it's matter of what "_WIN" or "_WIN32" variable is included. I may have to do a fresh clone and apply as well to see if my MSYS2 setup does the same. Thank you for testing this, I'd love to see if this does anything to the linux builds.

Edit: I have had no issues just saying "make" in my MSYS2 environment and having it work properly. I was also able to narrow down the UI issues to a file that I had to move into one of the switch includes like the cdrom IO. I'll try to see if I can replicate the issue with the "target pcem" you were seeing. In the mean time, can you try "make" instead of "mingw32-make"?

Re: [Patch] MinGW Configure

Posted: Wed 31 Jan, 2018 9:17 am

by shermanp

Ok, I now understand what has happened.

MSYS2 has two (or three if one is being pedantic...) distinct build environments. It has the MinGW-w64 environments (32 and 64 bit), and it has the MSYS2 build environment. The MinGW-w64 build environment has its own distinct version of make (mingw32-make), gcc and other build tools. This environment is specifically designed for compiling programs to run on Windows.

The MSYS2 environment ALSO has it's own version of gcc and autotools, including make etc. These are designed specifically for compiling programs for use in the MSYS2 shell, not for general Windows use.

What has happened is that you have installed the MSYS2 tools which are available from the MSYS2 MinGW shells. Thus, calling make "works", but it will be using the MSYS2 version of make, not the MinGW version. The same with gcc I believe.

While the above appears to build a working executable, I do not think this is advisable, and there could be some luck involved that it works...

The reason it didn't work for me, was because I did not have the MSYS2 development tools installed.

Probably the best way to test things will be to uninstall the MSYS2 development packages such as make, gcc etc. That way you will be forced to get it working using only the MinGW-w64 tools. This should also be much more likely to work with legacy MinGW environments.

Re: [Patch] MinGW Configure

Posted: Wed 31 Jan, 2018 6:17 pm

by darksabre76

Looks like just putting the ../pcem target behind conditionals for both Linux and MACOSX will do the trick. Everything compiles correctly and it doesn't complain about a target that technically exists but can't be done. Newest patch in the top post.

Re: [Patch] MinGW Configure

Posted: Thu 01 Feb, 2018 2:27 am

by shermanp

Yay! Getting closer!

First, I got it to compile using mingw32-make. There is a bit of an issue with the WX stuff. The main config window does not appear to use styling, so the appearance is flat and ugly. Also there is no icon embedded in the executable. Both of these are non-issues with the predefined mingw/msys2 makefiles. Not sure if we are missing a library, or linking in the wrong order or what.

I was able to use mingw32-make by setting the MAKE variable on the command line by doing the following:

This substitution can be made where required when checking the build environment.

Re: [Patch] MinGW Configure

Posted: Thu 01 Feb, 2018 10:57 pm

by shermanp

Ok, done some poking around and it looks like the configured Makefile is missing the WX resource files, which explains the lack of icons and themes.

Also, most of the literature I've seen states that in a MinGW environment, the WX libraries should be linked before the other libraries.

I'm going to see if I can get an autotools environment setup (in a linux VM) and see if I can make the changes to get it working.

Re: [Patch] MinGW Configure

Posted: Fri 02 Feb, 2018 1:12 am

by darksabre76

I was able to find the missing parts for the wx issues and I'm on my way to getting that working properly. I don't actually think that redefining the "MAKE" variable will actually help or hurt here, but that could be just me.

Re: [Patch] MinGW Configure

Posted: Fri 02 Feb, 2018 2:01 am

by shermanp

Redefining MAKE is useful if using an environment where 'make' is not installed, but 'mingw32-make' is. Otherwise running mingw32-make fails when the Makefile itself tries to call make.

Setting it on the command line when running ./configure does appear to work, if you don't want to change configure.ac for it. I just thought it might be a good idea to make the substitution in configure.ac to make building as seamless as possible.

Re: [Patch] MinGW Configure

Posted: Tue 06 Feb, 2018 4:55 am

by darksabre76

Busy IRL so I finally got around to posting my updated patch. It includes the MAKE redefine for Windows only (as recommended by shermanp) as well as more conditionals for wxWidgets includes.

Re: [Patch] MinGW Configure

Posted: Tue 06 Feb, 2018 5:26 am

by darksabre76

And one more update because I apparently didn't understand where the wx resource file really REALLY was included.

Re: [Patch] MinGW Configure

Posted: Tue 06 Feb, 2018 8:36 am

by shermanp

Looking good so far!

Everything works fine in Msys2 32bit. Configures and makes correctly (or at least appears to anyway!).

I tried to compile in 64-bit mode, and it failed. Nothing wrong as such, I forgot to add the pcap headers for networking. Perhaps we should check for pcap during configure time if networking is enabled?

After installing the pcap headers, pcem compiled in 64-bit mode, but it fails to start, giving a 0xc000007b error, which appears to be a generic error about 32-bit code attempting to run 64-bit code (and vice versa?). I'm not sure if it's worth the effort to troubleshoot this.

Re: [Patch] MinGW Configure

Posted: Tue 06 Feb, 2018 5:37 pm

by darksabre76

Based on other conversations I've seen, I think I remember that there were issues with 64-bit in general. Honestly, that'd be something cool to try to get working as well, but as it stands, if 32-bit MinGW is working, I call that a win. I just need to make sure that none of these changes affect MacOS or Linux builds now, since I did make so many changes to the conditional statements.

Re: [Patch] MinGW Configure

Posted: Tue 06 Feb, 2018 8:12 pm

by darksabre76

Okay, one last update that makes one of the conditionals a little cleaner. I think this will be the last one unless something broke.

Re: [Patch] MinGW Configure

Posted: Wed 07 Feb, 2018 6:45 am

by shermanp

Seems to work fine for me on MSYS2 32 bit, and Manjaro linux (64-bit).

I don't think it will work on legacy MSYS/MinGW, simply due to the fact it does not have WX available as a package. Therefore wx-config is not available in this environment. It could probably be made to work with some effort, but I personally don't think it's worth the bother.

I think legacy MSYS/MinGW users will need to continue using the specific mingw makefiles for the foreseeable future.

On the other hand, if this patch gets included with PCem, I won't have to keep updating those msys2 makefiles, which is an annoyance for everyone involved!

Re: [Patch] MinGW Configure

Posted: Thu 08 Feb, 2018 2:20 am

by darksabre76

I call that a ringing endorsement for the other affected environments

Re: [Patch] MinGW Configure

Posted: Thu 08 Feb, 2018 9:00 pm

by JosepMa

I tested the patch here and worked as expected.

The only downside is that it is quite slower than building with the Makefile file.

The reason is because the generated Makefile continuously forks "sh" and other commands (standard behaviour), which under msys2 (Windows) is quite slow.

I even tried building with make -j , and while it improved it a bit, I still had to wait seeing the CPU underused, and also Windows Defender gets in the way too to slow it down.

Build works as expected. I ran:
./configure --enable-release-build --enable-networking
make -j

Re: [Patch] MinGW Configure

Posted: Fri 09 Feb, 2018 8:57 pm

by shermanp

The handmade Makefiles I was using with MSYS2 was almost as slow from my experience.

Also with mingw32-make, I believe its better to explicitly set -j <n>.

Although I just started a compilation and checked task manager and oh my, I see what you mean by Windows Defender!

Re: [Patch] MinGW Configure

Posted: Sat 10 Feb, 2018 11:30 am

by SarahWalker

Committed at rev 1020.

Re: [Patch] MinGW Configure

was commented out. I don't think I submitted the patch with that commented, but if I did, then I messed up. That line ensures that MinGW/MSYS2 doesn't look in the local folder first for a few things like io.h. Otherwise, compilation fails at 808x.c due to it finding io.h in the local folder before the system folder... but only on Windows. It's funny like that.

Re: [Patch] MinGW Configure

Posted: Sun 11 Feb, 2018 3:46 pm

by SarahWalker

That's my bad, sorry - I commented it out during testing, and forgot about it. Fixed at rev 1028.

Re: [Patch] MinGW Configure

Posted: Mon 12 Feb, 2018 12:44 am

by ruben_balea

Good job, now it works perfectly under MSYS2
I ran the following commands to get a fresh executable:

And about the speed for me it seems that MSYS2 was always slowest than regular MINGW for almost everything.
Anyway the full process isn't desperating, I tried it on my computer with max power saving enabled and it took just 6 minutes and 46 seconds. As a comparison while in this mode it can emulate only up to a Pentium 66 at full speed.

Re: [Patch] MinGW Configure

Posted: Mon 12 Feb, 2018 1:16 am

by shermanp

Yeah, if you want speed, MSYS2 is not the way to go.

It is however far more convenient to get started. All the libraries and headers required (except for pcap headers) are available from the MSYS2 repository. There is no need to try and figure out which files go where, especially with wxWidgets.

Also, using the automake generated makefiles should in theory be able to detect modifications to source code, and only compile necessary changes. I haven't tested this yet however.

Re: [Patch] MinGW Configure

Also, using the automake generated makefiles should in theory be able to detect modifications to source code, and only compile necessary changes. I haven't tested this yet however.

I've tried this out and it seems to work by just doing the mingw32-make step each time. If there were issues, it seemed to run configure again automatically and only a few files had to be recompiled. I can't say this is a definite thing, but at least for a couple tests on my end, it worked.

Re: [Patch] MinGW Configure

It is however far more convenient to get started. All the libraries and headers required (except for pcap headers) are available from the MSYS2 repository. There is no need to try and figure out which files go where, especially with wxWidgets.

Also, using the automake generated makefiles should in theory be able to detect modifications to source code, and only compile necessary changes. I haven't tested this yet however.

I must say I have no complaints at all about MSYS2, I simply wanted to confirm that it can be noticeably slower than Mingw.
But on the other hand MSYS2 is by far much easier to manage, I almost went crazy to set up wxWidgets on Mingw.

For both MSYS2 and Mingw the path where you downloaded PCem sources must be all in English characters or compilation will fail.

Re: [Patch] MinGW Configure

Posted: Mon 12 Feb, 2018 8:47 pm

by jznomoney

This patch stopped working when the patch https://bitbucket.org/pcem_emulator/pce ... af0cafce70 . It keeps coming up
pcem-model.o:model.c:(.text+0xf3d): undefined reference to `sl82c460_init'
pcem-model.o:model.c:(.text+0x11fd): undefined reference to `acc2036_init'
If I use a prebuild Makefile it works fine but I can no longer
./configure --enable-networking --enable-release-build
mingw32-make -j