-
Notifications
You must be signed in to change notification settings - Fork 2k
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
pkg: fix cross compiling with cmake on macOS #8509
Conversation
print "SET(CMAKE_SYSTEM_NAME Generic)\n"; | ||
print "SET(CMAKE_SYSTEM_VERSION 1)\n"; | ||
print "\n"; | ||
print "# specify the cross compiler\n"; | ||
#print "SET(CMAKE_AR \"$ENV{AR}\" CACHE STRING \"\")\n"; |
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.
here is something commented out
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.
not needed, will remove
pkg/ccn-lite/Makefile
Outdated
@@ -7,8 +7,22 @@ PKG_LICENSE=ISC | |||
|
|||
export RIOT_CFLAGS = ${CFLAGS} ${INCLUDES} | |||
|
|||
all: git-download | |||
cd $(PKG_BUILDDIR)/src && cmake -DCCNL_RIOT=1 -DRIOT_CFLAGS="${RIOT_CFLAGS}" . && make | |||
$(info $(PKG_BUILDDIR)) |
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.
debug output?
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.
yep, forgot to remove
@kaspar030 fixed, amended directly |
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.
Some makefile related remarks.
Also, please split the commit for relic
in two between style changes and actual changes with xcompile.
@@ -1,26 +1,21 @@ | |||
#!/usr/bin/env perl |
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.
As moving to a general RIOT script, I would prefer to have it in either sh/bash
or python
than perl
.
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.
yeah thought about that, too, but started with using what was already in place with relic
- I think sh
would be best.
makefiles/vars.inc.mk
Outdated
@@ -21,6 +21,7 @@ export RIOTBASE # The root folder of RIOT. The folder where this ve | |||
export RIOTCPU # For third party CPUs this folder is the base of the CPUs. | |||
export RIOTBOARD # For third party BOARDs this folder is the base of the BOARDs. | |||
export RIOTPKG # For overriding RIOT's pkg directory | |||
export RIOTTOOLS # For overriding RIOT's tools directory |
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.
Could this be done in a separate PR/issue, because right now there are still a lot of dist/tools
in the repository, and only two packages using the variable does not help keeping things consistent:
git grep 'dist/tools' | wc -l
219
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.
well that search mostly hits dist/tools
in comments and readme docs, nevertheless you got a point, that this is sub-optimal and inconsistent. I'll look into it.
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.
most hits are not actual usages but rather comments, e.g. in README.
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.
There are still a lot, all the python tests use it for example.
git grep dist/tools | grep -v -e README -e doc.txt -e.md | wc -l
176
pkg/ccn-lite/Makefile
Outdated
cp $(PKG_BUILDDIR)/src/lib/libccnl-riot.a ${BINDIR}/ccn-lite.a | ||
|
||
$(PKG_BUILDDIR)/src/Makefile: $(PKG_BUILDDIR)/xcompile-toolchain.cmake |
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.
Please use a variable for $(PKG_BUILDDIR)/xcompile-toolchain.cmake
its repeated 3 times in the build.
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.
good point
pkg/ccn-lite/Makefile
Outdated
all: git-download | ||
cd $(PKG_BUILDDIR)/src && cmake -DCCNL_RIOT=1 -DRIOT_CFLAGS="${RIOT_CFLAGS}" . && make | ||
all: $(PKG_BUILDDIR)/src/Makefile | ||
$(MAKE) -C $(PKG_BUILDDIR)/src && \ |
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.
&&
not required here.
pkg/ccn-lite/Makefile
Outdated
$(PKG_BUILDDIR)/src/Makefile: $(PKG_BUILDDIR)/xcompile-toolchain.cmake | ||
cd $(PKG_BUILDDIR)/src && \ | ||
cmake -DCMAKE_TOOLCHAIN_FILE=$(PKG_BUILDDIR)/xcompile-toolchain.cmake \ | ||
-DCCNL_RIOT=1 -DRIOT_CFLAGS="${RIOT_CFLAGS}" . |
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.
You could remove the cd
by using $(@D)
instead of .
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.
I'm unsure, because IIRC cmake
generates its intermediate files where it is called from, which in this case must be $(PKG_BUILDDIR)/src
otherwise the make
if above won't work.
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.
You are right, I forgot cmake was working this way.
pkg/ccn-lite/Makefile
Outdated
|
||
$(PKG_BUILDDIR)/xcompile-toolchain.cmake: git-download | ||
cd $(PKG_BUILDDIR) && \ | ||
perl $(RIOTTOOLS)/cmake/generate-xcompile-toolchain.pl > xcompile-toolchain.cmake |
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.
Here too, you could just use $@
instead of cd.
pkg/relic/Makefile
Outdated
all: $(PKG_BUILDDIR)/Makefile | ||
"$(MAKE)" -C $(PKG_BUILDDIR) && \ | ||
$(MAKE) -C $(PKG_BUILDDIR) && \ |
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.
Removed the "
around MAKE, also &&
not required.
pkg/relic/Makefile
Outdated
CFLAGS += -Wno-gnu-zero-variadic-macro-arguments -Wno-unused-function -Wno-newline-eof | ||
$(PKG_BUILDDIR)/xcompile-toolchain.cmake: fix_source | ||
cd $(PKG_BUILDDIR) && \ | ||
perl $(RIOTTOOLS)/cmake/generate-xcompile-toolchain.pl > xcompile-toolchain.cmake |
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.
Same remarks as the other package with cd
, I now understand where they come from.
Post review thoughts. In fact, I could fix my |
@cladmi I tried to address you comments, I changed the perl script into a shell script. Your hint with using |
ping! May I squash? |
ping again, @cladmi and @kaspar030 IMHO your change requests are addressed. |
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.
Still would like the RIOTTOOLS
done in another PR as it has no link to fix cros compiling with cmake
.
Then remaining one minor variable that could use $(TOOLCHAIN_FILE)
, see inline.
I ignored makefile cleanups that where not done before already.
pkg/relic/Makefile
Outdated
cp $(PKG_BUILDDIR)/lib/librelic_s.a $(BINDIR)/$(PKG_NAME).a | ||
|
||
$(PKG_BUILDDIR)/comp-options.cmake: fix_source | ||
cd "$(PKG_BUILDDIR)" && perl $(PKG_DIR)/generate-cmake-xcompile.perl > comp-options.cmake | ||
$(PKG_BUILDDIR)/Makefile: $(PKG_BUILDDIR)/xcompile-toolchain.cmake |
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.
This one should be $(TOOLCHAIN_FILE)
too.
What is the simple test procedure to test on mac if @kYc0o wants to check ? |
I think this is ready to merge now. |
-DCCNL_RIOT=1 -DRIOT_CFLAGS="${RIOT_CFLAGS}" -DBUILD_TESTING=OFF . | ||
|
||
$(TOOLCHAIN_FILE): git-download | ||
$(RIOTBASE)/dist/tools/cmake/generate-xcompile-toolchain.sh > $(TOOLCHAIN_FILE) |
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.
$(RIOTBASE)/dist/tools/cmake/generate-xcompile-toolchain.sh > $@
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.
ah, Makefile magic - kind of :) will add
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.
mhm, doesn't work though - $@
is expanded to /xcompile-toolchain.cmake
only, without pkg build dir set.
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.
so is $(TOOLCHAIN_FILE)
? $@
should evaluate to the target name.
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.
I'm not sure whats going wrong fact is:
$(RIOTBASE)/dist/tools/cmake/generate-xcompile-toolchain.sh > $@
is expanded to
/path/to/RIOT/dist/tools/cmake/generate-xcompile-toolchain.sh > /xcompile-toolchain.cmake
which obviously gives an error, because it is not allow to write to my root dir.
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.
so the pkgbuilddir is empty at this point
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.
leaving it as is, works
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.
ok, thanks for trying. Weird that it can match the target but doesn't evaluate $@ afterwards?
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.
At that time PKG_BUILDDIR
is not defined because pkg.mk
has not been included.
Goals are evaluated immediately not deferred. So the rule is really /xcompile-toolchain.cmake
.
But the problem was also in the pkg/relic/Makefile
before, so would require a real fix that could come later.
|
||
CFLAGS += -Wno-gnu-zero-variadic-macro-arguments -Wno-unused-function -Wno-newline-eof | ||
$(TOOLCHAIN_FILE): fix_source | ||
$(RIOTBASE)/dist/tools/cmake/generate-xcompile-toolchain.sh > $(TOOLCHAIN_FILE) |
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.
same
Contribution description
This PR fixes cross compiling on macOS for packages that use
cmake
, these currently are ccn-lite and relic. While relic had this already I recently ran in troubles with ccn-lite, which is fixed here.For future use by other packages the helper script is moved (and adapted a bit) to the tools directory, and Makefiles for both packages are adapted accordingly.
Issues/PRs references