Opened 7 months ago

Closed 5 months ago

Last modified 5 months ago

#69782 closed enhancement (fixed)

legacy-support: Minor issues with ARCHFLAGS in the Makefile

Reported by: TurtleWilly (Wilhelm Loves Their Turtles) Owned by: mascguy (Christopher Nielsen)
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc: fhgwright (Fred Wright)
Port: legacy-support

Description

Not a real problem, and easy to workaround, but I wanted to report it anyway.

In the Makefile it does the following:

FORCE_ARCH      ?=
ARCHFLAGS       ?=
LIPO            ?= lipo
CC              ?= cc $(ARCHFLAGS)
CFLAGS          ?= -Os -Wall -Wno-deprecated-declarations
DLIBCFLAGS      ?= -fPIC
SLIBCFLAGS      ?=
CXX             ?= c++ $(ARCHFLAGS)
CXXFLAGS        ?= -Os -Wall

So building with "make FORCE_ARCH=i368 ARCHFLAGS='-arch i368'" I expected to get a proper i386 build of the library, but I ended up with a x86_64 one anyway. It seems that "$(ARCHFLAGS)" is not expanded in the "CC ?= …" and "CXX ?= …" lines and simply ends up empty, hence the it progresses with a native arch build. Switching both lines from "?=" to just "=" makes things work (ultimately I just passed CC and CXX including the arch parameter as arguments to make instead using the ARCHFLAGS variable).

$ make --version
GNU Make 3.81
Copyright (C) 2006  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.

This program built for i386-apple-darwin11.3.0

(XCode 7.2/ OS X 10.10.5 Yosemite)

Unrelated to the actual issue above I think the BUILDING.txt could need some clarification how things work. I sounds a bit confusing. E.g. I assumed it would work with just FORCE_ARCH. It also could mention the supported arches, so one doesn't have to dig it out of the Makefile source code.

Attachments (1)

lscc.sh (1.0 KB) - added by fhgwright (Fred Wright) 7 months ago.
Wrapper script for building legacy-support

Download all attachments as: .zip

Change History (10)

comment:1 in reply to:  description Changed 7 months ago by ryandesign (Ryan Carsten Schmidt)

Cc: fhgwright added
Owner: set to mascguy
Status: newassigned

Replying to TurtleWilly:

It seems that "$(ARCHFLAGS)" is not expanded in the "CC ?= …" and "CXX ?= …" lines and simply ends up empty,

I would have thought it would get expanded.

CC              ?= cc $(ARCHFLAGS)
CXX             ?= c++ $(ARCHFLAGS)

But even if it did, this doesn't seem like a good way to do it. Users expect to be able to override CC and CXX, and they don't expect that, when they do so, some flags will no longer get added.

comment:2 Changed 7 months ago by ryandesign (Ryan Carsten Schmidt)

I would think something more like

CC              := $(CC) $(ARCHFLAGS)
CXX             := $(CXX) $(ARCHFLAGS)

but this is untested and still not ideal. Instead, $(ARCHFLAGS) should be in each rule that needs it.

(make defaults to cc and c++ for CC and CXX respectively, doesn't it? So providing that value should not be necessary.)

comment:3 Changed 7 months ago by TurtleWilly (Wilhelm Loves Their Turtles)

This is how it would resolve here on my system:

$ make --print-data-base | egrep '^(CC|CXX).*'
CC = cc
CXX = c++

$ which cc
/usr/bin/cc
$ which c++
/usr/bin/c++

$ ls -l /usr/bin/cc
lrwxr-xr-x  1 root  wheel  5 Oct 30  2014 /usr/bin/cc -> clang
$ ls -l /usr/bin/c++
lrwxr-xr-x  1 root  wheel  7 Oct 30  2014 /usr/bin/c++ -> clang++

And finally clang and clang++ are shim binaries that redirect to inside XCode, if installed, or prompt the user to install XCode first. Redirection madness. :)

comment:4 Changed 7 months ago by mascguy (Christopher Nielsen)

Priority: LowNormal

comment:5 Changed 7 months ago by fhgwright (Fred Wright)

I've seen cases where specifying the arch flag(s) in the usual C*FLAGS doesn't work and it *must* be done in CC or CXX, though admittedly that doesn't seem to be the case here. But I normally use a wrapper script to build legacy-support anyway. The script I use is set up to pick reasonable defaults on every system, though you can override them if you want. The one thing it doesn't do is use FORCE_ARCH, since in this context it's easier just to have the MacPorts cctools active on the systems where the system lipo is inadequate. The port avoids that for dependency reasons.

With this script I usually just say something like:

../.scripts/lscc.sh make

That works on all systems.

I'll attach a copy of the script.

Changed 7 months ago by fhgwright (Fred Wright)

Attachment: lscc.sh added

Wrapper script for building legacy-support

comment:6 Changed 7 months ago by fhgwright (Fred Wright)

I should point out that the default for ARCH only works if you've set build_arch explicitly in macports.conf, which I usually do anyway for clarity (and because the default sometimes doesn't agree with the documentation).

But if you set ARCH explicitly it doesn't matter.

comment:7 Changed 5 months ago by fhgwright (Fred Wright)

The problem is that ?= doesn't work with CC or CXX, since they're always defined. Another issue is that supplying CFLAGS or CXXFLAGS would override the defaults, and remove flags that are usually wanted. I have an upcoming fix for both issues.

comment:8 Changed 5 months ago by fhgwright (Fred Wright)

Resolution: fixed
Status: assignedclosed

In 86a71bfc238cda8577a8abc4f16a1b6e010d7492/macports-legacy-support (master):

Makefile: Fix CC/CXX/LD flags issues.

This fixes three issues with specifying flag variables to the Makefile:

1) It attempted to insert ARCHFLAGS into CC and CXX, but it was using ?=,
which doesn't work for predefined variables.

2) It never incorporated ARCHFLAGS into LDFLAGS.

3) It provided some defaults in CFLAGS and CXXFLAGS, but any setting of
these variables removed those defaults. The defaults are now in XCFLAGS
and XCXXFLAGS, which are added to C[XX]FLAGS, along with ARCHFLAGS, so
they normally are kept. If removing the defaults is desired, then
XC[XX]FLAGS can be overridden.

Note that the port build procedure uses FORCE_ARCH, not ARCHFLAGS.

Closes: #69782

TESTED:
ARCHFLAGS is now respected, and setting CFLAGS doesn't remove
defaults.

comment:9 Changed 5 months ago by fhgwright (Fred Wright)

In 5b06d58603710b847be0ad5adcf0d287ade64626/macports-ports (master):

legacy-support: Update to latest master

  • Fixes incorrect CLOCK_UPTIME_RAW_APPROX definition
  • Fixes Makefile flag handling (for non-port builds)

Re: #69782

  • Eliminates spurious fmemopen() in OSes that don't need it
  • Much internal rework of feature flags (WIP)

Re: #69867

TESTED:
Tested both normal and -devel versions on 10.4-10.5 ppc, 10.5-10.6 ppc
(i386 Rosetta), 10.4-10.6 i386, 10.4-12.x x86_64, and 11.x-14.x arm64.
Builds on all tested platforms except 10.4 ppc +universal.
Passes all tests in all buildable cases.

Note: See TracTickets for help on using tickets.