Skip to content
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

Merged
merged 4 commits into from
Mar 29, 2018

Conversation

smlng
Copy link
Member

@smlng smlng commented Feb 2, 2018

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

@smlng smlng added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation OS: Mac OS X Host OS: This PR/issue concerns usage of RIOT with Mac OS X as a host system Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Area: tools Area: Supplementary tools labels Feb 2, 2018
@smlng smlng requested review from tfar, cgundogan and kYc0o February 2, 2018 09:50
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";
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed, will remove

@@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug output?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, forgot to remove

@smlng
Copy link
Member Author

smlng commented Feb 2, 2018

@kaspar030 fixed, amended directly

Copy link
Contributor

@cladmi cladmi left a 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
Copy link
Contributor

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.

Copy link
Member Author

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.

@@ -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
Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Contributor

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

cp $(PKG_BUILDDIR)/src/lib/libccnl-riot.a ${BINDIR}/ccn-lite.a

$(PKG_BUILDDIR)/src/Makefile: $(PKG_BUILDDIR)/xcompile-toolchain.cmake
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

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 && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& not required here.

$(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}" .
Copy link
Contributor

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 .

Copy link
Member Author

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.

Copy link
Contributor

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_BUILDDIR)/xcompile-toolchain.cmake: git-download
cd $(PKG_BUILDDIR) && \
perl $(RIOTTOOLS)/cmake/generate-xcompile-toolchain.pl > xcompile-toolchain.cmake
Copy link
Contributor

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.

all: $(PKG_BUILDDIR)/Makefile
"$(MAKE)" -C $(PKG_BUILDDIR) && \
$(MAKE) -C $(PKG_BUILDDIR) && \
Copy link
Contributor

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.

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
Copy link
Contributor

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.

@cladmi
Copy link
Contributor

cladmi commented Feb 5, 2018

Post review thoughts. In fact, I could fix my make remarks in another PR if you want, as you basically just duplicated what was in relic in ccn-lite.

@smlng
Copy link
Member Author

smlng commented Feb 5, 2018

@cladmi I tried to address you comments, I changed the perl script into a shell script. Your hint with using @D didn't work for me, and removing the && \ didn't either <- but maybe its this (weird) Makefile scripting syntax. Regarding the RIOTTOOLS variable, it comes quite handy here, but I also don't want to break other stuff right now. So adapting other usages throughout RIOT source should be done in followup PRs, or not?

@smlng smlng added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 7, 2018
@smlng smlng added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 21, 2018
@smlng
Copy link
Member Author

smlng commented Feb 23, 2018

ping! May I squash?

@smlng smlng added Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 25, 2018
@smlng
Copy link
Member Author

smlng commented Feb 28, 2018

ping again, @cladmi and @kaspar030 IMHO your change requests are addressed.

@smlng smlng added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 28, 2018
Copy link
Contributor

@cladmi cladmi left a 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.

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
Copy link
Contributor

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.

@cladmi
Copy link
Contributor

cladmi commented Mar 22, 2018

What is the simple test procedure to test on mac if @kYc0o wants to check ?

@smlng
Copy link
Member Author

smlng commented Mar 27, 2018

@cladmi I removed RIOTTOOLS, saw you already provided a PR for that -> nice, thanks! If @kYc0o wants to verify: try to compile examples/ccn-lite on macOS for samr21-xpro linking will fail on master without this PR.

@smlng
Copy link
Member Author

smlng commented Mar 27, 2018

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)
Copy link
Contributor

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 > $@

Copy link
Member Author

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

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Contributor

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?

Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@kaspar030
Copy link
Contributor

I think too this has waited long enough.

@smlng feel free to squash in the "$@".

@cladmi you happy here?

@cladmi cladmi merged commit b502637 into RIOT-OS:master Mar 29, 2018
@smlng smlng deleted the cmake/xcompile branch March 29, 2018 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: pkg Area: External package ports Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Community: Hack'n'ACK candidate This PR is a candidate for review and discussion during one of RIOT's monthly Hack'n'ACK parties OS: Mac OS X Host OS: This PR/issue concerns usage of RIOT with Mac OS X as a host system Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants