I think there are 4 cases, depending on the values of -std and -stdlib, and
interacting with CC

1. -std and -stdlib both at their defaults (g++99 and the g++ library): We
need this to always work for compatibility with old compilers.
2. -std=c++11 and -stdlib at its default: This case should work and allow
either clang++ or g++ to build with the g++ library.
3. -std at its default and -stdlib=libc++: This case should work, at least
if CC=clang++. For CC=g++, it can work with more effort.
4. -std=c++11 and -stdlib=libc++:  This case should work, at least if
CC=clang++. For CC=g++, it can work with more effort.

Compiling with CC=clang++ and -stdlib=libc++ is possible, but I have only
seen it done as a stress test.

Since this is a bit complicated for the average user and using the c++11
standard doesn't currently add any features or performance benefits, I
think these options (except for 1) should be chosen by editing
submakefiles. But having a make/user file that is sourced last might be
good for a variety of reasons and would basically work like ~/.R/Makeflags
does with the rstan package.

Ben

On Fri, Aug 30, 2013 at 3:44 PM, Rob J Goedman <notifications@github.com>wrote:

> In make/os_mac:
>
> >  ifeq (clang++,$(CC_TYPE))
> >    CFLAGS_GTEST += -Wc++11-extensions
> >    CFLAGS_GTEST += -Wno-c++11-long-long
> >    CFLAGS += -Wno-unused-function
> >    CFLAGS += -Wno-tautological-compare
> >    CFLAGS += -Wno-c++11-long-long
> > +  CFLAGS += -ftemplate-depth=256
> > +  ifeq (true,$(C++11))
> > +    CFLAGS += -stdlib=libc++ -std=c++11
>
> Stepping on thin ice here ... My intention of passing a single C++11 flag
> on the command to make was primarily to keep things simple for ARM/R users
> (vs. BDA/R users). At the moment I don't have GCC 4.8 on my system but I
> seem to remember that GCC 4.8 does not require the -stdlib=libc++ addition,
> just -std=c++11. If that is true a similar nested ifeq could be added in
> make/os_linux: ifeq (g++,$(CC_TYPE)) LDFLAGS += -lpthread CFLAGS_GTEST +=
> -DGTEST_HAS_PTHREAD=0 ifeq (4.8,$(CC_MAJOR).$(CC_MINOR)) CFLAGS +=
> -Wno-unused-local-typedefs ifeq (true,$(C++11)) CFLAGS += -std=c++11 endif
> endif PCH = .gch endif Using a make/user_options file is another good
> solution. It does worry me to go to twice nested 'ifeq' constructs vs. just
> simply redefining flags. Rob J. Goedman goedman@icloud.com
> … <#140d0c1c9ea9c1c7_>
> On Aug 30, 2013, at 11:14 AM, bgoodri <notifications@github.com> wrote: >
> You could have two flags, one for the -std and one for the -stdlib, but
> that just seems overly complicated to me. For R users, they essentially
> have to add to the Makeflags anyway. > > — > Reply to this email directly
> or view it on GitHub. On Aug 30, 2013, at 10:27 AM, Bob Carpenter <
> notifications@github.com> wrote: > In make/os_mac: > > > ifeq
> (clang++,$(CC_TYPE)) > > CFLAGS_GTEST += -Wc++11-extensions > >
> CFLAGS_GTEST += -Wno-c++11-long-long > > CFLAGS += -Wno-unused-function > >
> CFLAGS += -Wno-tautological-compare > > CFLAGS += -Wno-c++11-long-long > >
> + CFLAGS += -ftemplate-depth=256 > > + ifeq (true,$(C++11)) > > + CFLAGS +=
> -stdlib=libc++ -std=c++11 > I am not a makefile guru or shell developer,
> but for what it's worth, I like the calling of user options rather than
> having people edit our makefiles. - Bob > … > — > Reply to this email
> directly or view it on GitHub. > On Aug 30, 2013, at 10:04 AM, bgoodri <
> notifications@github.com> wrote: In make/os_mac: > ifeq
> (clang++,$(CC_TYPE)) > CFLAGS_GTEST += -Wc++11-extensions > CFLAGS_GTEST +=
> -Wno-c++11-long-long > CFLAGS += -Wno-unused-function > CFLAGS +=
> -Wno-tautological-compare > CFLAGS += -Wno-c++11-long-long > + CFLAGS +=
> -ftemplate-depth=256 > + ifeq (true,$(C++11)) > + CFLAGS += -stdlib=libc++
> -std=c++11 @goedman <https://github.com/goedman> @bob-carpenter<https://github.com/bob-carpenter>I think having the C++11 flag imply CFLAGS += -stdlib=libc++ -std=c++11 is
> not quite right because we also want to support the c++11 standard under
> g++ (>= 4.7). It is technically possible to use LLVM's version of the
> standard c++ library with g++ but that is sort of an academic exercise and
> essentially everyone using g++ would be using GCC's version of the standard
> c++ library. So, I think if someone wants to use the C++11 standard, they
> should just add the appropriate flags locally to their
> make/os_{win,mac,linux} file. Or maybe we should source another (possibly
> empty) file under make/ called user_options or something. — Reply to this
> email directly or view it on GitHub.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/stan-dev/stan/pull/184/files#r6094468>
> .
>