Bug 7133 - Document environment file usage
Summary: Document environment file usage
Status: VERIFIED FIXED
Alias: None
Product: ADT Manual
Classification: Documentation
Component: SDK (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Medium+ enhancement
Target Milestone: 1.9 M3
Assignee: Costin
QA Contact: Costin
URL:
Whiteboard: 15 June 2015: Checking documentation ...
Depends on:
Blocks:
 
Reported: 2015-01-13 15:20 UTC by Mark Hatle
Modified: 2015-08-20 04:29 UTC (History)
7 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Done (doc changes complete)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Hatle 2015-01-13 15:20:20 UTC
The ADT documentation lists how to source the environment file, but not what to do with the now available environment variables.

Something like:

Once the environment file is sources, a number of environment variables are now defined:

SDKROOT - path to the installed SDK
SDKTARGETSYSROOT - path to the sysroot that will be used for cross compilation
PKG_CONFIG_PATH - path to pkg-config files for the target
CONFIG_SITE - a gnu autoconf site file preconfigured for the target
CC - minimum command and arguments to run the C compiler
CXX - minimum command and arguments to run the C++ compiler
CPP - minimum command and arguments to run the C preprocessor
AS - minimum command and arguments to run the assembler
LD - minimum command and arguments to run the linker
GDB - minimum command and arguments to run the GNU Debugger
STRIP - minimum command and arguments to run 'strip' (strip symbols)
RANLIB - minimum command and arguments to run 'ranlib'
OBJCOPY - minimum command and arguments to run 'objcopy'
OBJDUMP - minimum command and arguments to run 'objdump'
AR - minimum command and arguments to run 'ar'
NM - minimum command and arguments to run 'nm'
TARGET_PREFIX - toolchain binary prefix for the target tools
CROSS_COMPILE - (same as TARGET_PREFIX)
CONFIGURE_FLAGS - minimum arguments for GNU configure
CFLAGS - suggested C flags
CXXFLAGS - suggested C++ flags
LDFLAGS - suggested linker flags (when using CC to link)
CPPFLAGS - suggested preprocessor flags

To use the above, on the command line, to compile a simple hello_world.c and hello_world.cc, or the GNU version of hello world you would do the following:

(source the environment file as noted above)

Compile a simple C application:
$ $CC hello_world.c -o hello

Compile a simple CXX application:
$ $CXX hello_world.cxx -o hello_cxx

Configure and compile a GNU autoconf application
$ ./configure $CONFIGURE_FLAGS
$ make
Comment 1 Paul Eggleton 2015-01-20 15:54:06 UTC
I've talked to Scott about this offline. However, we don't seem to have a reference to SDKROOT anywhere I can find. Mark, is this something specific to your setup?
Comment 2 Mark Hatle 2015-01-20 16:05:04 UTC
You are correct.  The SDKROOT is what was implemented in the meta-mingw patch that I submitted to the Yocto Project. (Not yet merged.)  It's not in the default Linux SDK.

So it likely should be documented.
Comment 3 Scott Rifenbark 2015-01-23 18:29:51 UTC
Hi, 

I have gone through the entire adt-manual and addressed this issue.  The result was "feathering" in text to more fully describe the use and role for the cross-toolchain environment variables that are established when one runs the cross-toolchain environment setup script.  

Additionally, many new variables were added to the ref-manual to support the changes.  I would like the stuff reviewed and notified of any further changes or issues.  Note that the descriptions for the new variables are very brief and are based soley on the short descriptions provided in the bug.  If you want to expand on them, give me some more details and I will.

You can see the changes at:

  http://www.yoctoproject.org/docs/1.8/adt-manual/adt-manual.html (it would be good to check out most of the document - several areas were changed).

  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-SDKROOT
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-SDKTARGETSYSROOT
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-PKG_CONFIG_PATH
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-CONFIG_SITE
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-CC
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-CXX
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-CPP
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-AS
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-LD
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-GDB
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-STRIP
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-RANLIB
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-OBJCOPY
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-OBJDUMP
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-AR
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-NM
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-TARGET_PREFIX
  http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-CROSS_COMPILE
    http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-CONFIGURE_FLAGS
    http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-CFLAGS
    http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-CXXFLAGS
    http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-LDFLAGS
    http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#var-CPPFLAGS

Thanks, 
Scott
Comment 4 Mark Hatle 2015-01-23 19:51:36 UTC
Comments.. ADT section 5.2 is incorrect:

5.2. Makefile-Based Projects¶

For Makefile-based projects, you make sure your Makefile has statements that ensure proper use of the cross-toolchain. For example, the following statements inside a Makefile ensure the C compiler, linker, flags passed to the C compiler, and flags passed to the C++ compiler are specifically defined for the build:

     CC=arm-poky-linux-gnueabi-gcc
     LD=arm-poky-linux-gnueabi-ld
     CFLAGS=”${CFLAGS} --sysroot=<sysroot-dir>”
     CXXFLAGS=”${CXXFLAGS} --sysroot=<sysroot-dir>”
        

When using the cross compiler, the environment will set the CC and LD arguments to their appropriate values, including the --sysroot= value.

So the Makefile should either NOT have CC, CXX, LD, CFLAGS, CXXFLAGS set -- or if set should be overridden by the environment.

As for the other references.. they look to be correct in most cases.  However, "SDKROOT" was something I added specifically for meta-mingw and should NOT be in the documentation.  So please remove references to SDKROOT.
Comment 5 Scott Rifenbark 2015-01-23 23:37:53 UTC
Hi Mark, 

I re-wrote that last section on the Makefile stuff.  See http://www.yoctoproject.org/docs/1.8/adt-manual/adt-manual.html#makefile-based-projects.  Tell me if I captured it okay. 

Also, "SDKROOT" has been eradicated from the YP manual set. 

Thanks, 
Scott
Comment 6 Scott Rifenbark 2015-03-17 18:24:18 UTC
Hi, 

No more feedback on this so I am marking it RESOLVED. Doc flag set to "Done".

Thanks, 
Scott
Comment 7 Costin 2015-04-09 18:08:29 UTC
Hi Mark, Scott,

I just tested this enhancement and I think there is some confusing info in the added/modified chapter of the ADT manual. 
Downwards are steps i took in order to check/test/verify:

1) downloaded last toolchain available (and installed it after):
http://autobuilder.yoctoproject.org/pub/releases/yocto-1.8_m4.rc2/toolchain/x86_64/

