I run macOS Big Sur (v. 11.4) and I am trying to do Fisher analysis by using fishchips (https://github.com/xzackli/fishchips-public.git). In order to do so, I need to use CLASS (https://github.com/lesgourg/class_public.git). Following the instructions here, Class requires using make to allow us to use classy. When I initially run make, I get the error: clang: error: unsupported option '-fopenmp'. After reading here, I changed the OMPFLAG in my makefile from OMPFLAG = -fopenmp to OMPFLAG = -Xpreprocessor -fopenmp and now I get the error:
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
make: *** [class] Error 1.
I am confused about how to solve this. Here is a copy of my current makefile if it helps:
#Some Makefile for CLASS.
#Julien Lesgourgues, 28.11.2011
#Nils Schöneberg, Matteo Lucca, 27.02.2019
MDIR := $(shell pwd)
WRKDIR = $(MDIR)/build
.base:
if ! [ -e $(WRKDIR) ]; then mkdir $(WRKDIR) ; mkdir $(WRKDIR)/lib; fi;
touch build/.base
vpath %.c source:tools:main:test
vpath %.o build
vpath .base build
########################################################
###### LINES TO ADAPT TO YOUR PLATEFORM ################
########################################################
# your C compiler:
CC = gcc
#CC = icc
#CC = pgcc
# your tool for creating static libraries:
AR = ar rv
# Your python interpreter.
# In order to use Python 3, you can manually
# substitute python3 to python in the line below, or you can simply
# add a compilation option on the terminal command line:
# "PYTHON=python3 make all" (Thanks to Marius Millea for python3 compatibility)
PYTHON ?= python
# your optimization flag
OPTFLAG = -O3
#OPTFLAG = -Ofast -ffast-math #-march=native
#OPTFLAG = -fast
# your openmp flag (comment for compiling without openmp)
OMPFLAG = -Xpreprocessor -fopenmp
#OMPFLAG = -mp -mp=nonuma -mp=allcores -g
#OMPFLAG = -openmp
# all other compilation flags
CCFLAG = -g -fPIC
LDFLAG = -g -fPIC
# leave blank to compile without HyRec, or put path to HyRec directory
# (with no slash at the end: e.g. "external/RecfastCLASS")
HYREC = external/HyRec2020
RECFAST = external/RecfastCLASS
HEATING = external/heating
########################################################
###### IN PRINCIPLE THE REST SHOULD BE LEFT UNCHANGED ##
########################################################
# pass current working directory to the code
CCFLAG += -D__CLASSDIR__='"$(MDIR)"'
# where to find include files *.h
INCLUDES = -I../include
HEADERFILES = $(wildcard ./include/*.h)
# automatically add external programs if needed. First, initialize to blank.
EXTERNAL =
vpath %.c $(RECFAST)
#CCFLAG += -DRECFAST
INCLUDES += -I../$(RECFAST)
EXTERNAL += wrap_recfast.o
HEADERFILES += $(wildcard ./$(RECFAST)/*.h)
vpath %.c $(HEATING)
#CCFLAG += -DHEATING
INCLUDES += -I../$(HEATING)
EXTERNAL += injection.o noninjection.o
HEADERFILES += $(wildcard ./$(HEATING)/*.h)
# update flags for including HyRec
ifneq ($(HYREC),)
vpath %.c $(HYREC)
CCFLAG += -DHYREC
#LDFLAGS += -DHYREC
INCLUDES += -I../$(HYREC)
EXTERNAL += hyrectools.o helium.o hydrogen.o history.o wrap_hyrec.o energy_injection.o
HEADERFILES += $(wildcard ./$(HYREC)/*.h)
endif
%.o: %.c .base $(HEADERFILES)
cd $(WRKDIR);$(CC) $(OPTFLAG) $(OMPFLAG) $(CCFLAG) $(INCLUDES) -c ../$< -o $*.o
TOOLS = growTable.o dei_rkck.o sparse.o evolver_rkck.o evolver_ndf15.o arrays.o parser.o quadrature.o hyperspherical.o common.o trigonometric_integrals.o
SOURCE = input.o background.o thermodynamics.o perturbations.o primordial.o fourier.o transfer.o harmonic.o lensing.o distortions.o
INPUT = input.o
PRECISION = precision.o
BACKGROUND = background.o
THERMO = thermodynamics.o
PERTURBATIONS = perturbations.o
TRANSFER = transfer.o
PRIMORDIAL = primordial.o
HARMONIC = harmonic.o
FOURIER = fourier.o
LENSING = lensing.o
DISTORTIONS = distortions.o
OUTPUT = output.o
CLASS = class.o
TEST_LOOPS = test_loops.o
TEST_LOOPS_OMP = test_loops_omp.o
TEST_HARMONIC = test_harmonic.o
TEST_TRANSFER = test_transfer.o
TEST_FOURIER = test_fourier.o
TEST_PERTURBATIONS = test_perturbations.o
TEST_THERMODYNAMICS = test_thermodynamics.o
TEST_BACKGROUND = test_background.o
TEST_HYPERSPHERICAL = test_hyperspherical.o
C_TOOLS = $(addprefix tools/, $(addsuffix .c,$(basename $(TOOLS))))
C_SOURCE = $(addprefix source/, $(addsuffix .c,$(basename $(SOURCE) $(OUTPUT))))
C_TEST = $(addprefix test/, $(addsuffix .c,$(basename $(TEST_DEGENERACY) $(TEST_LOOPS) $(TEST_TRANSFER) $(TEST_FOURIER) $(TEST_PERTURBATIONS) $(TEST_THERMODYNAMICS))))
C_MAIN = $(addprefix main/, $(addsuffix .c,$(basename $(CLASS))))
C_ALL = $(C_MAIN) $(C_TOOLS) $(C_SOURCE)
H_ALL = $(addprefix include/, common.h svnversion.h $(addsuffix .h, $(basename $(notdir $(C_ALL)))))
PRE_ALL = cl_ref.pre clt_permille.pre
INI_ALL = explanatory.ini lcdm.ini
MISC_FILES = Makefile CPU psd_FD_single.dat myselection.dat myevolution.dat README bbn/sBBN.dat external_Pk/* cpp
PYTHON_FILES = python/classy.pyx python/setup.py python/cclassy.pxd python/test_class.py
all: class libclass.a classy
libclass.a: $(TOOLS) $(SOURCE) $(EXTERNAL)
$(AR) $# $(addprefix build/, $(TOOLS) $(SOURCE) $(EXTERNAL))
class: $(TOOLS) $(SOURCE) $(EXTERNAL) $(OUTPUT) $(CLASS)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o class $(addprefix build/,$(notdir $^)) -lm
test_loops: $(TOOLS) $(SOURCE) $(EXTERNAL) $(OUTPUT) $(TEST_LOOPS)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_loops_omp: $(TOOLS) $(SOURCE) $(EXTERNAL) $(OUTPUT) $(TEST_LOOPS_OMP)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_harmonic: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_HARMONIC)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_transfer: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_TRANSFER)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_fourier: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_FOURIER)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_perturbations: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_PERTURBATIONS)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_thermodynamics: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_THERMODYNAMICS)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_background: $(TOOLS) $(SOURCE) $(EXTERNAL) $(TEST_BACKGROUND)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o $# $(addprefix build/,$(notdir $^)) -lm
test_hyperspherical: $(TOOLS) $(TEST_HYPERSPHERICAL)
$(CC) $(OPTFLAG) $(OMPFLAG) $(LDFLAG) -o test_hyperspherical $(addprefix build/,$(notdir $^)) -lm
tar: $(C_ALL) $(C_TEST) $(H_ALL) $(PRE_ALL) $(INI_ALL) $(MISC_FILES) $(HYREC) $(PYTHON_FILES)
tar czvf class.tar.gz $(C_ALL) $(H_ALL) $(PRE_ALL) $(INI_ALL) $(MISC_FILES) $(HYREC) $(PYTHON_FILES)
classy: libclass.a python/classy.pyx python/cclassy.pxd
ifdef OMPFLAG
cp python/setup.py python/autosetup.py
else
grep -v "lgomp" python/setup.py > python/autosetup.py
endif
cd python; export CC=$(CC); $(PYTHON) autosetup.py install || $(PYTHON) autosetup.py install --user
rm python/autosetup.py
clean: .base
rm -rf $(WRKDIR);
rm -f libclass.a
rm -f $(MDIR)/python/classy.c
rm -rf $(MDIR)/python/build
rm -f python/autosetup.py
I believe I found the solution fix. It seems as if deleting OMPFLAG was all that was needed to run.
I am developing an application for STM32 in stm32cubeIDE
I am using the below custom makefile. Now i want to have a release and a debug build, but they both build the debug build.
I´ve tried
RELDIR = bin/release
DEBUGDIR = bin/debug
ifdef DEBUG
BIN=$(DEBUGDIR)
COMPILERFLAGS += -g3 -O0 -D_DEBUG
else
BIN=$(RELDIR)
COMPILERFLAGS += -O3
endif
and
debug : rebuild
BIN=$(DEBUGDIR)
COMPILERFLAGS += -g3 -O0 -D_DEBUG
release : rebuild
BIN=$(RELDIR)
COMPILERFLAGS += -O3
Can someone tell me how to achieve a release and a debug build :)
Full script:
RED = [31m
GREEN = [32m
YELLOW = [33m
BLUE = [34m
NC = [0m
BIN = bin
SRC = src
INC = inc
SOURCE = $(wildcard $(SRC)/*.c)
OBJECT = $(patsubst %,$(BIN)/%, $(notdir $(SOURCE:.c=.o)))
COMPILER=arm-none-eabi-gcc
ARCHITECTURE=cortex-m4
COMPILERFLAGS= -c -mcpu=$(ARCHITECTURE) -mthumb -mfloat-abi=soft -std=gnu11 -Wall -I $(INC)
LINKERFLAGS= -mcpu=$(ARCHITECTURE) -mthumb -mfloat-abi=soft --specs=nano.specs --specs=rdimon.specs -lc -lrdimon --specs=nosys.specs -T stm32_linker_script.ld -Wl,-Map=out.map
COMPILE= $(COMPILER) $(COMPILERFLAGS) -o $# $<
LINK= $(COMPILER) $(LINKERFLAGS) -o $# $^
RELDIR = bin/release
DEBUGDIR = bin/debug
ifdef DEBUG
BIN=$(DEBUGDIR)
COMPILERFLAGS += -g3 -O0 -D_DEBUG
else
BIN=$(RELDIR)
COMPILERFLAGS += -O3
endif
debug : rebuild
#BIN=$(DEBUGDIR)
#COMPILERFLAGS += -g3 -O0 -D_DEBUG
#
release : rebuild
#BIN=$(RELDIR)
#COMPILERFLAGS += -O3
.PHONY: rebuild
rebuild:
$(MAKE) clean
$(MAKE) all
all : out.elf
#echo "$(GREEN)Done!$(NC)"
out.elf : $(OBJECT)
#echo "$(YELLOW)Linking...$(NC)"
$(LINK)
$(BIN)/%.o : $(SRC)/%.c
$(COMPILE)
.PHONY: all clean debug prep release remake
clean:
#echo "$(GREEN)Cleaning...$(NC)"
rm -rf $(BIN)/*.o $(BIN)/*.elf
I ended up creating two makefiles, one for debug and one for release. It is kind of anoying to have duplicated code, but at least it is obvious what is going on in each script. The scripts are then called from the IDE via "make -f Makefile.DEBUG.mk rebuild" and "make -f Makefile.REBUILD.mk rebuild"
#RED = [31m
#GREEN = [32m
#YELLOW = [33m
BLUE = [34m
NC = [0m
BIN = bin/release
SRC = src
INC = inc
MAKE = make -f Makefile.RELEASE.mk
COMPILER=arm-none-eabi-gcc
ARCHITECTURE=cortex-m4
COMPILERFLAGS= -c -mcpu=$(ARCHITECTURE) \
-mthumb -mfloat-abi=soft -std=gnu11 -Wall -O3 -I $(INC)
LINKERFLAGS= -mcpu=$(ARCHITECTURE) \
-mthumb -mfloat-abi=soft \
--specs=nano.specs \
-T stm32_linker_script.ld \
-Wl,-Map=$(BIN)/out.map
COMPILE= $(COMPILER) $(COMPILERFLAGS) -o $# $<
LINK= $(COMPILER) $(LINKERFLAGS) -o $(BIN)/$# $^
SOURCE = $(wildcard $(SRC)/*.c)
OBJECT = $(patsubst %,$(BIN)/%, $(notdir $(SOURCE:.c=.o)))
.PHONY: rebuild
rebuild:
$(MAKE) clean
$(MAKE) all
all : out.elf
#echo "$(BLUE)Done!$(NC)"
out.elf : $(OBJECT)
#echo "$(BLUE)Linking...$(NC)"
$(LINK)
$(BIN)/%.o : $(SRC)/%.c
$(COMPILE)
.PHONY: all clean
clean:
#echo "$(BLUE)Cleaning...$(NC)"
rm -rf $(BIN)/*.o $(BIN)/*.elf $(BIN)/*.map
and
#RED = [31m
#GREEN = [32m
#YELLOW = [33m
BLUE = [34m
NC = [0m
BIN = bin/debug
SRC = src
INC = inc
MAKE = make -f Makefile.DEBUG.mk
COMPILER=arm-none-eabi-gcc
ARCHITECTURE=cortex-m4
COMPILERFLAGS= -c -mcpu=$(ARCHITECTURE) \
-mthumb -mfloat-abi=soft -std=gnu11 -Wall -g -I $(INC)
LINKERFLAGS= -mcpu=$(ARCHITECTURE) \
-mthumb -mfloat-abi=soft \
--specs=nano.specs \
--specs=rdimon.specs -lc -lrdimon \
--specs=nosys.specs \
-T stm32_linker_script.ld \
-Wl,-Map=$(BIN)/out.map
COMPILE= $(COMPILER) $(COMPILERFLAGS) -o $# $<
LINK= $(COMPILER) $(LINKERFLAGS) -o $(BIN)/$# $^
SOURCE = $(wildcard $(SRC)/*.c)
OBJECT = $(patsubst %,$(BIN)/%, $(notdir $(SOURCE:.c=.o)))
.PHONY: rebuild
rebuild:
$(MAKE) clean
$(MAKE) all
all : out.elf
#echo "$(BLUE)Done!$(NC)"
out.elf : $(OBJECT)
#echo "$(BLUE)Linking...$(NC)"
$(LINK)
$(BIN)/%.o : $(SRC)/%.c
$(COMPILE)
.PHONY: all clean
clean :
#echo "$(BLUE)Cleaning...$(NC)"
rm -rf $(BIN)/*.o $(BIN)/*.elf $(BIN)/*.map
I'm fairly new to makefiles and am currently running with the following one that came with the code and that I extended by the options FFLAGS_EXT1, COMP_EXT1, and file1.F90 and file2.F90:
FC = gfortran
FFLAGS = -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../
FFLAGS_EXT1 = -g -fbacktrace -ffpe-trap=zero,invalid,overflow,underflow -fbounds-check -fcheck=all -Wconversion -std=gnu -O3 -fmax-errors=5 -Dno_nans -I ../ # Stricter compiler flags
LDFLAGS =
OBJ_EXT = o
EXE_EXT = x
COMP = $(FC) $(FFLAGS) -c -o $# $<
COMP_EXT1 = $(FC) $(FFLAGS_EXT1) -c -o $# $<
LINK = $(FC) $(LDFLAGS) -o $# $^
MAIN_MODULES = $(a list of file names without extensions)
OUR_MODULES = $(another list of file names without extensions)
# FORTRAN settings
.SUFFIXES: .F90 .$(OBJ_EXT)
# compilation rules
.F90.$(OBJ_EXT):
# $(COMP)
$(COMP_EXT1)
.PHONY: all
all: \
program1.$(EXE_EXT) program2.$(EXE_EXT) ...
program1.$(EXE_EXT): \
$(addsuffix .$(OBJ_EXT),$(MAIN_MODULES)) \
$(addsuffix .$(OBJ_EXT),$(OUR_MODULES)) \
file1.$(OBJ_EXT) \
file2.$(OBJ_EXT)
$(LINK)
...
This enables me to compile either all of the source files with FFLAGS or with the stricter FFLAGS_EXT1 depending on the choice of the compilation rule.
What I'd like to get is: use COMP as default (there are also other programs apart from the defined program1 which I must not break compatibility with) but use COMP_EXT1 or respectively FFLAGS_EXT1 specifically for file1 and file2 (the legacy code throws a lot of warnings I'd like to ignore and only focus on my new stuff - it is a fairly large project in total...).
I am aware of, e.g., this post, but I'm totally unaware of how to implement this in my case.
Any help would be highly appreciated!
EDIT:
Thanks to the hint by #Matt, I figured out the this changed version would do the trick:
FC = gfortran
FFLAGS = -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../
FFLAGS_EXT1 = -g -fbacktrace -ffpe-trap=zero,invalid,overflow,underflow -fbounds-check -fcheck=all -Wconversion -std=gnu -O3 -fmax-errors=5 -Dno_nans -I ../ # Stricter compiler flags
LDFLAGS =
OBJ_EXT = o
EXE_EXT = x
COMP = $(FC) $(FFLAGS) -c -o $# $<
LINK = $(FC) $(LDFLAGS) -o $# $^
MAIN_MODULES = $(a list of file names without extensions)
OUR_MODULES = $(another list of file names without extensions)
# FORTRAN settings
.SUFFIXES: .F90 .$(OBJ_EXT)
# compilation rules
.F90.$(OBJ_EXT):
$(COMP)
file1.$(OBJ_EXT):
$(FC) $(FFLAGS_EXT1) -c file1.F90 -o file1.$(OBJ_EXT)
file2.$(OBJ_EXT):
$(FC) $(FFLAGS_EXT1) -c file2.F90 -o file2.$(OBJ_EXT)
.PHONY: all
all: \
program1.$(EXE_EXT) program2.$(EXE_EXT) ...
program1.$(EXE_EXT): \
$(addsuffix .$(OBJ_EXT),$(MAIN_MODULES)) \
$(addsuffix .$(OBJ_EXT),$(OUR_MODULES)) \
file1.$(OBJ_EXT) \
file2.$(OBJ_EXT)
$(LINK)
...
However, this seems to be quite cumbersome once there are many rules and many files. Simply using something like $(COMP_EXT1) did not work, as it failed with a no input file error.
Is there a way to shorten this construct?
Well, by all means, this is a matter of style. But let's try something:
# prefer simple variables over recursive ones...
FC := gfortran
FFLAGS := -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../
FFLAGS_EXTRA := -fbacktrace -fbounds-check -fcheck=all -Wconversion -std=gnu -O3 -fmax-errors=5
# ...unless we *do* require deferred expansion
COMP = $(FC) $(FFLAGS) $(FFLAGS_$#) -c -o $# $<
LINK = $(FC) $(LDFLAGS) -o $# $^
# this is a matter of choice but one-letter variables could be handy
O := o
X := x
# I assume both file1 and file2 are already mentioned here
MAIN_MODULES := $(a list of file names without extensions)
OUR_MODULES := $(another list of file names without extensions)
# use computed variables for maximum flexibility
FFLAGS_file1.$O := $(FFLAGS_EXTRA)
FFLAGS_file2.$O := $(FFLAGS_EXTRA)
.PHONY: all
all: program1.$X program2.$X ...
program1.$X: $(addsuffix .$O,$(MAIN_MODULES) $(OUR_MODULES))
$(LINK)
program2.$X: ...
$(LINK)
# it is recommended to use pattern rules instead of suffix rules
%.$O: %.F90
$(COMP)
...
Maybe you want to go a different route, namely to use gmtt which is a library for well, quite some things programming in GNUmake. It offers a table data structure which is aimed at build config tasks like yours:
include gmtt-master/gmtt.mk
FC = gfortran
FFLAGS = -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../
LDFLAGS =
OBJ_EXT = o
EXE_EXT = x
COMP = $(FC) $(FFLAGS) -c -o $# $<
LINK = $(FC) $(LDFLAGS) -o $# $^
MAIN_MODULES = $(a list of file names without extensions)
OUR_MODULES = $(another list of file names without extensions)
# FORTRAN settings
.SUFFIXES: .F90 .$(OBJ_EXT)
# Construct a gmtt table. The one caveat is that we must escape the space characters in the
# second column until we select entries from the table.
define COMPILE_FLAGS_TBL
2
file1.$(OBJ_EXT) $(call spc-mask,-fbacktrace -ffpe-trap=zero,invalid,overflow,underflow -fbounds-check -fcheck=all -Wconversion -std=gnu -O3 -fmax-errors=5)
file2.$(OBJ_EXT) $(call spc-mask,-fbacktrace -ffpe-trap=zero,invalid,overflow,underflow -fbounds-check -fcheck=all -Wconversion -std=gnu -O3 -fmax-errors=5)
endef
# Special flags: "select column 2 from COMPILE_FLAGS_TBL where first column is string-equal to the target"
# ...and recover the space characters afterwards:
FFLAGS_SPECIAL = $(call spc-unmask,$(call select,2,$(COMPILE_FLAGS_TBL),$$(call str-eq,$$1,$#)))
# compilation rules
.PHONY: all
all: foo.o bar.o file1.o file2.o
%.F90:
touch $#
%.o: %.F90
#echo flags: $(FFLAGS) $(FFLAGS_SPECIAL)
Output:
$ make
touch foo.F90
flags: -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../
touch bar.F90
flags: -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../
touch file1.F90
flags: -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../ -fbacktrace -ffpe-trap=zero,invalid,overflow,underflow -fbounds-check -fcheck=all -Wconversion -std=gnu -O3 -fmax-errors=5
touch file2.F90
flags: -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../ -fbacktrace -ffpe-trap=zero,invalid,overflow,underflow -fbounds-check -fcheck=all -Wconversion -std=gnu -O3 -fmax-errors=5
rm bar.F90 file1.F90 foo.F90 file2.F90
You can have more flexible file selection by using globs:
include gmtt-master/gmtt-master/gmtt.mk
FFLAGS = -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../
OBJ_EXT = o
# Construct a gmtt table. The one caveat is that we must escape the space characters in the
# second column until we select entries from the table.
define COMPILE_FLAGS_TBL
2
file1.$(OBJ_EXT) $(call spc-mask,-fbacktrace -ffpe-trap=zero,invalid,overflow,underflow -fbounds-check -fcheck=all -Wconversion -std=gnu -O3 -fmax-errors=5)
file2.$(OBJ_EXT) $(call spc-mask,-fbacktrace -ffpe-trap=zero,invalid,overflow,underflow -fbounds-check -fcheck=all -Wconversion -std=gnu -O3 -fmax-errors=5)
endef
define PATTERN_FLAGS_TBL
2
*_frobozz_[7-9].$(OBJ_EXT) $(call spc-mask,-ffrobozz)
X_frabazz_*.$(OBJ_EXT) $(call spc-mask,-ffrabazz -dwhatever)
endef
# Special flags: "select column 2 from COMPILE_FLAGS_TBL where first column is string-equal to the target"
# ...and recover the space characters afterwards:
FFLAGS_SPECIAL = $(call spc-unmask,$(call select,2,$(COMPILE_FLAGS_TBL),$$(call str-eq,$$1,$#)))
# Very special flags: "select column 2 from PATTERN_FLAGS_TBL where target matches glob in first column"
# ...and recover the space characters afterwards
FFLAGS_VERY_SPECIAL = $(call spc-unmask,$(call select,2,$(PATTERN_FLAGS_TBL),$$(call glob-match,$#,$$1)))
# compilation rules
.PHONY: all
all: foo.o bar.o file1.o file2.o A_frobozz_8.o A_frobozz_6.o X_frabazz_mike.o X_frabazz_mandy.o
%.F90:
#touch $#
%.o: %.F90
#echo $# flags: $(FFLAGS) $(FFLAGS_SPECIAL) $(FFLAGS_VERY_SPECIAL)
Output:
$ make
foo.o flags: -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../
bar.o flags: -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../
file1.o flags: -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../ -fbacktrace -ffpe-trap=zero,invalid,overflow,underflow -fbounds-check -fcheck=all -Wconversion -std=gnu -O3 -fmax-errors=5
file2.o flags: -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../ -fbacktrace -ffpe-trap=zero,invalid,overflow,underflow -fbounds-check -fcheck=all -Wconversion -std=gnu -O3 -fmax-errors=5
A_frobozz_8.o flags: -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../ -ffrobozz
A_frobozz_6.o flags: -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../
X_frabazz_mike.o flags: -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../ -ffrabazz -dwhatever
X_frabazz_mandy.o flags: -g -ffpe-trap=zero,invalid,overflow,underflow -Dno_nans -I ../ -ffrabazz -dwhatever
rm X_frabazz_mandy.F90 A_frobozz_8.F90 bar.F90 file1.F90 foo.F90 A_frobozz_6.F90 file2.F90 X_frabazz_mike.F90
I found a bare-metal example for a board different from mine so I will have to modify the loader script but for now I just want to be able to compile and link the example as it is.
I copied the arm-none-eabi cross-compiler to the directory just above c_blinky which is where the source files are.
(I have a diagram of the directory structure on a page on my website)
Here's the makefile:
ifeq ($(GNU_ARM),)
GNU_ARM = ../arm-none-eabi/bin
endif
CC := $(GNU_ARM)/arm-none-eabi-gcc
CPP := $(GNU_ARM)/arm-none-eabi-g++
ASM := $(GNU_ARM)/arm-none-eabi-as
LINK := $(GNU_ARM)/arm-none-eabi-gcc
BIN := $(GNU_ARM)/arm-none-eabi-objcopy
RM := rm -rf
MKDIR := mkdir
BLDDIR = .
CCINC = -I$(BLDDIR)
APP_DEP = $(BLDDIR)/bsp.h \
$(BLDDIR)/arm_exc.h \
$(BLDDIR)/isr.h
APP_NAME = blinky
ARM_CORE = arm7tdmi
ifeq (rel, $(CONF)) # Release configuration
BINDIR = rel
CCFLAGS = -c -mcpu=$(ARM_CORE) -mthumb-interwork -Os \
-mlong-calls -ffunction-sections -Wall -DNDBEBUG -o$#
ASMFLAGS = -mcpu=$(ARM_CORE) -mthumb-interwork -o$#
LINKFLAGS = -T .\$(APP_NAME).ld -o $(BINDIR)\$(APP_NAME).elf \
-Wl,-Map,$(BINDIR)\$(APP_NAME).map,--cref,--gc-sections
else # default Debug configuration
BINDIR = dbg
CCFLAGS = -g -c -mcpu=$(ARM_CORE) -mthumb-interwork -O \
-mlong-calls -ffunction-sections -Wall -o$#
ASMFLAGS = -g -mcpu=$(ARM_CORE) -mthumb-interwork -o$#
LINKFLAGS = -T .\$(APP_NAME).ld -o $(BINDIR)\$(APP_NAME).elf \
-Wl,-Map,$(BINDIR)\$(APP_NAME).map,--cref,--gc-sections
endif
all: $(BINDIR)/$(APP_NAME).bin
$(BINDIR)/$(APP_NAME).bin : $(BINDIR)/$(APP_NAME).elf
$(BIN) -O binary $(BINDIR)/$(APP_NAME).elf $(BINDIR)/$(APP_NAME).bin
$(BINDIR)/$(APP_NAME).elf : \
./$(APP_NAME).ld \
$(BINDIR)/startup.o \
$(BINDIR)/arm_exc.o \
$(BINDIR)/low_level_init.o \
$(BINDIR)/isr.o \
$(BINDIR)/bsp.o \
$(BINDIR)/blinky.o
$(LINK) \
$(BINDIR)/startup.o \
$(BINDIR)/arm_exc.o \
$(BINDIR)/low_level_init.o \
$(BINDIR)/isr.o \
$(BINDIR)/bsp.o \
$(BINDIR)/blinky.o \
$(LINKFLAGS)
$(BINDIR)/startup.o: $(BLDDIR)/startup.s
$(ASM) $(ASMFLAGS) $<
$(BINDIR)/arm_exc.o: $(BLDDIR)/arm_exc.s
$(ASM) $(ASMFLAGS) $<
# choose the ARM or THUMB compilation for each module...
$(BINDIR)/low_level_init.o: $(BLDDIR)/low_level_init.c $(APP_DEP)
$(CC) -marm $(CCFLAGS) $(CCINC) $<
$(BINDIR)/isr.o: $(BLDDIR)/isr.c $(APP_DEP)
$(CC) -marm $(CCFLAGS) $(CCINC) $<
$(BINDIR)/bsp.o: $(BLDDIR)/bsp.c $(APP_DEP)
$(CC) -mthumb $(CCFLAGS) $(CCINC) $<
$(BINDIR)/blinky.o: $(BLDDIR)/blinky.c $(APP_DEP)
$(CC) -mthumb $(CCFLAGS) $(CCINC) $<
I set GNU_ARM in the makefile to ../arm-none-eabi/bin and ran make and got the following error:
(the file blinky.ld does exist in the source directory)
../arm-none-eabi/bin/arm-none-eabi-gcc \
dbg/startup.o \
dbg/arm_exc.o \
dbg/low_level_init.o \
dbg/isr.o \
dbg/bsp.o \
dbg/blinky.o \
-T .\blinky.ld -o dbg\blinky.elf -Wl,-Map,dbg\blinky.map,--cref,--gc-sections
/home/dan/dev/compile/bare-metal/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: cannot open linker script file .blinky.ld: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [dbg/blinky.elf] Error 1
I thought the LINK assignment at the beginning should be:
LINK := $(GNU_ARM)/arm-none-eabi-ld
and not
LINK := $(GNU_ARM)/arm-none-eabi-gcc
and I got:
../arm-none-eabi/bin/arm-none-eabi-ld \
dbg/startup.o \
dbg/arm_exc.o \
dbg/low_level_init.o \
dbg/isr.o \
dbg/bsp.o \
dbg/blinky.o \
-T .\blinky.ld -o dbg\blinky.elf -Wl,-Map,dbg\blinky.map,--cref,--gc-sections
../arm-none-eabi/bin/arm-none-eabi-ld: cannot open linker script file .blinky.ld: No such file or directory
make: *** [dbg/blinky.elf] Error 1
It looks like arm-none-eabi-gcc is calling collect2 in lib/gcc/arm-none-eabi/4.9.3 which in turn calls ld which is not in the main bin directory:
/home/dan/dev/compile/bare-metal/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld:
I tried making a symbolic link to arm-none-eabi-ld as ld and got the same error.
I have the following Makefile. Whenever I run make, I get the following error.
ifort: error #10236: File not found: 'mkl_matrix_multiply.o'
I have been trying to figure this out for a while now with no luck.
C = icc
FC = ifort
LD = ifort
OPT = -Ofast -vec_report6 -simd -xhost -debug -traceback -ftrapuv
OP = -Ofast -vec_report6 -simd -xhost
LINK = -L$(MKLROOT)/lib/intel64 $(MKLROOT)/lib/intel64/libmkl_blas95_ilp64.a -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -lpthread -lm
INCLUDE = -openmp -i8 -I$(MKLROOT)/include/intel64/ilp64 -I$(MKLROOT)/include
mkl_matrix_multiply.exe: mkl_matrix_multiply.o timing.o
$(LD) -o mkl_matrix_multiply.exe mkl_matrix_multiply.o timing.o
mkl_matrix_multiply.o: mkl_matrix_multiply.f90
$(FC) $(INCLUDE) $(LINK) mkl_matrix_multiply.f90
timing.o: timing.c
$(CC) $(OP) -c timing.c
dummy.o: dummy.c
$(CC) $(OP) -c dummy.c
clean:
rm -f *.o matrix_multiply.exe
Any help would be greatly appreciated.
Seems like you are missing -c in mkl_matrix_multiply.o rule.
Modify your makefile as
C = icc
FC = ifort
LD = ifort
OPT = -Ofast -vec_report6 -simd -xhost -debug -traceback -ftrapuv
OP = -Ofast -vec_report6 -simd -xhost
LINK = -L$(MKLROOT)/lib/intel64 $(MKLROOT)/lib/intel64/libmkl_blas95_ilp64.a -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -lpthread -lm
INCLUDE = -openmp -i8 -I$(MKLROOT)/include/intel64/ilp64 -I$(MKLROOT)/include
mkl_matrix_multiply.exe: mkl_matrix_multiply.o timing.o
$(LD) -o mkl_matrix_multiply.exe mkl_matrix_multiply.o timing.o
mkl_matrix_multiply.o: mkl_matrix_multiply.f90
$(FC) -c $(INCLUDE) $(LINK) mkl_matrix_multiply.f90
timing.o: timing.c
$(CC) $(OP) -c timing.c
dummy.o: dummy.c
$(CC) $(OP) -c dummy.c
clean:
rm -f *.o matrix_multiply.exe