asm6f icon indicating copy to clipboard operation
asm6f copied to clipboard

Makefile fixups (Cygwin vs. Windows vs. Linux)

Open koitsu opened this issue 3 years ago • 2 comments

  • Leverage $CC, as it's set by GNU make: https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
  • Detect Cygwin vs. native Windows vs. Linux better (and without shell)
  • Use $CFLAGS for compiler flags rather than hard-code them
  • Deal with rm vs. del (native Windows) better

The logic here can be confusing so I'll explain it with a chart:

Environment OS OSTYPE MSYSTEM Delete
Cygwin (Windows) Windows_NT cygwin rm -f
MSYS2 (Windows Windows_NT MINGW64 CLANG64 etc. rm -f
Windows native Windows_NT del /Q /F
FreeBSD freebsdXX.Y rm -f
Linux linux-gnu rm -f

The BSDs require GNU make (gmake) installed to use any of this (i.e. BSD make is not compatible with any of this, but that's expected).

Regarding $CC:

Assuming gcc isn't exactly safe everywhere nowadays. FreeBSD since 11.x has used clang instead of gcc (there is no gcc command), while "cc" is is a symlink to "clang", so it works fine. Thus, just rely on what GNU make defines $CC as by default; else we can override it elsewhere.

Most important:

AJ, I don't know what your development environment is like, so please test this before merging! I can't stress this enough.

I will have some more PRs coming soon that will modify further pieces of this, such as setting $CFLAGS to a very long list of warnings (and treating warnings as errors), a large PR to fix all those warnings (there are hundreds), as well as using -O2 -s to get smaller binaries and hopefully faster execution.

koitsu avatar Jan 22 '23 11:01 koitsu

I should add that the Cygwin and MSYS2 logic is correct, but might want BINARY=asm6f.exe since both environments support standard Windows binaries ending in .exe. Issue https://github.com/freem/asm6f/issues/23 indirectly points this out as well.

The OS detection portion, however, does work. (And on Linux/FreeBSD/etc. we definitely do not want binaries named asm6f.exe)

In short: to implement this correctly, I need to know a bit about your development environment. Otherwise if you want to rework this + implement it yourself using your own approach, go right ahead. :)

Either way, just do me 2 favours:

  1. Leave CC unset so that people can do things like CC=gcc make or CC=clang make to test both compilers. I do this, for example. The default value in GNU make is CC=cc. This method also works fine on FreeBSD (where gmake is required anyway).
  2. Please do use CFLAGS as demonstrated, as I will have an upcoming PR that greatly expands these flags to catch all sorts of problems (hence most of the PRs I've been submitting as of late).

koitsu avatar May 30 '23 07:05 koitsu

@freem This is now in a very good state. I have personally tested building on:

  • MSYS2 MINGW64 (gcc)
  • MSYS2 CLANG64 (Clang)
  • MSYS2 UCRT64 (gcc and Clang)
  • FreeBSD 11.x (gcc)
  • Linux (Ubuntu 22.04) (gcc)

I cannot test on "native" Windows for various reasons, but as long as it's GCC or Clang on native Windows it should (ideally) work. Obviously use of MSVC compiler will fail, but that would be a much bigger undertaking and not many people use Makefiles for such things anyway.

Please give this a try on your own dev environment and merge. Would love to get this finally closed out :)

koitsu avatar Aug 23 '23 03:08 koitsu