I am trying to run some old Fortran code of my project team in ubuntu 16.04. I have not done any modifications to the existing code.
All I have done is installed gfortran, opened a terminal, and went to the file location using "cd" command. Here I have many files, but just consider this three, a script file compile.sh, and two makefiles counter.make and remail.make.
In compile.sh
make -f counter.make
make -f remail.make
In counter.make
SOURCE_APPLI=../SOURCES_COUNTERFLOW/
SOURCES_f77 = $(SOURCE_APPLI)table.f
TARGET = unst.e
OBJECTS = $(SOURCES_f77:.f=.o)
COMPILE = f77 -f
.f90.o :
$(COMPILE1) -o $*.o -c $*.f90
.f.o :
$(COMPILE) -o $*.o -c $*.f
$(TARGET) : $(OBJECTS)
$(COMPILE) $(OBJECTS) -o $#
del :
$(DELETE) $(OBJECTS)
In remail.make
SOURCE_APPLI= ../SOURCES_COUNTERFLOW/
$(SOURCE_APPLI)grcom.f
TARGET = remail.e
OBJECTS = $(SOURCES_f77:.f=.o)
COMPILE = f90
.f90.o :
$(COMPILE) -o $*.o -c $*.f90
.f.o :
$(COMPILE) -o $*.o -c $*.f
$(TARGET) : $(OBJECTS)
$(COMPILE) $(OBJECTS) -o $#
del :
$(DELETE) $(OBJECTS)
When I run compile.sh, I got an error as shown below
f77: error: unrecognized command line option ‘-f’
counter.make:29: recipe for target 'unst.e' failed
make: *** [unst.e] Error 1
make: 'remail.e' is up to date.
So my question is what is the difference with and without using -f option in the f77 command line?
The f77 manual page at https://www.unix.com/man-page/v7/1/f77/ says
-f Use a floating point interpreter
(for PDP11's that lack 11/70-style floating point).
If you are not on a PDP-11, it appears that this option would perhaps not be useful at all in the first place.
Probably still review the local documentation, ideally for the system where this set of Makefiles was once created.
GNU Fortran 77 appears to use this option to specify various language options, but then it would not be useful on its own (it takes arguments like -fdollar-ok to enable something called "dollar ok", for example. See the linked manual for an extensive list of these options and their meaning).
I am trying to compile a .ttcn file with my a generated makefile with role is to create a .cc and .hh file.
But when I run the make command I have a problem with the .o file, it is not generated so my .exe is not generated too
here is the error I have and my Makefile:
Makefile:
# This Makefile was generated by the Makefile Generator
# of the TTCN-3 Test Executor version CRL 113 200/5 R2A
# for U-TMV\qi11091 (qi11091#WMUC-0118) on Thu Apr 9 16:49:49 2015
# Copyright Ericsson Telecom AB 2000-2014
# The following make commands are available:
# - make, make all Builds the executable test suite.
# - make archive Archives all source files.
# - make check Checks the semantics of TTCN-3 and ASN.1 modules.
# - make clean Removes all generated files.
# - make compile Translates TTCN-3 and ASN.1 modules to C++.
# - make dep Creates/updates dependency list.
# - make executable Builds the executable test suite.
# - make library Builds the library archive.
# - make objects Builds the object files without linking the executable.
# WARNING! This Makefile can be used with GNU make only.
# Other versions of make may report syntax errors in it.
#
# Do NOT touch this line...
#
.PHONY: all shared_objects executable library objects check clean dep archive
.SUFFIXES: .d
#
# Set these variables...
#
# The path of your TTCN-3 Test Executor installation:
# Uncomment this line to override the environment variable.
# TTCN3_DIR =
# Your platform: (SOLARIS, SOLARIS8, LINUX, FREEBSD or WIN32)
PLATFORM = WIN32
# Your C++ compiler:
# (if you change the platform, you may need to change the compiler)
CXX = g++
# Flags for the C++ preprocessor (and makedepend as well):
CPPFLAGS = -D$(PLATFORM) -I$(TTCN3_DIR)/include
# Flags for dependency generation
CXXDEPFLAGS = -MM
# Flags for the C++ compiler:
CXXFLAGS = -Wall
# Flags for the linker:
LDFLAGS =
ifeq ($(PLATFORM), WIN32)
# Silence linker warnings.
LDFLAGS += -Wl,--enable-auto-import,--enable-runtime-pseudo-reloc
endif
# Utility to create library files
AR = ar
ARFLAGS =
# Flags for the TTCN-3 and ASN.1 compiler:
COMPILER_FLAGS = -L
# Execution mode: (either ttcn3 or ttcn3-parallel)
TTCN3_LIB = ttcn3-parallel
# The path of your libxml2 installation:
# If you do not have your own one, leave it unchanged.
XMLDIR = $(TTCN3_DIR)
# Directory to store the archived source files:
ARCHIVE_DIR = backup
#
# You may change these variables. Add your files if necessary...
#
# TTCN-3 modules of this project:
TTCN3_MODULES = TTCN3SessionSetup.ttcn
# ASN.1 modules of this project:
ASN1_MODULES =
# C++ source & header files generated from the TTCN-3 & ASN.1 modules of
# this project:
GENERATED_SOURCES = $(TTCN3_MODULES:.ttcn=.cc) $(ASN1_MODULES:.asn=.cc)
GENERATED_HEADERS = $(GENERATED_SOURCES:.cc=.hh)
# C/C++ Source & header files of Test Ports, external functions and
# other modules:
USER_SOURCES =
USER_HEADERS = $(USER_SOURCES:.cc=.hh)
# Object files of this project that are needed for the executable test suite:
OBJECTS = $(GENERATED_OBJECTS) $(USER_OBJECTS)
GENERATED_OBJECTS = $(GENERATED_SOURCES:.cc=.o)
USER_OBJECTS = $(USER_SOURCES:.cc=.o)
DEPFILES = $(USER_OBJECTS:.o=.d) $(GENERATED_OBJECTS:.o=.d)
# Other files of the project (Makefile, configuration files, etc.)
# that will be added to the archived source files:
OTHER_FILES = Makefile
# The name of the executable test suite:
EXECUTABLE = TTCN3SessionSetup.exe
LIBRARY = libTTCN3SessionSetup.a
TARGET = $(EXECUTABLE)
#
# Do not modify these unless you know what you are doing...
# Platform specific additional libraries:
#
SOLARIS_LIBS = -lsocket -lnsl -lxml2
SOLARIS8_LIBS = -lsocket -lnsl -lxml2
LINUX_LIBS = -lxml2
FREEBSD_LIBS = -lxml2
WIN32_LIBS = -lxml2
#
# Rules for building the executable...
#
all: $(TARGET) ;
executable: $(EXECUTABLE) ;
library: $(LIBRARY) ;
objects: $(OBJECTS) compile;
$(EXECUTABLE): $(OBJECTS)
if $(CXX) $(LDFLAGS) -o $# $^ \
-L$(TTCN3_DIR)/lib -l$(TTCN3_LIB) \
-L$(OPENSSL_DIR)/lib -lcrypto \
-L$(XMLDIR)/lib $($(PLATFORM)_LIBS); \
then : ; else $(TTCN3_DIR)/bin/titanver $(OBJECTS); exit 1; fi
$(LIBRARY): $(OBJECTS)
$(AR) -r $(ARFLAGS) $(LIBRARY) $(OBJECTS)
.cc.o .c.o:
$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $# $<
.cc.d .c.d:
#echo Creating dependency file for '$<'; set -e; \
$(CXX) $(CXXDEPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $< \
| sed 's/\($*\)\.o[ :]*/\1.o $# : /g' > $#; \
[ -s $# ] || rm -f $#
$(GENERATED_SOURCES) $(GENERATED_HEADERS): compile
#if [ ! -f $# ]; then $(RM) compile; $(MAKE) compile; fi
check: $(TTCN3_MODULES) $(ASN1_MODULES)
$(TTCN3_DIR)/bin/compiler -s $(COMPILER_FLAGS) $^
compile: $(TTCN3_MODULES) $(ASN1_MODULES)
$(TTCN3_DIR)/bin/compiler $(COMPILER_FLAGS) $^ - $?
touch $#
clean:
-$(RM) $(EXECUTABLE) $(LIBRARY) $(OBJECTS) $(GENERATED_HEADERS) \
$(GENERATED_SOURCES) compile $(DEPFILES) \
tags *.log
dep: $(GENERATED_SOURCES) $(USER_SOURCES) ;
ifeq ($(findstring n,$(MAKEFLAGS)),)
ifeq ($(filter clean check compile archive diag,$(MAKECMDGOALS)),)
-include $(DEPFILES)
endif
endif
archive:
mkdir -p $(ARCHIVE_DIR)
tar -cvhf - $(TTCN3_MODULES) $(ASN1_MODULES) \
$(USER_HEADERS) $(USER_SOURCES) $(OTHER_FILES) \
| gzip >$(ARCHIVE_DIR)/`basename $(TARGET) .exe`-`date '+%y%m%d-%H%M'`.tgz
diag:
$(TTCN3_DIR)/bin/compiler -v 2>&1
$(TTCN3_DIR)/bin/mctr_cli -v 2>&1
$(CXX) -v 2>&1
$(AR) -V 2>&1
#echo TTCN3_DIR=$(TTCN3_DIR)
#echo OPENSSL_DIR=$(OPENSSL_DIR)
#echo XMLDIR=$(XMLDIR)
#echo PLATFORM=$(PLATFORM)
#
# Add your rules here if necessary...
#
And here is my error
qi11091#WMUC-0118 ~/Documents/TITAN_Command_Line/FirstTest
$ make
/cygdrive/c/Users/qi11091/Documents/TITAN_files/TITAN/bin/compiler -L TTCN3Ses sionSetup.ttcn - TTCN3SessionSetup.ttcn
Notify: Parsing TTCN-3 module `TTCN3SessionSetup.ttcn'...
Notify: Checking modules...
Notify: Generating code...
Notify: File `TTCN3SessionSetup.hh' was generated.
Notify: File `TTCN3SessionSetup.cc' was generated.
Notify: 2 files were updated.
touch compile
Creating dependency file for TTCN3SessionSetup.cc
g++: Fehler: spawn: No such file or directory
g++ -c -DWIN32 -I/cygdrive/c/Users/qi11091/Documents/TITAN_files/TITAN /include -Wall -o TTCN3SessionSetup.o TTCN3SessionSetup.cc
g++: Fehler: spawn: No such file or directory
Makefile:151: die Regel für Ziel „TTCN3SessionSetup.o“ scheiterte
make: *** [TTCN3SessionSetup.o] Fehler 1
If that's an exact copy of the output you're seeing, then one problem is:
g++ -c -DWIN32 -I/cygdrive/c/Users/qi11091/Documents/TITAN_files/TITAN /include -Wall -o TTCN3SessionSetup.o TTCN3SessionSetup.cc
Note all the spaces between .../TITAN_files/TITAN and /include. That whitespace makes the compiler think these are separate arguments, and it seems like you're trying to add the "file" /include to your compile line, which does not exist of course.
Your makefile doesn't actually set the TTCN3_DIR variable, in this example, so I don't know where that value is coming from but wherever it is, you need to be sure there is no whitespace at the end of the value.
Thanks!, I have updated my makefile now. And the .o are created in the src directory.
here is the makefile and output. The makefile throws the error because all the .o are created in the src folders. I don't know why? I am new to Makefile so kindly please bear with my silly questions.
# This is the Vpath; as my source directory is in the src folder - all the .c files
#folder structure
#Gif_Utility
#-->src/*.c
#-->include/*.h
VPATH = src:include:objects
CFLAGS = -I ./include -g -Wall -DDEBUG
OBJS =./objects
# Look at the CFLAGS here; it has -DDEBUG because in my code, I have #ifdef DEBUG
# Look at the CFLAGS here; -Wall : To generate all the compiler warnings.
# include is required as my compilation depends on the .h files.
# The LD flags to link the shared objects
#LDFLAGS=
#in my mini-project, I am using maths library, Thus, I have lm.
# lc to link my main function with crt1.o
#what is the compiler, am I using.
#This is a good practice since I can modify these flags when cross-compiling.
cc= gcc
#PATH for the LIBS
#This might be useful while cross-compiling.
LIBS= -lm -lc
target: $(patsubst %.c,%.o,$(wildcard ./src/*.c))
#echo "making target"
#mkdir -p ./objects
$(cc) $(patsubst ./src/%.c,./objects/%.o,$(wildcard ./src/*.c)) $(LIBS) -o gif
./objects/%.o: ./src/%.c
#echo "making objects now"
$(cc) $(CFLAGS) $(LDFLAGS) -c $< -o $#
#It is always better to write a PHONY rule for a rules like clean.
#It may happen that in source sandbox, you have a clean file. This may invoke the clean file.
#In order to prevent invoking a clean file during make clean; We give this general rule as PHONY
#PHONY tells the MAKEFILE that there is a rule clean, not a file called clean.
#Generally use PHONY for all, install, clean, distclean,
.PHONY: clean
clean:
#echo "cleaning everything"
#rm -f *.o
#rm -f gif
#echo "clearning .o from src"
#rm -f ./src/*.o
#rm -f ./objects/*.o
$make target
cc -I ./include -g -Wall -DDEBUG -c -o src/sysm.o src/sysm.c
cc -I ./include -g -Wall -DDEBUG -c -o src/x86_main.o src/x86_main.c
src/x86_main.c:11:9: warning: second argument of ‘main’ should be ‘char **’ [-Wmain]
src/x86_main.c: In function ‘main’:
src/x86_main.c:16:9: warning: implicit declaration of function ‘display_init’ [-Wimplicit-function-declaration]
src/x86_main.c:19:9: warning: implicit declaration of function ‘Gif_Read’ [-Wimplicit-function-declaration]
making target
gcc ./objects/gif_display.o ./objects/gif_lzw.o ./objects/gif_read.o ./objects/sysm.o ./objects/x86_main.o -lm -lc -o gif
gcc: error: ./objects/gif_display.o: No such file or directory
gcc: error: ./objects/gif_lzw.o: No such file or directory
gcc: error: ./objects/gif_read.o: No such file or directory
gcc: error: ./objects/sysm.o: No such file or directory
gcc: error: ./objects/x86_main.o: No such file or directory
make: *** [target] Error
You need to fix your patsubst to change the directory part of the filenames as well as the suffixes:
$(patsubst ./src/%.c,./objects/%.o,$(wildcard ./src/*.c))
You have other issues in your makefile too, e.g. this target has the wrong prerequisite:
./objects/%.o: %.c
The source file should be something like ./src/%.c
And the rule for that target is wrong, it outputs to ./objects/$# which would expand to something like ./objects/./objects/x86_main.o
I'm working on a makefile that uses c source files and header files.
I would like to check if all those files exist before compiling, so that if one is missing, printing a customized message instead of the usual 'no rule to make target'.
The code is as follows:
PROG1=file1
PROG2=file2
INCLUDE=header
all: $(PROG1).x $(PROG2).x
%.x : %.c $(INCLUDE).c
$(CC) -o $/$# $^
# echo File $# has been successfully created from $^;
Where and how should I check that file1.c, file2.c and header.h exist to print a customized error message if any of them is missing?
PROG1=file1
PROG2=file2
INCLUDE=header
all: $(PROG1).x $(PROG2).x
%.x : %.c $(INCLUDE).c
$(CC) -o $/$# $^
#echo File $# has been successfully created from $^
%.c :
#echo Missing $#
%.h :
#echo Missing $#
Would that work? If those files don't exist you'd get something like the following output:
posey#DEATHSTAR:~$ make all
Missing file1.c
Missing header.c
cc -o file1.x file1.c header.c
cc: error: file1.c: No such file or directory
cc: error: header.c: No such file or directory
cc: fatal error: no input files
compilation terminated.
make: *** [file1.x] Error 4
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.
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
output
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
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)
error
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$
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
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.
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$
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$
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$
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$
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.
export 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 will invoke this wrapper to run each line of yoru recipes. This is a little ugly, but it did work for me on OSX.
Outside
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 "$#"
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.
Your problem is not that make failed to find avr-gcc. Your problem is in this line:
$(CC) $(CFLAGS) -mmcu=$(MCU) -c $(input) -o $(output)
Since $(input) and $(output) have not been defined your avr-gcc command-line is incomplete. Try changing that line to this instead:
$(CC) $(CFLAGS) -mmcu=$(MCU) -c $< -o $#
$< and $# are automatic variables defined to mean "the first prerequisite" and "the output target", respectively.
The problem is that make is failing to find avr-gcc, and it's due to the \ in your PATH= line.
$ mkdir /tmp/foo\ bar
$ cd /tmp/foo\ bar
$ (echo "#! /bin/sh"; echo "echo this got run") > execable
$ chmod +x execable
$ mkdir /tmp/tstmake; cd /tmp/tstmake
(now make a Makefile with contents as shown)
$ cat Makefile
PATH := /tmp/foo\ bar:$(PATH)
all:
#echo path is "$(PATH)"
execable
$ make
path is /tmp/foo\ bar:/Users/torek/bin.i386:/Users/torek/scripts:[snipped lots]
execable
make: execable: Command not found
make: *** [all] Error 127
$ ed Makefile
71
1s/\\//p
PATH := /tmp/foo bar:$(PATH)
w
70
q
$ make
path is /tmp/foo bar:/Users/torek/bin.i386:/Users/torek/scripts:[snipped lots]
execable
this got run
Update: this is not the only problem, at least when I use my MBP to simulate the issue. The remaining two are:
CPATH also needs the backslash removed (this is a general rule about these := settings)
CPATH needs to be explicitly exported, by adding the line
export CPATH
to the Makefile.
(The reason you need the backslash sometimes, but not other times, has to do with how many times the string gets passed expliclty to the shell: once when it's in $(CC) but zero times when it is an environment variable or part of $(PATH).)
Seeing as this page didn't have a proper answer, I'll link to this page that does:
How I could add dir to $PATH in Makefile?
For whatever reason OS X does not export PATH unless you set the SHELL variable too.
So:
SHELL=/bin/bash
export PATH:=/foo/bar:$(PATH)
..would work.
I just recently ran into this issue. As other comments suggest, the version of make shipped with MacOS has some issues. Build (as #MadScientist suggests above) or install GNU make from Homebrew. The installed version of make on my system is 3.81 and exhibits the same problem. The version provided from Homebrew (version 4.3) works as expected.
I presume you're using OSX. Figuring out an elegant solution may take a few iterations.
In the meantime try this kludge, and tell us the result:
CC=`avr-gcc`
If what you want is to update your PATH variable, then do:
export PATH=$(shell echo $${PATH}):<paths to add>
Example I did:
File : ./c/luckme.sh
echo "Hello Lucky Me ! "
Makefile :
export PATH=$(shell echo $${PATH}):c:.
all:
#luckyme.sh
output of make:
~$ make
Hello Lucky Me !