This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 213915 - Generated Makefile have incorrect handling of environment variables which are also variables used in Make rules
Summary: Generated Makefile have incorrect handling of environment variables which are...
Status: REOPENED
Alias: None
Product: cnd
Classification: Unclassified
Component: Project (show other bugs)
Version: 7.2
Hardware: All All
: P3 normal with 1 vote (vote)
Assignee: issues@cnd
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-10 17:49 UTC by eda
Modified: 2012-06-12 12:00 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description eda 2012-06-10 17:49:33 UTC
Environment variables are used by default and convention for some things in a Makefile. They may be used to pass parameters to the compiler to compile for certain target hardware. See the following for variables which are used in built in rules.

http://www.gnu.org/savannah-checkouts/gnu/make/manual/html_node/Implicit-Variables.html

The Makefile generated by NetBeans uses the variables of these names but overwrites them when they come from the environment. To test compare the result of:

(if using bash)
export CXXFLAGS=-pipe
make

with

make CXXFLAGS=-pipe

. Both cases should be handled the same. They are not. They are both handled incorrectly, but differently.

The most generally correct behavior is to add parameters set in the project by NetBeans to those of the environment variable. For example, if the parameter
-pipe
were to be specified in the NetBeans project, the Makefile would contain the following

CXXFLAGS += -pipe
export CXXFLAGS
Comment 1 eda 2012-06-10 18:10:19 UTC
In the second case, like

make CXXFLAGS=-pipe

current behavior is to replace the flags in the NetBeans project. The CXXFLAGS from the environment may not be set specific to the project and may therefore lack parameters needed for the specific project. This is a reason to aggregate the values from the environment and within the project.
Comment 2 Leonid Lenyashin 2012-06-11 07:18:38 UTC
From the description it looks like that you use IDE generated makefiles. In this case you should specify your flags in Project Properties. Let us know if it does not solve your issue. Fill free to reopen the bug.
Comment 3 eda 2012-06-11 09:28:10 UTC
Yes, this issue is with IDE generated Makefiles.

The issue is not about a particular project using NetBeans. It relates much more to compilation of multiple projects on the same system and support of a CND project for multiple platforms simultaneously.

What I described as desired behavior of the Makefiles is also a convention. The convention is that way to support use of both build parameters coming from the environment and those specified within a specific project simultaneously.

One recurring circumstance which causes a need for the described desired behavior of Makefiles is when the party building a project is not a developer of the project.

Maybe some examples will help to understand the general issue.

Example 0:
Consider an operating system where the entire system is built from the source code by the user installing the OS, such as Exherbo or Gentoo. There the user sets environment variables (CFLAGS, CXXFLAGS, LDFLAGS) at time of the build and OS install which are applied to all projects. This happens because the environment variables are used in addition to with the variables specified in each of the projects being compiled. Each project or package has its own compile flags it needs, which in NetBeans is set in the Project Properties. In addition it uses flags which are specified at the time the whole system is being built. Those flags are unforeseeable to the authors of the hundreds or thousands of packages being built and also to me. Some such flags may be to: compile for the local hardware; tune optimization; enable profiling; or select a binary linking format such as ELF or whatever may succeed it. Where Makefiles are employed, well designed Makefiles accommodate this.

Example 1:
Cross platform compilation:
The project has compiler flags for building on the default platform which is the hosting platform. A compilation environment for cross platform compilation is provided to by a third party. It sets the compilation and linking flags in environment variables appropriate for the target platform. This third party is not going to modify any NetBeans project. They only provide the compilation environment for their supported target platform. Fortunately, in our example, all Makefiles of all compiled projects are and have the expected behavior of automatically accumulating the compile parameters from environment variables with those specific to the project, which for NetBeans projects were specified in the Project Properties, and cross platform building is easily accomplished without modification of any of the projects being built by the building party.

Example 2:
A system of software comprised of multiple executables and libraries are being compiled or built. The third party supplier of a library uses NetBeans for their development. The user of the library does not. If the generated Makefile of that library does not handle environment variables for the build in the conventional manner, special effort will need to be made to get that library to build with the desired parameters.

I hope this will has helped to illustrate by specific examples what general issue is. If I can help by further description or explanation of something, questions are welcome.
Comment 4 Leonid Lenyashin 2012-06-12 12:00:00 UTC
What you really want is in reality a mixture of concepts: managed and unmanaged projects.
Managed projects use IDE Generated Makefiles and offer users simplicity and no burden of Makefiles coding.
Unmanaged projects are built around user provided makefiles and provide flexibility and ability to manage non-trivial cases.
You basically want both. This mixture might look easy to create, but in reality it will be very error-prone and will generate a stream of new bugs as it will work not the way you expect it in every other non-trivial case.

I'll keep this request as an enhancement, meanwhile I advise you to look towards unmanaged projects and pay the price of taking care of your Makefiles for the sake of flexibility and portability.