简体   繁体   中英

Makefile variable substitution sometimes ignored

Compiling a CUDA enabled version of aircrack-ng that hasn't been bug-fixed in a while so needed a bit of patching to get most of the way there.

Basically, the make cannot find the relevant compiler ( nvcc ) for this one section of code;

Relevent Makefile section

ifeq ($(CUDA), true)
CFLAGS += -DCUDA_ENABLED

NVCC := $(CUDA_BIN)/nvcc
INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/include
COMMONFLAGS += $(INCLUDES) -DUNIX

NVCCFLAGS += --compiler-options -fno-strict-aliasing --host-compilation=C $(COMMONFLAGS)

# Change this only if you have COMPUTE > 1.0
NVCCFLAGS += -maxrregcount 12

# Enable this for extra compiler and as output
#NVCCFLAGS += --ptxas-options "-v" --verbose

LIBSSL += -L$(CUDA_INSTALL_PATH)/lib -L$(CUDA_INSTALL_PATH)/lib64 -lcuda -lcudart

%.o : %.cu   
    $(NVCC) $(NVCCFLAGS) $(SMVERSIONFLAGS) -o $@ -c $<
endif

Relevant Make output

/nvcc --compiler-options -fno-strict-aliasing --host-compilation=C -I. -I/include -DUNIX -maxrregcount 12  -o cudacrypto.o -c cudacrypto.cu
make[1]: /nvcc: Command not found
make[1]: *** [cudacrypto.o] Error 127
make[1]: Leaving directory `/home/bolster/src/aircrack-ng-cuda/src'
make: *** [install] Error 2

As you can see it looks like make is dropping the environment variables 'CUDA_BIN'.

Output of echo $CUDA_BIN

/usr/local/cuda/bin

Output of which nvcc

/usr/local/cuda/bin/nvcc

I am not a make-guru by any stretch, so if I'm doing something patently obviously wrong, forgive me.

After trying hard coding the nvcc flag with the full path, that section compiles, but when it comes to a crypto section (involving libssl) it cannot find the necessary libraries, and in a similar fashion as above isn't replacing 'CUDA_INSTALL_PATH', even though it is in the environment, which indicates to be that something weird is going on.

It's usually not a good idea to rely on environmental variables in a makefile. Making the value explicit in the makefile, or specifying it in the call (eg make CUDA=... ) is actually the correct way to go.

If you still want to use the value from the environment, I don't know why your makefile isn't working, but you can try this:

 CUDA_BIN := $(shell echo $$CUDA_BIN)

You can only use environment variables in a Makefile if they have been exported. Ie if you do:

export CUDA_BIN=/usr/local/cuda/bin

The more basic command CUDA_BIN=/usr/local/cuda/bin will lead to the correct result for the command echo $CUDA_BIN but will not ensure that the Makefile has access to the variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM