OSX上的makefile路径问题 [英] makefile pathing issues on OSX

查看:59
本文介绍了OSX上的makefile路径问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我想我要尝试最后一次更新,看看它是否可以带我到任何地方.我创建了一个非常小的测试用例.这不应该构建任何东西,它只是测试路径设置.另外,我已经设置了路径,所以没有空格.这是我能想到的最小,最简单的测试用例.

OK, I thought I would try one last update and see if it gets me anywhere. I've created a very small test case. This should not build anything, it just tests the path settings. Also I've setup the path so there are no spaces. The is the smallest, simplest test case I could come up with.

此makefile将设置路径,回显该路径,使用指定的完整路径运行avr-gcc -v,然后尝试在不指定完整路径的情况下运行它.它应该在第二次尝试的路径中找到avr-gcc,但没有.

This makefile will set the path, echo the path, run avr-gcc -v with the full path specified and then try to run it without the full path specified. It should find avr-gcc in the path on the second try, but does not.

makefile

TOOLCHAIN := /Users/justinzaun/Desktop/AVRBuilder.app/Contents/Resources/avrchain


PATH := ${TOOLCHAIN}/bin:${PATH}
export PATH


all:
    @echo ${PATH}
    @echo --------
    "${TOOLCHAIN}/bin/avr-gcc" -v
    @echo --------
    avr-gcc -v

输出

JUSTINs-MacBook-Air:Untitled justinzaun$ make
/Users/justinzaun/Desktop/AVRBuilder.app/Contents/Resources/avrchain/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
--------
"/Users/justinzaun/Desktop/AVRBuilder.app/Contents/Resources/avrchain/bin/avr-gcc" -v
Using built-in specs.
COLLECT_GCC=/Users/justinzaun/Desktop/AVRBuilder.app/Contents/Resources/avrchain/bin/avr-gcc
COLLECT_LTO_WRAPPER=/Users/justinzaun/Desktop/AVRBuilder.app/Contents/Resources/avrchain/bin/../libexec/gcc/avr/4.6.3/lto-wrapper
Target: avr
Configured with: /Users/justinzaun/Development/AVRBuilder/Packages/gccobj/../gcc/configure --prefix=/Users/justinzaun/Development/AVRBuilder/Packages/gccobj/../build/ --exec-prefix=/Users/justinzaun/Development/AVRBuilder/Packages/gccobj/../build/ --datadir=/Users/justinzaun/Development/AVRBuilder/Packages/gccobj/../build/ --target=avr --enable-languages=c,objc,c++ --disable-libssp --disable-lto --disable-nls --disable-libgomp --disable-gdbtk --disable-threads --enable-poison-system-directories
Thread model: single
gcc version 4.6.3 (GCC) 
--------
avr-gcc -v
make: avr-gcc: No such file or directory
make: *** [all] Error 1
JUSTINs-MacBook-Air:Untitled justinzaun$ 



原始问题



Original Question

我正在尝试从makefile内设置路径.我似乎无法在OSX上执行此操作.用PATH := /new/bin/:$(PATH)设置路径不起作用.请参阅下面的我的makefile.

I'm trying to set the path from within the makefile. I can't seem to do this on OSX. Setting the path with PATH := /new/bin/:$(PATH) does not work. See my makefile below.

makefile

PROJECTNAME = Untitled

# Name of target controller
# (e.g. 'at90s8515', see the available avr-gcc mmcu
# options for possible values)
MCU = atmega640

# id to use with programmer
# default: PROGRAMMER_MCU=$(MCU)
# In case the programer used, e.g avrdude, doesn't
# accept the same MCU name as avr-gcc (for example
# for ATmega8s, avr-gcc expects 'atmega8' and 
# avrdude requires 'm8')
PROGRAMMER_MCU = $(MCU)

# Source files
# List C/C++/Assembly source files:
# (list all files to compile, e.g. 'a.c b.cpp as.S'):
# Use .cc, .cpp or .C suffix for C++ files, use .S
# (NOT .s !!!) for assembly source code files.
PRJSRC = main.c   \
         utils.c

# additional includes (e.g. -I/path/to/mydir)
INC = 

# libraries to link in (e.g. -lmylib)
LIBS = 

# Optimization level,
# use s (size opt), 1, 2, 3 or 0 (off)
OPTLEVEL = s



### You should not have to touch anything below this line ###



PATH := /Users/justinzaun/Library/Developer/Xcode/DerivedData/AVR_Builder-gxiykwiwjywvoagykxvmotvncbyd/Build/Products/Debug/AVR\ Builder.app/Contents/Resources/avrchain/bin:/usr/bin:/bin:$(PATH)
CPATH := /Users/justinzaun/Library/Developer/Xcode/DerivedData/AVR_Builder-gxiykwiwjywvoagykxvmotvncbyd/Build/Products/Debug/AVR\ Builder.app/Contents/Resources/avrchain/include


# HEXFORMAT -- format for .hex file output
HEXFORMAT = ihex

# compiler
CFLAGS = -I. $(INC) -g -mmcu=$(MCU) -O$(OPTLEVEL)  \
         -fpack-struct -fshort-enums               \
         -funsigned-bitfields -funsigned-char      \
         -Wall -Wstrict-prototypes                 \
         -Wa,-ahlms=$(firstword                    \
                    $(filter %.lst, $(<:.c=.lst)))

# c++ specific flags
CPPFLAGS = -fno-exceptions                 \
           -Wa,-ahlms=$(firstword          \
           $(filter %.lst, $(<:.cpp=.lst)) \
           $(filter %.lst, $(<:.cc=.lst))  \
           $(filter %.lst, $(<:.C=.lst)))

# assembler
ASMFLAGS = -I. $(INC) -mmcu=$(MCU)          \
           -x assembler-with-cpp            \
           -Wa,-gstabs,-ahlms=$(firstword   \
           $(<:.S=.lst) $(<.s=.lst))

# linker
LDFLAGS = -Wl,-Map,$(TRG).map -mmcu=$(MCU)  \
          -lm $(LIBS)

##### executables ####
CC=avr-gcc
OBJCOPY=avr-objcopy
OBJDUMP=avr-objdump
SIZE=avr-size
AVRDUDE=avrdude
REMOVE=rm -f

##### automatic target names ####
TRG=$(PROJECTNAME).out
DUMPTRG=$(PROJECTNAME).s

HEXROMTRG=$(PROJECTNAME).hex
HEXTRG=$(HEXROMTRG) $(PROJECTNAME).ee.hex

# Start by splitting source files by type
#  C++
CPPFILES=$(filter %.cpp, $(PRJSRC))
CCFILES=$(filter %.cc, $(PRJSRC))
BIGCFILES=$(filter %.C, $(PRJSRC))
#  C
CFILES=$(filter %.c, $(PRJSRC))
#  Assembly
ASMFILES=$(filter %.S, $(PRJSRC))

# List all object files we need to create
OBJDEPS=$(CFILES:.c=.o)     \
        $(CPPFILES:.cpp=.o) \
        $(BIGCFILES:.C=.o)  \
        $(CCFILES:.cc=.o)   \
        $(ASMFILES:.S=.o)

# Define all lst files.
LST=$(filter %.lst, $(OBJDEPS:.o=.lst))

# All the possible generated assembly
# files (.s files)
GENASMFILES=$(filter %.s, $(OBJDEPS:.o=.s))

.SUFFIXES : .c .cc .cpp .C .o .out .s .S \
            .hex .ee.hex .h .hh .hpp

# Make targets:
# all, disasm, stats, hex, writeflash/install, clean
all: $(TRG)

$(TRG): $(OBJDEPS)
    $(CC) $(LDFLAGS) -o $(TRG) $(OBJDEPS)

#### Generating assembly ####
# asm from C
%.s: %.c
    $(CC) -S $(CFLAGS) $< -o $@

# asm from (hand coded) asm
%.s: %.S
    $(CC) -S $(ASMFLAGS) $< > $@

# asm from C++
.cpp.s .cc.s .C.s :
    $(CC) -S $(CFLAGS) $(CPPFLAGS) $< -o $@

#### Generating object files ####
# object from C
.c.o:
    $(CC) $(CFLAGS) -c $< -o $@

# object from C++ (.cc, .cpp, .C files)
.cc.o .cpp.o .C.o :
    $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

# object from asm
.S.o :
    $(CC) $(ASMFLAGS) -c $< -o $@

#### Generating hex files ####
# hex files from elf
.out.hex:
    $(OBJCOPY) -j .text                    \
               -j .data                    \
               -O $(HEXFORMAT) $< $@

