pkg: fix cross compiling with cmake on macOS#8509
Conversation
| 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.
here is something commented out
pkg/ccn-lite/Makefile
Outdated
|
|
||
| all: git-download | ||
| cd $(PKG_BUILDDIR)/src && cmake -DCCNL_RIOT=1 -DRIOT_CFLAGS="${RIOT_CFLAGS}" . && make | ||
| $(info $(PKG_BUILDDIR)) |
|
@kaspar030 fixed, amended directly |
| @@ -1,26 +1,21 @@ | |||
| #!/usr/bin/env perl | |||
There was a problem hiding this comment.
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.
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
| 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.
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.
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.
most hits are not actual usages but rather comments, e.g. in README.
There was a problem hiding this comment.
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
| $(MAKE) -C $(PKG_BUILDDIR)/src && \ | ||
| 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.
Please use a variable for $(PKG_BUILDDIR)/xcompile-toolchain.cmake its repeated 3 times in the build.
| 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 && \ |
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.
You could remove the cd by using $(@D) instead of .
There was a problem hiding this comment.
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.
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.
Here too, you could just use $@ instead of cd.
|
|
||
| all: $(PKG_BUILDDIR)/Makefile | ||
| "$(MAKE)" -C $(PKG_BUILDDIR) && \ | ||
| $(MAKE) -C $(PKG_BUILDDIR) && \ |
There was a problem hiding this comment.
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.
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. |
cladmi
left a comment
There was a problem hiding this comment.
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
|
|
||
| $(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.
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.
$(RIOTBASE)/dist/tools/cmake/generate-xcompile-toolchain.sh > $@
There was a problem hiding this comment.
ah, Makefile magic - kind of :) will add
There was a problem hiding this comment.
mhm, doesn't work though - $@ is expanded to /xcompile-toolchain.cmake only, without pkg build dir set.
There was a problem hiding this comment.
so is $(TOOLCHAIN_FILE)? $@ should evaluate to the target name.
There was a problem hiding this comment.
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.
so the pkgbuilddir is empty at this point
There was a problem hiding this comment.
ok, thanks for trying. Weird that it can match the target but doesn't evaluate $@ afterwards?
There was a problem hiding this comment.
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) |
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