2) sourced the environment: 
autobuilder@sstate1:/opt/poky/1.8$ pwd
/opt/poky/1.8
autobuilder@sstate1: . ./environment-setup-i586-poky-linux 

3) checked for few variables as described in the manual:
autobuilder@sstate1:/opt/poky/1.8$ echo $CC
i586-poky-linux-gcc -m32 -march=i586 --sysroot=/opt/poky/1.8/sysroots/i586-poky-linux
autobuilder@sstate1:/opt/poky/1.8$ echo $CXX
i586-poky-linux-g++ -m32 -march=i586 --sysroot=/opt/poky/1.8/sysroots/i586-poky-linux
autobuilder@sstate1:/opt/poky/1.8$ echo $CFLAGS
-O2 -pipe -g -feliminate-unused-debug-types

4) created a Makefile for both a small helloworld.c and an helloworld.cxx. This file contains for both CC and CXX variables a wrong option (-t), meaning that if they are overridden(according to manual), there should be no problem:
autobuilder@sstate1:/opt/poky/1.8/tests_dir$ cat Makefile

buildc:
        CC=gcc -t
        $(CC) hello.c -o hello.o

buildcpp:
        CXX=g++ -t
        $(CXX) hello.cxx -o hellocxx.o

5) tried the Makefile:
autobuilder@sstate1:/opt/poky/1.8/tests_dir$ sudo make buildc
CC=gcc -t
/bin/sh: 1: -t: not found
make: *** [buildc] Error 127

autobuilder@sstate1:/opt/poky/1.8$ sudo make buildcpp
CXX=g++ -t
/bin/sh: 1: -t: not found
make: *** [buildcpp] Error 127

As a result of the above, i believe that there is an error in the manual, since local Makefile variables are not overridden by the environment ones. I also tried other variables (CFLAGS) and behavior is the same. I also tried without -t option and everything is fine, meaning OS gcc and g++ are used.     
  
Costin
Comment 8 Scott Rifenbark 2015-04-09 18:14:59 UTC
Hey Costin, 