.out.ee.hex:
    $(OBJCOPY) -j .eeprom                     \
               --change-section-lma .eeprom=0 \
               -O $(HEXFORMAT) $< $@

#### Information ####
info:
    @echo PATH:
    @echo "$(PATH)"
    $(CC) -v
    which $(CC)

#### Cleanup ####
clean:
    $(REMOVE) $(TRG) $(TRG).map $(DUMPTRG)
    $(REMOVE) $(OBJDEPS)
    $(REMOVE) $(LST)
    $(REMOVE) $(GENASMFILES)
    $(REMOVE) $(HEXTRG)

错误

JUSTINs-MacBook-Air:Untitled justinzaun$ make
avr-gcc -I.  -g -mmcu=atmega640 -Os -fpack-struct -fshort-enums -funsigned-bitfields -funsigned-char -Wall -Wstrict-prototypes -Wa,-ahlms=main.lst -c main.c -o main.o
make: avr-gcc: No such file or directory
make: *** [main.o] Error 1
JUSTINs-MacBook-Air:Untitled justinzaun$

如果我将CC=更改为包括完整路径:

If I change my CC= to include the full path:

CC=/Users/justinzaun/Library/Developer/Xcode/DerivedData/AVR_Builder-gxiykwiwjywvoagykxvmotvncbyd/Build/Products/Debug/AVR\ Builder.app/Contents/Resources/avrchain/bin/avr-gcc

然后找到它,但这似乎不是正确的做事方法.例如,它试图使用系统as而不是正确路径中的那个.

then it finds it, but this doesn't seem the correct way to do things. For instance its trying to use the system as not the one in the correct path.

更新-可以肯定的是,我也添加了ls命令的输出,因此每个人都知道该文件存在.另外,我还向makefile文件中添加了一个make info目标,并显示了该输出.

update - Just to be sure, I'm adding the output of my ls command too so everyone knows the file exist. Also I've added a make info target to the makefile and showing that output as well.

JUSTINs-MacBook-Air:Untitled justinzaun$ ls /Users/justinzaun/Library/Developer/Xcode/DerivedData/AVR_Builder-gxiykwiwjywvoagykxvmotvncbyd/Build/Products/Debug/AVR\ Builder.app/Contents/Resources/avrchain/bin
ar      avr-elfedit avr-man     avr-strip   objcopy
as      avr-g++     avr-nm      avrdude     objdump
avr-addr2line   avr-gcc     avr-objcopy c++     ranlib
avr-ar      avr-gcc-4.6.3   avr-objdump g++     strip
avr-as      avr-gcov    avr-ranlib  gcc
avr-c++     avr-gprof   avr-readelf ld
avr-c++filt avr-ld      avr-size    ld.bfd
avr-cpp     avr-ld.bfd  avr-strings nm
JUSTINs-MacBook-Air:Untitled justinzaun$ 

make info的输出,其中\在我的路径中

Output of make info with the \ in my path

JUSTINs-MacBook-Air:Untitled justinzaun$ make info
PATH:
/Users/justinzaun/Library/Developer/Xcode/DerivedData/AVR_Builder-gxiykwiwjywvoagykxvmotvncbyd/Build/Products/Debug/AVR\ Builder.app/Contents/Resources/avrchain/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
avr-gcc -v
make: avr-gcc: No such file or directory
make: *** [info] Error 1
JUSTINs-MacBook-Air:Untitled justinzaun$ 

make info的输出,其中\不在我的路径中

Output of make info with the \ not in my path

JUSTINs-MacBook-Air:Untitled justinzaun$ make info
PATH:
/Users/justinzaun/Library/Developer/Xcode/DerivedData/AVR_Builder-gxiykwiwjywvoagykxvmotvncbyd/Build/Products/Debug/AVR Builder.app/Contents/Resources/avrchain/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
avr-gcc -v
make: avr-gcc: No such file or directory
make: *** [info] Error 1
JUSTINs-MacBook-Air:Untitled justinzaun$ 

更新-当我如上所述将CC设置为包括完整路径时,这是make info的结果.

update - When I have my CC set to include the full path as described above, this is the result of make info.

