LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-13-2014, 09:36 PM   #1
georgewhr
Member
 
Registered: Nov 2012
Location: SF Bay Area
Posts: 47

Rep: Reputation: Disabled
Makefile can't export variable


Here is the code:
MY_FLAG=0
ifeq ($(chipset),y)
MY_FLAG+=1
export MY_FLAG
endif


It get error once I compiled it, any suggestion?
 
Old 08-15-2014, 09:37 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
make has make variables, bash has shell variables, your environment has environment variables. export is a bash command to set an environment variable from a shell variable. There is no need to do this with make variables, since you have full control over the things make runs. Are you trying to cause a make variable to be persistent after make runs? This is not supported by make, and the environment that it is using is discarded when it completes. You could use the source command to run a bash script in your current environment.
 
Old 08-15-2014, 01:27 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I need a better example of where that code exists and what you're trying to do with it.

An example is that I have a script which I invoke to perform two make actions. One is a normal Makefile for Linux gcc of C based code. The second one is a Qt Makefile which was autocreated by qmake and as a result is different, plus also self contained. My main point was that I wanted to control my version, date, and time of compile and not have them re-generated by macro substitution in the code or within the Makefiles because the time would be different. As a result I had to figure out how to declare variables in the outer BASH shell script to be exported to the two Makefiles which would import them and agree that they were valid variables.

This may not be what you're trying to do, but here's the example and how it worked:

Again, example is BASH script running as my primary interface, defining variables for Version and Date/Time of build, and then running two different Makefiles:

Code:
# From within the BASH script
export RELEASE_VER=X.y.z
export BLD_DATE=`date +%D-%T`
Next step was still within that BASH script to make variables which were acceptable to the various Makefiles:

Code:
DFLAGS=
DFLAGS="$DFLAGS -D'__APP_VER__=\"$RELEASE_VER\"'"        # Adds release version and defines macro for program use
UIDEFINES="'__APP_VER__=\"$RELEASE_VER\"'"               # (GUI) Adds release version and defines macro for program use
UIDEFINES="$UIDEFINES -D'__BUILD_DATE__=\"$BLD_DATE\"'"  # (GUI) Adds build date and defines macro for program use

export DFLAGS
export UIDEFINES

cd $HOME/AppDirectory;
make;                            # Run make for main application

cd $HOME/GuiDirectory;
make;                            # Run make for Qt GUI

The "App" Makefile is pretty generic, here are some relevant lines from it, and it works for me, I get things working and don't experiment if I don't have to go any further, some may have thoughts and better ways, I just stopped when it did what I wanted.

And of course I've redacted out actual file and final names with generic replacement words.

Code:
START=`pwd`

CFLAGS= -I. -O0 -ggdb -Wformat=2 -Werror -Wall -Wextra -Wswitch-default -Wswitch-enum -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn

# Required libraries required for certain computations
LFLAGS= -lm -ldl

OBJS= <my list of objects> filename1.o filename2.o etc ...

GCC= /usr/bin/gcc

%.o:	%.c
	$(GCC) $(CFLAGS) $(DFLAGS) -c $<
# Notice above where DFLAGS is used, that came from my calling script

app:	$(OBJS)
	$(GCC) $(OBJS) $(LFLAGS) -o app
Next are some portions of my Qt Makefile which originally was is typically auto-generated by qmake, and I had to define a .pro file which uses the name UIDEFINES, the symbol I exported out of my calling BASH script. It merely turns out that the form of how those variables are used are different for this make versus the classical gcc type of make file.

Code:
CC            = gcc
CXX           = g++
DEFINES       = -D$(UIDEFINES) -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS        = -pipe -ggdb -Wl,--export-dynamic -O2 -Wall -W -D_REENTRANT $(DEFINES)
CXXFLAGS      = -pipe -ggdb -Wno-write-strings -Wl,--export-dynamic -O2 -Wall -W -D_REENTRANT $(DEFINES)
The Qt Makefile is just different and so you see how I had to differently construct that UIDEFINES variable to properly get it to be interpreted within the Qt Makefile.

This is probably a lot more complicated than what you were trying to do.

Note a very important point is that you can invoke make with the -d argument or --debug=level to specify a level of debug and see the actions of make. That's pretty much how I debugged this to get my variables properly interpreted within each Makefile.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Export variable as contents of another variable jnojr Linux - Newbie 3 05-08-2012 02:48 PM
.sym not being generated by -export-symbols in Makefile.am hedpe Programming 0 04-20-2011 05:16 PM
export a variable vinaytp Linux - Newbie 2 02-04-2010 11:45 PM
What does export do in Makefile? vipulc Linux - General 1 06-20-2006 08:37 AM
export cd variable? rjwhite Linux - Games 1 12-17-2005 05:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration