Thread: What happens when an empty variable is exported

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,462

    What happens when an empty variable is exported

    So for example I have this:
    Code:
    ifeq "$(PWD)" ""
    uname_s:=WIN32
    _WIN32:=1
    
    uname_p:=$(or $(PROCESSOR_ARCHITEW6432),$(PROCESSOR_ARCHITECTURE))
    AMD64:=$(if $(filter AMD64,$(uname_p)),1)
    x86:=$(if $(filter x86,$(uname_p)),1)
    
    cpu_sfx:=$(if $(is_amd64),.amd64.,.)
    else
    uname_s:=$(shell uname -s)
    LINUX:=$(if $(filter Linux,$(uname_s)),1)
    OSX:=$(if $(filter Darwin,$(uname_s)),1)
    
    uname_p:=$(shell uname -p)
    AMD64:=$(if $(filter AMD64 x86_64,$(uname_p)),1)
    IA32:=$(if $(filter %86,$(uname_p)),1)
    ARM:=$(if $(filter arm%,$(uname_p)),1)
    
    cpu_sfx:=$(or $(if $(is_arm),.arm.),$(if $(is_amd),.amd64.))
    cpu_sfx:=$(or $(cpu_sfx),$(if $(i32),.ia32.,.))
    endif
    ...
    export PATH
    export _DEBUG
    export TOP_DIR
    export LIBRARY_PATH
    
    export _WIN32
    export LINUX
    export OSX
    export AMD64
    export x86
    export IA32
    export ARM
    ...
    Do the variables get defined anyways or are they skipped? Asking because I want to know the result of for example
    Code:
    #ifdef _WIN32
    when _WIN32 was empty, I never tried before and since I'm still implementing some new functions I'm not gonna see the result any time soon.

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,462
    Also I'm at my wits end trying to capture the output of a shell command here:
    Code:
    ifneq "$(is_gnu)" ""
    StrInc="$(hash)include <$1s>" | $(CC) -c -x c -
    TryInc=$(shell $(call StrInc,$1))
    CanInc=$(if $(findstring error,$(call TryInc,$1)),,1)
    HAVE_PTHREAD:=$(call CanInc,pthread.h)
    endif
    Would appreciate help fixing it, currently HAVE_PTHREAD should be empty because of the extra 's' I added for checking the functionality works as intended, instead I get '1' in it

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    907
    Can't find, now, the actual reference on make manual, but uninitialized variables aren't exported:
    Code:
    # Makefile
    
    #X=1
    export X
    
    all:
      make -f Makefile.2
    Code:
    # Makefile.2
    ifdef X
      MSG=Imported
    else
      MSG=Not imported
    endif
    
    all:
      @echo $(MSG)
    Running:
    Code:
    $ make
    make -f Makefile.2
    make[1]: Entering directory './tmp'
    Not imported
    make[1]: Leaving directory './tmp'
    Change to X=1 and it is ok.
    Last edited by flp1969; 11-26-2021 at 08:54 AM.

  4. #4
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,462
    Quote Originally Posted by flp1969 View Post
    Can't find, now, the actual reference on make manual, but uninitialized variables aren't exported:
    Code:
    # Makefile
    
    #X=1
    export X
    
    all:
      make -f Makefile.2
    Code:
    # Makefile.2
    ifdef X
      MSG=Imported
    else
      MSG=Not imported
    endif
    
    all:
      @echo $(MSG)
    Running:
    Code:
    $ make
    make -f Makefile.2
    make[1]: Entering directory './tmp'
    Not imported
    make[1]: Leaving directory './tmp'
    Change to X=1 and it is ok.
    Good to know, thx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to check "struct tm" variable is empty?
    By krishnampkkm in forum C Programming
    Replies: 2
    Last Post: 01-11-2021, 10:50 PM
  2. Replies: 2
    Last Post: 03-08-2011, 02:16 AM
  3. Array crashing when it has an empty variable?
    By omnificient in forum C Programming
    Replies: 5
    Last Post: 01-02-2008, 10:07 AM
  4. Problem in returning value from the dll exported function
    By dattaforit in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2006, 04:30 AM
  5. makefile exported by vc 6.0 doesn't work
    By wow in forum Windows Programming
    Replies: 7
    Last Post: 03-24-2006, 04:20 PM

Tags for this Thread