Skip to content

support LDFLAGS in configure and Makefile.config.in except for flexlink#10091

Merged
gasche merged 1 commit intoocaml:trunkfrom
gasche:ldflags
Dec 21, 2020
Merged

support LDFLAGS in configure and Makefile.config.in except for flexlink#10091
gasche merged 1 commit intoocaml:trunkfrom
gasche:ldflags

Conversation

@gasche
Copy link
Copy Markdown
Member

@gasche gasche commented Dec 18, 2020

OC_LDFLAGS is for options specific to linking OCaml programs, LDFLAGS
are user-chosen flags that should be included in any call to the
system linker.

This is intended to fix #9191.

The logic followed in this PR is similar to the treatment of CFLAGS in
the build system, which comes from #9837.

Passing LDFLAGS to flexlink is not supported. It is a pain to do
correctly, and we haven't got requests from Windows users yet, only
from users of unix variants.

(cc our configuration overlords, @shindere and @dra27)

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Dec 18, 2020 via email

@gasche
Copy link
Copy Markdown
Member Author

gasche commented Dec 18, 2020

Thanks for the review.

if you don't want to deal with LDLIBS then you could write "like LDLIBS"

I don't know what LDLIBS is, so I followed that route indeed, thanks for the suggestion.

I seem to remember that for some linkers it is important that either LDFLAGS or LDLIBS come last, e.g. after the -o.

Yes, this seems to be done in this way in the msvc case, with /link ... after the $(1) $(2) part. I exactly followed the way OC_LDFLAGS is handled (in the mscv and in the non-msvc case), so this PR should not change the correctness of the code: in the msvc case, OC_LDFLAGS was at the end, and I included LDFLAGS there as well, in the non-msvc case OC_LDFLAGS was after the {OC,_}CFLAGS and I did the same for LDFLAGS.

It seems that, before your patch, this definition did
not make use of $(OC_LDFLAGS). If you add LDFLAGS their, shouldn't
OC_LDFLAGS be added, too?

I don't really know how OC_LDFLAGS is supposed to work, and I am not sure that the change would be correct. (Given that it is not passed here, I would expect it to be either passed explicitly somewhere else, or ignored. It actually appears to be included in mkexe and ignored for mksharedlib by default.) The present PR is rather non-invasive in the sense that if LDFLAGS is empty, nothing changes. Including OC_LDFLAGS in mksharedlib is an orthogonal change that may break things, and that I have no idea how to test, so I would rather avoid it.

With the question above, I realise that we may need to clarify what
OC_LDFLAGS represents. To me the intention was for it to contain any
linker flags found to be useful by the configure script and thus LDFLAGS
becomes a mechanism to overload those flags.

I am not sure either, but the same question holds for OC_CFLAGS, and I would expect the same answer in both cases. My guess when reading the code was that OC_CFLAGS is meant for settings specifically decided by us for the OCaml build, and CFLAGS is for additional settings decided by the user (I tried to explain this in the comment about mkexe). Currently the definition of oc_cflags does not include CFLAGS, but ocamlc_cflags (the flags used by OCaml to compile C sources) includes both. I followed the same discipline of keeping them separate in this patch.

Copy link
Copy Markdown
Member

@dra27 dra27 left a comment

Choose a reason for hiding this comment

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

You haven't regenerated configure which means in any testing you haven't seen the errors!

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Dec 18, 2020 via email

@dra27
Copy link
Copy Markdown
Member

dra27 commented Dec 19, 2020

@dra27 commented on this pull request. You haven't regenerated configure which means in any testing you haven't seen the errors!

Woudl it be possible that Travis checks for this as the pre-commit hook does? Will review the rest on Monday.

The pre-commit hook doesn't check for this - it's the Travis check-typo which does that (and which has been consistently red for the PR!). I'm technically now on vacation, but I expect may do some CI hackery at some point prior to 31 Dec to move the last of the Travis checks like that to GitHub actions before Travis shut us down completely on 31 Dec...

@gasche
Copy link
Copy Markdown
Member Author

gasche commented Dec 19, 2020

Thanks! I hadn't noticed this Travis check. I suppose it was still failing because I regenerated configure incorrectly (I didn't remember how one does that, and I tried autoconf and automake.) The Travis CI check gives the information that one should make configure instead, it would be nice to include it in HACKING.adoc as well.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Dec 21, 2020 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Dec 21, 2020 via email

@gasche
Copy link
Copy Markdown
Member Author

gasche commented Dec 21, 2020

In any case, I'd say that $LDFLAGS should appear as late as possible
in the command so that it gives users a chance to overload any otherwise
set flag.

This is a good point, consistent with how CFLAGS is included after OC_CFLAGS and LDFLAGS after OC_LDFLAGS. I rebased the PR so that LDFLAGS occurs after configure-decided flags.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Dec 21, 2020 via email

OC_LDFLAGS is for options specific to linking OCaml programs, LDFLAGS
are user-chosen flags that should be included in any call to the
system linker.

This is intended to fix ocaml#9191.

The logic followed in this PR is similar to the treatment of CFLAGS in
the build system, which comes from ocaml#9837.

Passing LDFLAGS to flexlink is not supported. It is a pain to do
correctly, and we haven't got requests from Windows users yet, only
from users of unix variants.
@gasche
Copy link
Copy Markdown
Member Author

gasche commented Dec 21, 2020

Thanks, I rebased the PR with all these changes.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Dec 21, 2020 via email

@gasche
Copy link
Copy Markdown
Member Author

gasche commented Dec 21, 2020

Thanks for the approval. I started a precheck job and will merge if the results are good.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Dec 21, 2020 via email

@gasche gasche merged commit 6457422 into ocaml:trunk Dec 21, 2020
@gasche
Copy link
Copy Markdown
Member Author

gasche commented Dec 21, 2020

precheck is happy, so merging. Thanks @dra27 and @shindere for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to make OCaml build honour CFLAGS, LDFLAGS et al

3 participants