JUSTINs-MacBook-Air:Untitled justinzaun$ make info
PATH:
/Users/justinzaun/Library/Developer/Xcode/DerivedData/AVR_Builder-gxiykwiwjywvoagykxvmotvncbyd/Build/Products/Debug/AVR Builder.app/Contents/Resources/avrchain/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
/Users/justinzaun/Library/Developer/Xcode/DerivedData/AVR_Builder-gxiykwiwjywvoagykxvmotvncbyd/Build/Products/Debug/AVR\ Builder.app/Contents/Resources/avrchain/bin/avr-gcc -v
Using built-in specs.
COLLECT_GCC=/Users/justinzaun/Library/Developer/Xcode/DerivedData/AVR_Builder-gxiykwiwjywvoagykxvmotvncbyd/Build/Products/Debug/AVR Builder.app/Contents/Resources/avrchain/bin/avr-gcc
COLLECT_LTO_WRAPPER=/Users/justinzaun/Library/Developer/Xcode/DerivedData/AVR_Builder-gxiykwiwjywvoagykxvmotvncbyd/Build/Products/Debug/AVR Builder.app/Contents/Resources/avrchain/bin/../libexec/gcc/avr/4.6.3/lto-wrapper
Target: avr
Configured with: /Users/justinzaun/Development/AVRBuilder/Packages/gccobj/../gcc/configure --prefix=/Users/justinzaun/Development/AVRBuilder/Packages/gccobj/../build/ --exec-prefix=/Users/justinzaun/Development/AVRBuilder/Packages/gccobj/../build/ --datadir=/Users/justinzaun/Development/AVRBuilder/Packages/gccobj/../build/ --target=avr --enable-languages=c,objc,c++ --disable-libssp --disable-lto --disable-nls --disable-libgomp --disable-gdbtk --disable-threads --enable-poison-system-directories
Thread model: single
gcc version 4.6.3 (GCC) 
which /Users/justinzaun/Library/Developer/Xcode/DerivedData/AVR_Builder-gxiykwiwjywvoagykxvmotvncbyd/Build/Products/Debug/AVR\ Builder.app/Contents/Resources/avrchain/bin/avr-gcc
/Users/justinzaun/Library/Developer/Xcode/DerivedData/AVR_Builder-gxiykwiwjywvoagykxvmotvncbyd/Build/Products/Debug/AVR Builder.app/Contents/Resources/avrchain/bin/avr-gcc
JUSTINs-MacBook-Air:Untitled justinzaun$ 

推荐答案

我在OSX和Linux上尝试了您的示例,并获得了与您相同的结果.我不太明白为什么它不起作用(并且很想知道),但是我确实有两种可能会有所帮助的解决方法.

I tried your example on OSX and Linux, and got the same results that you did. I don't quite understand why that isn't working (and would love to know), but I do have two workarounds that might help.

导出外壳

而不是在Makefile中设置PATH,而是像这样覆盖SHELL:

Instead of setting the PATH in your Makefile, override the SHELL like this:

export SHELL=/Users/whatever/avr-dir/wrapper

以下是该包装的可能版本:

Here's a possible version of that wrapper:

#!/bin/bash
PATH="/Users/whatever/avr-dir:${PATH}"
/bin/bash "$@"

Make将调用此包装器以运行yoru食谱的每一行.这有点难看,但是它确实在OSX上对我有用.

Make will invoke this wrapper to run each line of yoru recipes. This is a little ugly, but it did work for me on OSX.

外部

修复make之外的PATH.也许创建一个每次登录运行一次的脚本来修复外壳中的PATH,或者创建一个小的脚本(我通常将其称为mk)来修复PATH,然后调用make传递任何参数.这是一个例子:

Fix the PATH outside of make. Perhaps create a script that you run once per login that fixes the PATH in your shell, or create a small script (I usually call it mk) that fixes the PATH and then invokes make passing along any parameters. Here's an exmaple:

#!/bin/bash
PATH="/Users/whatever/avr-dir:${PATH}" exec make "$@"

我知道您要求一个Makefile解决方案,但我想无论如何我都会提到此选项.这只是我的意见,但是类似PATH的东西通常是特定于机器的(而不是特定于项目的),我更喜欢将它们与源代码分开.

I know you asked for a Makefile solution, but I thought I would mention this option anyway. It is just my opinion, but things like PATHs tend to be machine specific (and not project specific), and I prefer to keep them separate from source code.

这篇关于OSX上的makefile路径问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