So thanks for looking at this.  What would you say the fix is here for the docs?  Should we remove that part about the running the cross-toolchain environment setup script overriding any settings you might have in your Makefile?

Scott
Comment 9 Costin 2015-04-13 08:42:23 UTC
Hi Scott,

I realized I made a small mistake in my previous comment, but I will correct it here. Also, in my opinion the section for Makefile stuff should look something like:

For Makefile-based projects, the cross-toolchain environment variables established by running the cross-toolchain environment 
setup script are subject to general make rules. Suppose the resulted environment variables look like this, 3 cases apply:

     CC=i586-poky-linux-gcc -m32 -march=i586 --sysroot=/opt/poky/1.8/sysroots/i586-poky-linux
     LD=i586-poky-linux-ld --sysroot=/opt/poky/1.8/sysroots/i586-poky-linux
     CFLAGS=-O2 -pipe -g -feliminate-unused-debug-types
     CXXFLAGS=-O2 -pipe -g -feliminate-unused-debug-types	
	 
Case 1: None of these variables are set in the Makefile
The result will be that make considers the variables as set from environment.
eg. of Makefile content:
build:
    echo $(CC)
    echo $(LD)
    echo $(CFLAGS)
    echo $(CXXFLAGS)
	
Case 2: Variables are set in Makefile:
The result will be that these variables override the content of those from environment.
eg. of Makefile content:
CC=gcc
LD=ld
CFLAGS=-g
CXXFLAGS=$(CFLAGS) -O
build:
        echo $(CC)
        echo $(LD)
        echo $(CFLAGS)
        echo $(CXXFLAGS)
		
Case 3: Variables are set when make is executed from command line:
The result is that no matter what the Makefile contains, the respective variable will be overridden with the command line content.
In this case, also environment variables are not considered. The content of Makefile is the same as on case 2.
eg.: make CFLAGS='-p' build

If the desired behavior is to override any Makefile variable with the content of those from environment, then the "-e" flag for make should be used.  
eg.:  make -e build


Thank you,
Costin
Comment 10 Scott Rifenbark 2015-04-13 14:31:30 UTC
Costin, 

I updated that section based on your suggestions.  Note that I did not provide example output as your explanation did.  I think the points for the three cases can be make without those.

You can see the modified section at http://www.yoctoproject.org/docs/1.8/adt-manual/adt-manual.html#makefile-based-projects.  Please let me know of any issues or changes that might still be needed.

Note - I am setting the target for this bug to 1.9 M1 as the deadline for doc changes to 1.8 has passed.

Thanks,
Scott
Comment 11 Scott Rifenbark 2015-05-04 21:17:01 UTC
Setting status to RESOLVED as I have had no feedback on it.  Assuming it is okay.

Scott
Comment 12 Costin 2015-06-15 09:56:24 UTC
Hi Scott,

I think there is a small mistake in the manual:

As it is now:
For Makefile-based projects, the cross-toolchain environment variables established by running the cross-toolchain environment setup script override any settings you might have in your Makefile. For example, if you had settings such as the following in your Makefile, the environment variables defined by the script would override them: 

Should be:
For Makefile-based projects, the cross-toolchain environment variables established by running the cross-toolchain environment setup script are overridden by those in your Makefile. For example, if you had settings such as the following in your Makefile, the environment variables defined by the script would be overridden: 
...

Thank you,

Costin
Comment 13 Scott Rifenbark 2015-06-15 12:31:36 UTC
Hi Costin, 

Since this change was made in the 1.8 manual as noted in Comment 10, further work has been done to that section for the upcoming YP release.  Could you look at that new work and see if that addresses your concerns?  You can see the changes here - http://www.yoctoproject.org/docs/1.9/adt-manual/adt-manual.html#makefile-based-projects.

If this section in the 1.9 manual is okay, then I can push it into the fido tree for the latest 1.8 manuals online.  

Thanks, 
Scott
Comment 14 Stephen K Jolley 2015-07-23 14:54:33 UTC
Costin,   Please reply to Scott's comment.
Comment 15 Costin 2015-07-27 14:34:10 UTC
Hi,

Yes, looks fine now. 

Cositn
Comment 16 Costin 2015-07-27 14:34:47 UTC
Marking as verified.