-
Notifications
You must be signed in to change notification settings - Fork 484
Make the build logic more robust for BSD systems #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
makefile_include.mk
Outdated
|
|
||
| ifeq ($(CC),cc) | ||
| ifeq ($(origin CC),default) | ||
| ifneq (,$(shell echo $$"\#ifdef __clang__\nCLANG\n\#endif\n" | $(CC) -E - | grep CLANG)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhm, this creates the following for me:
$ make
<stdin>:3:2: error: #endif without #if
...
$ gcc -dumpversion
5.4.0
$ cc -dumpversion
5.4.0
$ clang -dumpversion
4.2.1
Ubuntu Xenial-based distro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, I can reproduce that on Elementary OS, which is based on Ubuntu 16.04. Interestingly the problem seems to be with the string escaping. On FreeBSD, the $$" is required, otherwise piping to $(CC) -E fails with "error: unterminated conditional directive." On Linux, it appears that the $$" is what's messing it up...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add to the confusion, macOS, which uses Clang as the default compiler, seems to be fine both with and without $$. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that be an option?
-ifneq (,$(shell echo $$"\#ifdef __clang__\nCLANG\n\#endif\n" | $(CC) -E - | grep CLANG))
+ifneq (,$(shell $(CC) --version | grep -i clang))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem there is that Clang's version info doesn't tell you it's Clang on every platform. For example, Clang on macOS calls itself "Apple LLVM."
I was chatting with a colleague about the $$ conundrum and he said that it stems from the fact that shell in a Makefile refers to a different shell on different systems, and that it's always POSIX sh on FreeBSD and dash on Ubuntu. While an interesting tidbit, it doesn't provide an immediate solution. 😉
I think the easiest way forward here would be to put the check in a file, e.g. just make a file containing
#ifdef __clang__
CLANG
#endifand in the Makefile call $(shell $(CC) -E file | grep CLANG). The downside of that of course is then there's just some annoying little file sitting floating around in the source tree...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured it out. We can just conditionally add extra escaping on FreeBSD.
sjaeckel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@buggywhip can you please test on Mac?
@karel-m can you please test as well on the platforms where you use makefile or makefile.shared?
|
I tried this out on my Mac, both with |
that's not how it works. in a properly configured environment, the default compiler is detected as follows:
that means that a properly configured system should have symlinks /usr/bin/cc -> /usr/bin/clang or whatever in place. no makefile should ever do bogus stuff like using |
|
That's not what this does. Currently, the logic here says "if your |
yeah, i'm talking about how it should be according to conventions |
|
@rofl0r okay, so how should we solve this? |
|
looking into one of my cross-compiler builds: that means what i said above applies also to CROSS_COMPILE scenarios i.e.: there should be a so:
or simplified (pseudocode): |
|
no, CROSS_COMPILE is user set, you shouldnt try to set it if not given
that's odd. where did you get your cross toolchains from ? EDIT: anyway, even if there are some toolchains out there that don't set $(CROSS_COMPILE)cc as a symlink to the right compiler, we should lobby them into doing it, as this takes away the entire need for system-specific and non-crosscompile-compatible uname hacks. |
sorry - that's what I meant by I, the user, not the libtom maintainer :)
well I haven't seen any cross toolchain that provides a cc ... I've some from linaro, some from debian/ubuntu packages, some in yocto... Edit: oh, I just found one, buildroot seems to provide a $(CROSS_COMPILE)cc ... and yes it's a good idea to 'lobby them into doing it' but for now that's not real yet and so we should go with one of those 'temporary solutions'^TM that lets us anyways do what we want :) |
| endif | ||
|
|
||
| ifeq ($(CC),cc) | ||
| ifeq ($(origin CC),default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before merging this... I just realized that the original check for CC was already wrong, this path should only be taken if CROSS_COMPILE is defined... or not? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*ping*?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, been busy with other stuff. I'll revisit this.
This properly sets MAKE (when undefined) on BSDs to gmake rather than make, which refers to the incompatible BSD Make. Further, it betters detection of Clang as the default compiler, which is the case on FreeBSD 11.0+ and OpenBSD 6.0+.
Make the build logic more robust for BSD systems (cherry picked from commit 5ab8dcf)
This properly sets
MAKE(when undefined) on BSDs togmakerather thanmake, which refers to the incompatible BSD Make. Further, it betters detection of Clang as the default compiler, which is the case on FreeBSD 11.0+ and OpenBSD 6.0+.This has been verified to work on FreeBSD with
gmakeandgmake -f makefile.shared.Companion to libtom/libtommath#108.