Freetz makefile: unrecognized command-line option ‘-m32’ - linux

I'm trying to build a Freetz firmware for my Fritzbox. I'm trying to do this on Ubuntu running in Parallels on my M1 MBP.
After eliminating all other issues (mainly dependencies), I end up with the following error:
cc: error: unrecognized command-line option ‘-m32’
The full dialog is:
parallels#ubuntu-linux-22-04-desktop:~/Downloads/freetz-ng$ make
Freetz-NG 20037-37d64c4f7 trunk 2022-07-08
cmd() { make -j3 "$#" || { [ "2" = "0" ] && echo && cat .build.log 2>/dev/null; kill $$ 2>/dev/null || kill $$$$ 2>/dev/null; printf "\n\\033[33m%s\\033[m\n" "ERROR: Build failed."; exit 1; } }; mkdir -p source; [ -n "" ] && step="/" || step=""; [ -n "" ] && step="$step/"; case "" in BIN) echo -n "package/" >source/.echo_item_tmp ;; LIB) echo -n "library/" >source/.echo_item_tmp ;; HTL) echo -n "tools/" >source/.echo_item_tmp ;; KTC) echo -n "toolchain/kernel$step" >source/.echo_item_tmp ;; TTC) echo -n "toolchain/target$step" >source/.echo_item_tmp ;; KRN) echo -n "kernel" >source/.echo_item_tmp ;; esac; if ! diff -q source/.echo_item_tmp source/.echo_item_new >/dev/null 2>&1 || [ ! -e source/.echo_item_1st ]; then if [ -e source/.echo_item_end -a -e source/.echo_item_new -a -e source/.echo_item_1st ]; then echo -e "\e[48;5;26mdone\e[49m."; rm -f source/.echo_item_end source/.echo_item_1st; fi; [ -s source/.echo_item_tmp ] && cat source/.echo_item_tmp > source/.echo_item_new 2>/dev/null; [ -s source/.echo_item_new ] || cat source/.echo_item_old > source/.echo_item_new 2>/dev/null; if [ -s "source/.echo_item_new" ]; then echo -ne "\e[48;5;90m---> "; cat source/.echo_item_new 2>/dev/null | tee source/.echo_item_old; echo -ne "\e[49m ... "; [ "2" != "0" ] && echo; touch source/.echo_item_end; touch source/.echo_item_1st; fi; fi; echo -ne "\e[48;5;56mbuilding\e[49m ... "; cmd -C /home/parallels/Downloads/freetz-ng/source/host-tools/pseudo-0cda3ba5f94aed8d50652a99ee9c502975aa2926/arch install-lib
---> tools/pseudo-host ...
building ... cc -fno-strict-aliasing -pipe -std=gnu99 -Wall -W -Wextra -Wno-deprecated-declarations -fPIC -D_LARGEFILE64_SOURCE -D_ATFILE_SOURCE -Wno-cast-function-type -Wno-nonnull-compare -fcommon -m32 -DPSEUDO_PREFIX='"/home/parallels/Downloads/freetz-ng/tools/build"' -DPSEUDO_SUFFIX='""' -DPSEUDO_BINDIR='"bin"' -DPSEUDO_LIBDIR='"lib"' -DPSEUDO_LOCALSTATEDIR='"var/pseudo"' -DPSEUDO_VERSION='"1.9.0"' -DUSE_MEMORY_DB -DPSEUDO_PASSWD_FALLBACK='""' -O2 -g -D_GNU_SOURCE -c -o pseudo_wrappers.o pseudo_wrappers.c
cc -c -pipe -std=gnu99 -Wall -W -Wextra -Wno-deprecated-declarations -fPIC -D_LARGEFILE64_SOURCE -D_ATFILE_SOURCE -Wno-cast-function-type -Wno-nonnull-compare -fcommon -m32 -DPSEUDO_PREFIX='"/home/parallels/Downloads/freetz-ng/tools/build"' -DPSEUDO_SUFFIX='""' -DPSEUDO_BINDIR='"bin"' -DPSEUDO_LIBDIR='"lib"' -DPSEUDO_LOCALSTATEDIR='"var/pseudo"' -DPSEUDO_VERSION='"1.9.0"' -DUSE_MEMORY_DB -DPSEUDO_PASSWD_FALLBACK='""' -O2 -g pseudo_client.c
cc -c -pipe -std=gnu99 -Wall -W -Wextra -Wno-deprecated-declarations -fPIC -D_LARGEFILE64_SOURCE -D_ATFILE_SOURCE -Wno-cast-function-type -Wno-nonnull-compare -fcommon -m32 -DPSEUDO_PREFIX='"/home/parallels/Downloads/freetz-ng/tools/build"' -DPSEUDO_SUFFIX='""' -DPSEUDO_BINDIR='"bin"' -DPSEUDO_LIBDIR='"lib"' -DPSEUDO_LOCALSTATEDIR='"var/pseudo"' -DPSEUDO_VERSION='"1.9.0"' -DUSE_MEMORY_DB -DPSEUDO_PASSWD_FALLBACK='""' -O2 -g pseudo_ipc.c
cc: error: unrecognized command-line option ‘-m32’
make[2]: *** [Makefile:158: pseudo_wrappers.o] Error 1
make[2]: *** Waiting for unfinished jobs....
cc: error: unrecognized command-line option ‘-m32’
make[2]: *** [Makefile:131: pseudo_client.o] Error 1
cc: error: unrecognized command-line option ‘-m32’
make[2]: *** [Makefile:131: pseudo_ipc.o] Error 1
make[1]: *** [tools/make/pseudo-host/pseudo-host.mk:57: /home/parallels/Downloads/freetz-ng/tools/build/lib/libpseudo.so] Terminated
make: *** [Makefile:46: envira] Terminated
Any ideas?
I tried
make MACHINE=arm
as I read in another discussion that I might be an architecture issue. But it doesn't seem to be.

Related

I am getting a strange error when running MPICH 4.0.3

I am getting an error when running mpirun:
will#will-MS-7D91:~/WRFHYDRO/Tests/Compatibility$ mpirun ./a.out |& tee comp_test2.txt
C function called by Fortran
Values are xx = 2.00 and ii = 1
Abort(2139535) on node 0 (rank 0 in comm 0): Fatal error in PMPI_Init: Other MPI error, error stack:
MPIR_Init_thread(176)........:
MPID_Init(1538)..............:
MPIDI_OFI_mpi_init_hook(1511):
open_fabric(2565)............:
find_provider(2683)..........: OFI fi_getinfo() failed (ofi_init.c:2683:find_provider:No data available)
I have tested the commands on another computer and it works fine. The commands are this:
echo "Test 2"
mpifort -c 02_fortran+c+netcdf+mpi_f.f
mpicc -c 02_fortran+c+netcdf+mpi_c.c
mpifort 02_fortran+c+netcdf+mpi_f.o \
02_fortran+c+netcdf+mpi_c.o \
-L${NETCDF}/lib -lnetcdff -lnetcdf
mpirun ./a.out |& tee comp_test2.txt
I recently built a new pc, with an MSI Z790 Tomahawk board, Intel-13900K cpu, and 64GB of DDR5 5600mhz RAM. Could this be this issue were one of those things are not compatibile with mpich? Mpich version is 4.0.3.
sudo apt -y update
sudo apt -y upgrade
sudo apt -y install gcc gfortran g++ libtool automake autoconf make m4 default-jre default-jdk csh ksh git python3 python3-dev python2 python2-dev mlocate curl cmake libcurl4-openssl-dev
echo " "
##############################Directory Listing############################
export HOME=`cd;pwd`
mkdir $HOME/WRF
export WRF_FOLDER=$HOME/WRF
cd $WRF_FOLDER/
mkdir Downloads
mkdir WRFPLUS
mkdir WRFDA
mkdir Libs
export DIR=$WRF_FOLDER/Libs
mkdir Libs/grib2
mkdir Libs/NETCDF
mkdir Libs/MPICH
mkdir -p Tests/Environment
mkdir -p Tests/Compatibility
echo " "
#############################Core Management####################################
export CPU_CORE=$(nproc) # number of available threads on system
export CPU_6CORE="6"
export CPU_HALF=$(($CPU_CORE / 2)) #half of availble cores on system
export CPU_HALF_EVEN=$(( $CPU_HALF - ($CPU_HALF % 2) )) #Forces CPU cores to even number to avoid partial core export. ie 7 cores would be 3.5 cores.
if [ $CPU_CORE -le $CPU_6CORE ] #If statement for low core systems. Forces computers to only use 1 core if there are 4 cores or less on the system.
then
export CPU_HALF_EVEN="2"
else
export CPU_HALF_EVEN=$(( $CPU_HALF - ($CPU_HALF % 2) ))
fi
echo "##########################################"
echo "Number of Threads being used $CPU_HALF_EVEN"
echo "##########################################"
echo " "
##############################Downloading Libraries############################
#Force use of ipv4 with -4
cd Downloads
wget -c -4 https://github.com/madler/zlib/archive/refs/tags/v1.2.13.tar.gz
wget -c -4 https://github.com/HDFGroup/hdf5/archive/refs/tags/hdf5-1_13_2.tar.gz
wget -c -4 https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.9.0.tar.gz
wget -c -4 https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.6.0.tar.gz
wget -c -4 https://github.com/pmodels/mpich/releases/download/v4.0.3/mpich-4.0.3.tar.gz
wget -c -4 https://download.sourceforge.net/libpng/libpng-1.6.39.tar.gz
wget -c -4 https://www.ece.uvic.ca/~frodo/jasper/software/jasper-1.900.1.zip
wget -c -4 https://sourceforge.net/projects/opengrads/files/grads2/2.2.1.oga.1/Linux%20%2864%20Bits%29/opengrads-2.2.1.oga.1-bundle-x86_64-pc-linux-gnu-glibc_2.17.tar.gz
echo " "
####################################Compilers#####################################
export CC=gcc
export CXX=g++
export FC=gfortran
export F77=gfortran
export CFLAGS="-fPIC -fPIE -O3"
#IF statement for GNU compiler issue
export GCC_VERSION=$(/usr/bin/gcc -dumpfullversion | awk '{print$1}')
export GFORTRAN_VERSION=$(/usr/bin/gfortran -dumpfullversion | awk '{print$1}')
export GPLUSPLUS_VERSION=$(/usr/bin/g++ -dumpfullversion | awk '{print$1}')
export GCC_VERSION_MAJOR_VERSION=$(echo $GCC_VERSION | awk -F. '{print $1}')
export GFORTRAN_VERSION_MAJOR_VERSION=$(echo $GFORTRAN_VERSION | awk -F. '{print $1}')
export GPLUSPLUS_VERSION_MAJOR_VERSION=$(echo $GPLUSPLUS_VERSION | awk -F. '{print $1}')
export version_10="10"
if [ $GCC_VERSION_MAJOR_VERSION -ge $version_10 ] || [ $GFORTRAN_VERSION_MAJOR_VERSION -ge $version_10 ] || [ $GPLUSPLUS_VERSION_MAJOR_VERSION -ge $version_10 ]
then
export fallow_argument=-fallow-argument-mismatch
export boz_argument=-fallow-invalid-boz
else
export fallow_argument=
export boz_argument=
fi
export FFLAGS=$fallow_argument
export FCFLAGS=$fallow_argument
echo "##########################################"
echo "FFLAGS = $FFLAGS"
echo "FCFLAGS = $FCFLAGS"
echo "##########################################"
echo " "
#############################zlib############################
#Uncalling compilers due to comfigure issue with zlib1.2.13
#With CC & CXX definied ./configure uses different compiler Flags
cd $WRF_FOLDER/Downloads
tar -xvzf v1.2.13.tar.gz
cd zlib-1.2.13/
./configure --prefix=$DIR/grib2
make -j $CPU_HALF_EVEN
make -j $CPU_HALF_EVEN install |& tee make.install.log
#make check
echo " "
##############################MPICH############################
#F90= due to compiler issues with mpich install
cd $WRF_FOLDER/Downloads
tar -xvzf mpich-4.0.3.tar.gz
cd mpich-4.0.3/
F90= ./configure --prefix=$DIR/MPICH --with-device=ch3 FFLAGS=$fallow_argument FCFLAGS=$fallow_argument
make -j $CPU_HALF_EVEN
make -j $CPU_HALF_EVEN install |& tee make.install.log
# make check
export PATH=$DIR/MPICH/bin:$PATH
export MPIFC=$DIR/MPICH/bin/mpifort
export MPIF77=$DIR/MPICH/bin/mpifort
export MPIF90=$DIR/MPICH/bin/mpifort
export MPICC=$DIR/MPICH/bin/mpicc
export MPICXX=$DIR/MPICH/bin/mpicxx
echo " "
#############################libpng############################
cd $WRF_FOLDER/Downloads
export LDFLAGS=-L$DIR/grib2/lib
export CPPFLAGS=-I$DIR/grib2/include
tar -xvzf libpng-1.6.39.tar.gz
cd libpng-1.6.39/
CC=$MPICC FC=$MPIFC F77=$MPIF77 F90=$MPIF90 CXX=$MPICXX ./configure --prefix=$DIR/grib2
make -j $CPU_HALF_EVEN
make -j $CPU_HALF_EVEN install |& tee make.install.log
#make check
echo " "
#############################JasPer############################
cd $WRF_FOLDER/Downloads
unzip jasper-1.900.1.zip
cd jasper-1.900.1/
./configure --prefix=$DIR/grib2
CC=$MPICC FC=$MPIFC F77=$MPIF77 F90=$MPIF90 CXX=$MPICXX ./configure --prefix=$DIR/grib2
make -j $CPU_HALF_EVEN
make -j $CPU_HALF_EVEN install |& tee make.install.log
#make check
export JASPERLIB=$DIR/grib2/lib
export JASPERINC=$DIR/grib2/include
echo " "
#############################hdf5 library for netcdf4 functionality############################
cd $WRF_FOLDER/Downloads
tar -xvzf hdf5-1_13_2.tar.gz
cd hdf5-hdf5-1_13_2
CC=$MPICC FC=$MPIFC F77=$MPIF77 F90=$MPIF90 CXX=$MPICXX ./configure --prefix=$DIR/grib2 --with-zlib=$DIR/grib2 --enable-hl --enable-fortran
make -j $CPU_HALF_EVEN
make -j $CPU_HALF_EVEN install |& tee make.install.log
#make check
export HDF5=$DIR/grib2
export LD_LIBRARY_PATH=$DIR/grib2/lib:$LD_LIBRARY_PATH
echo " "
##############################Install NETCDF C Library############################
cd $WRF_FOLDER/Downloads
tar -xzvf v4.9.0.tar.gz
cd netcdf-c-4.9.0/
export CPPFLAGS=-I$DIR/grib2/include
export LDFLAGS=-L$DIR/grib2/lib
export LIBS="-lhdf5_hl -lhdf5 -lz -lcurl -lgfortran -lgcc -lm -ldl"
CC=$MPICC FC=$MPIFC CXX=$MPICXX F90=$MPIF90 F77=$MPIF77 ./configure --prefix=$DIR/NETCDF --disable-dap --enable-netcdf-4 --enable-netcdf4 --enable-shared
make -j $CPU_HALF_EVEN
make -j $CPU_HALF_EVEN install |& tee make.install.log
#make check
export PATH=$DIR/NETCDF/bin:$PATH
export NETCDF=$DIR/NETCDF
echo " "
##############################NetCDF fortran library############################
cd $WRF_FOLDER/Downloads
tar -xvzf v4.6.0.tar.gz
cd netcdf-fortran-4.6.0/
export LD_LIBRARY_PATH=$DIR/NETCDF/lib:$LD_LIBRARY_PATH
export CPPFLAGS="-I$DIR/NETCDF/include -I$DIR/grib2/include"
export LDFLAGS="-L$DIR/NETCDF/lib -L$DIR/grib2/lib"
export LIBS="-lnetcdf -lhdf5_hl -lhdf5 -lz -ldl"
CC=$MPICC FC=$MPIFC CXX=$MPICXX F90=$MPIF90 F77=$MPIF77 ./configure --prefix=$DIR/NETCDF --enable-netcdf-4 --enable-netcdf4 --enable-shared
make -j $CPU_HALF_EVEN
make -j $CPU_HALF_EVEN install |& tee make.install.log
#make check
echo " "
#################################### System Environment Tests ##############
cd $WRF_FOLDER/Downloads
wget -c -4 https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/Fortran_C_NETCDF_MPI_tests.tar
wget -c -4 https://www2.mmm.ucar.edu/wrf/OnLineTutorial/compile_tutorial/tar_files/Fortran_C_tests.tar
tar -xvf Fortran_C_tests.tar -C $WRF_FOLDER/Tests/Environment
tar -xvf Fortran_C_NETCDF_MPI_tests.tar -C $WRF_FOLDER/Tests/Compatibility
export one="1"
echo " "
############## Testing Environment #####
cd $WRF_FOLDER/Tests/Environment
echo " "
echo " "
echo "Environment Testing "
echo "Test 1"
gfortran TEST_1_fortran_only_fixed.f
./a.out |& tee env_test1.txt
export TEST_PASS=$(grep -w -o -c "SUCCESS" env_test1.txt | awk '{print$1}')
if [ $TEST_PASS -ge 1 ]
then
echo "Enviroment Test 1 Passed"
else
echo "Environment Compiler Test 1 Failed"
exit
fi
read -t 3 -p "I am going to wait for 3 seconds only ..."
echo " "
echo "Test 2"
gfortran TEST_2_fortran_only_free.f90
./a.out |& tee env_test2.txt
export TEST_PASS=$(grep -w -o -c "SUCCESS" env_test2.txt | awk '{print$1}')
if [ $TEST_PASS -ge 1 ]
then
echo "Enviroment Test 2 Passed"
else
echo "Environment Compiler Test 2 Failed"
exit
fi
echo " "
read -t 3 -p "I am going to wait for 3 seconds only ..."
echo " "
echo "Test 3"
gcc TEST_3_c_only.c
./a.out |& tee env_test3.txt
export TEST_PASS=$(grep -w -o -c "SUCCESS" env_test3.txt | awk '{print$1}')
if [ $TEST_PASS -ge 1 ]
then
echo "Enviroment Test 3 Passed"
else
echo "Environment Compiler Test 3 Failed"
exit
fi
echo " "
read -t 3 -p "I am going to wait for 3 seconds only ..."
echo " "
echo "Test 4"
gcc -c -m64 TEST_4_fortran+c_c.c
gfortran -c -m64 TEST_4_fortran+c_f.f90
gfortran -m64 TEST_4_fortran+c_f.o TEST_4_fortran+c_c.o
./a.out |& tee env_test4.txt
export TEST_PASS=$(grep -w -o -c "SUCCESS" env_test4.txt | awk '{print$1}')
if [ $TEST_PASS -ge 1 ]
then
echo "Enviroment Test 4 Passed"
else
echo "Environment Compiler Test 4 Failed"
exit
fi
echo " "
read -t 3 -p "I am going to wait for 3 seconds only ..."
echo " "
############## Testing Environment #####
cd $WRF_FOLDER/Tests/Compatibility
cp ${NETCDF}/include/netcdf.inc .
echo " "
echo " "
echo "Library Compatibility Tests "
echo "Test 1"
gfortran -c 01_fortran+c+netcdf_f.f
gcc -c 01_fortran+c+netcdf_c.c
gfortran 01_fortran+c+netcdf_f.o 01_fortran+c+netcdf_c.o \
-L${NETCDF}/lib -lnetcdff -lnetcdf
./a.out |& tee comp_test1.txt
export TEST_PASS=$(grep -w -o -c "SUCCESS" comp_test1.txt | awk '{print$1}')
if [ $TEST_PASS -ge 1 ]
then
echo "Compatibility Test 1 Passed"
else
echo "Compatibility Compiler Test 1 Failed"
exit
fi
echo " "
read -t 3 -p "I am going to wait for 3 seconds only ..."
echo " "
echo "Test 2"
mpifort -c 02_fortran+c+netcdf+mpi_f.f
mpicc -c 02_fortran+c+netcdf+mpi_c.c
mpifort 02_fortran+c+netcdf+mpi_f.o \
02_fortran+c+netcdf+mpi_c.o \
-L${NETCDF}/lib -lnetcdff -lnetcdf
mpirun ./a.out |& tee comp_test2.txt
So this issue was having the intel mpi program in the $PATH and $LD_LIBRARY_PATH
Once I removed the intel mpi program from the both of those places in .bashrc it fixed the issue.

LFS Fails on step 6.18 with x86_64-lfs-linux-gnu-gcc -dumpspecs > tmp-specs

I'm on 6.18 of LFS.
https://linuxfromscratch.org/lfs/view/stable-systemd/chapter06/gcc-pass2.html
But I keep getting the error below.
g++ -fno-PIE -c -g -O2 -DIN_GCC -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -I. -I. -I../.././gcc -I../.././gcc/. -I../.././gcc/../include -I../.././gcc/../libcpp/include -I../.././gcc/../libcody -I/mnt/lfs/sources/gcc-12.2.0/host-x86_64-lfs-linux-gnu/gmp -I/mnt/lfs/sources/gcc-12.2.0/gmp -I/mnt/lfs/sources/gcc-12.2.0/host-x86_64-lfs-linux-gnu/mpfr/src -I/mnt/lfs/sources/gcc-12.2.0/mpfr/src -I/mnt/lfs/sources/gcc-12.2.0/mpc/src -I../.././gcc/../libdecnumber -I../.././gcc/../libdecnumber/dpd -I../libdecnumber -I../.././gcc/../libbacktrace -o insn-recog.o -MT insn-recog.o -MMD -MP -MF ./.deps/insn-recog.TPo insn-recog.cc
x86_64-lfs-linux-gnu-gcc -dumpspecs > tmp-specs
/bin/sh: line 1: x86_64-lfs-linux-gnu-gcc: command not found
make[2]: *** [Makefile:2185: specs] Error 127
make[2]: *** Waiting for unfinished jobs....
rm gcc.pod
make[2]: Leaving directory '/mnt/lfs/sources/gcc-12.2.0/host-x86_64-lfs-linux-gnu/gcc'
make[1]: *** [Makefile:4621: all-gcc] Error 2
make[1]: Leaving directory '/mnt/lfs/sources/gcc-12.2.0'
make: *** [Makefile:1036: all] Error 2
Im using this function to build:
function gcc2() {
export BUILD_DIR=/mnt/lfs/sources ## This si usualy at top of file but added it for this examples sake.
#https://linuxfromscratch.org/lfs/view/stable-systemd/chapter06/gzip.html
cd $BUILD_DIR && tar -vxkf gcc-12.2.0.tar.xz && cd gcc-12.2.0
$BUILD_DIR/gcc-12.2.0/contrib/download_prerequisites
rm -rf $BUILD_DIR/gcc-12.2.0/isl*
case $(uname -m) in
x86_64)
sed -e '/m64=/s/lib64/lib/' -i.orig $BUILD_DIR/gcc-12.2.0/gcc/config/i386/t-linux64
;;
esac
sed '/thread_header =/s/#.*#/gthr-posix.h/' -i $BUILD_DIR/gcc-12.2.0/libgcc/Makefile.in libstdc++-v3/include/Makefile.in
if ! [[ -d "$BUILD_DIR/gcc-12.2.0/build" ]]; then
mkdir $BUILD_DIR/gcc-12.2.0/build && cd $BUILD_DIR/gcc-12.2.0/build
fi
$BUILD_DIR/gcc-12.2.0/build/../configure --build=$(../config.guess) --host=$LFS_TGT --target=$LFS_TGT LDFLAGS_FOR_TARGET=-L$PWD/$LFS_TGT/libgcc --prefix=/usr --with-build-sysroot=$LFS --enable-initfini-array --disable-nls --disable-multilib --disable-decimal-float --disable-libatomic --disable-libgomp --disable-libquadmath --disable-libssp --disable-libvtv --enable-languages=c,c++
make && make DESTDIR=$LFS install && ln -sv gcc $LFS/usr/bin/cc
}
My env looks like this:
lfs:/mnt/lfs/sources/gcc-12.2.0$ env
PWD=/mnt/lfs/sources/gcc-12.2.0
HOME=/home/lfs
MAKEFLAGS=-j8
TERM=screen
SHLVL=1
PS1=\u:\w\$
LFS_TGT=x86_64-lfs-linux-gnu
LC_ALL=POSIX
LFS=/mnt/lfs
CONFIG_SITE=/mnt/lfs/usr/share/config.site
PATH=/mnt/lfs/tools/bin:/usr/bin
_=/usr/bin/env
OLDPWD=/mnt/lfs/sources/gcc-12.2.0/build
lfs:/mnt/lfs/sources/gcc-12.2.0$
I don't understand why its failing. Where have I gone wrong?

Embedding bash script into makefile

I want to include some conditional statement into a makefile:
SHELL=/bin/bash
all:
$(g++ -Wall main.cpp othersrc.cpp -o hello)
#if [[ $? -ne -1 ]]; then \
echo "Compile failed!"; \
exit 1; \
fi
But get an error:
/bin/bash: -c: line 0: conditional binary operator expected /bin/bash:
-c: line 0: syntax error near -1' /bin/bash: -c: line 0:if [[ -ne -1 ]]; then \' makefile:3: recipe for target 'all' failed make: *** [all] Error 1
How to fix it?
Note that each line of a makefile recipe runs in a different shell, so that $? of the previous line is unavailable, unless you use .ONESHELL option.
A fix without .ONESHELL:
all: hello
.PHONY: all
hello: main.cpp othersrc.cpp
g++ -o $# -Wall main.cpp othersrc.cpp && echo "Compile succeeded." || (echo "Compile failed!"; false)
With .ONESHELL:
all: hello
.PHONY: all
SHELL:=/bin/bash
.ONESHELL:
hello:
#echo "g++ -o $# -Wall main.cpp othersrc.cpp"
g++ -o $# -Wall main.cpp othersrc.cpp
if [[ $$? -eq 0 ]]; then
echo "Compile succeded!"
else
echo "Compile failed!"
exit 1
fi
When $ needs to be passed into a shell command it must be quoted as $$ in the makefile (make charges you a dollar for passing one dollar, basically). Hence $$?.

Cross compile for RISCV

I have a C program that I want to compile it for RISCV ISA. I have followed their instruction for installing the tools. Their tools work correctly and I can compile a "Hello world!" C program and run it. But right now I want to compile another C program that contains multiple files. I tried to change the makefile and instead of using gcc, I replace it with their compiler name riscv64-unknown-linux-gnu-gcc but I got:
Relocations in generic ELF (EM: 62)
error, then I tried to set CC = riscv64-unknown-linux-gnu-gcc but I got another error about pthread
unrecognized command line option '-pthread'
My question is that should I change the make file to use their compiler?
Thanks for your help in advance.
DEBUG := 0
PROFILE := 0
MRSFAST_VERSION := "3.3.1"
BUILD_DATE := "$(shell date)"
all: OPTIMIZE_FLAGS build
debug: DEBUG_FLAGS build
profile: PROFILE_FLAGS build
build: clean-executable SSE_FLAGS compile mrsfast snp_indexer clean
LDFLAGS=#-static
LIBS=-lz -lm -pthread -lpthread
CFLAGS=-fno-pic -DMRSFAST_VERSION=\"$(MRSFAST_VERSION)\" -DBUILD_DATE=\"$(BUILD_DATE)\"
objects=baseFAST.o Sort.o MrsFAST.o Common.o CommandLineParser.o RefGenome.o HashTable.o Reads.o Output.o SNPReader.o HELP.o
compile: $(objects)
mrsfast:
ifeq ($(shell uname -s),Linux)
gcc -w $(objects) -o $# ${LDFLAGS} ${LIBS}
else
gcc -Wl,-no_pie -fno-pic -w $(objects) -o $# ${LDFLAGS} ${LIBS}
endif
snp_indexer: SNPIndexer.o
gcc $^ -o $# ${LDFLAGS} ${LIBS}
clean:
#rm -f $(objects)
#rm -f SNPIndexer.o
#rm -f HELPstub.c
#rm -f HELPstub.o
clean-executable:
#rm -f mrsfast
HELP.o:
#groff -Tascii -man ./HELP.man > HELP
ifeq ($(shell uname -s),Linux)
#ld -r -b binary -o HELP.o HELP
else
#touch HELPstub.c
gcc -o HELPstub.o -c HELPstub.c
ld -r -o HELP.o -sectcreate binary HELP HELP HELPstub.o
endif
DEBUG_FLAGS:
$(eval CFLAGS = $(CFLAGS) -ggdb)
$(eval LIBS = $(LIBS) -ggdb)
OPTIMIZE_FLAGS:
$(eval CFLAGS = $(CFLAGS) -O2)
PROFILE_FLAGS:
$(eval CFLAGS = $(CFLAGS) -pg -g)
$(eval LIBS = $(LIBS) -pg -g)
SSE_FLAGS:
ifeq ($(shell uname -s),Linux)
ifeq ($(with-sse4),no)
$(shell echo "-DSSE4=0")
else
$(eval CFLAGS = $(CFLAGS) \
$(shell gv=`gcc -dumpversion`; \
sc=`grep -c "sse4" /proc/cpuinfo`; \
echo $$sc.$$gv | awk -F. '{if($$1>0 && $$2>=4 && $$3>=4) print "-DSSE4=1 -msse4.2"; else print "-DSSE4=0"}'))
endif
else
ifeq ($(with-sse4),no)
$(shell echo "-DSSE4=0")
else
$(eval CFLAGS = $(CFLAGS) \
$(shell gv=`gcc -dumpversion`; \
sc=`sysctl -n machdep.cpu.features | grep -c "SSE4"` ;\
echo $$sc.$$gv | awk -F. '{if($$1>0 && $$2>=4 && $$3>=4) print "-DSSE4=1 -msse4.2"; else print "-DSSE4=0"}'))
endif
endif

Simple bash script

im new to bash scripting and tring to make a script
goal: reciving 2 names (1 - logfilename 2- program name) the program should compile the program
and send both outputs to a log
if success then write "compile V" and return 0 else compile X and return number
i tried
#!/bin/bash
gcc {$2}.c -Wall -g -o $2> $1 2>&1
exit
and i have no idea how to check if it did or didnt success and the to echo V or X
edit:
thx for you guys, i got this
#!/bin/bash
gcc {$2}.c -Wall -g -o ${2}>${1} 2>&1
if (($?==0));then
echo Compile V
[else
echo compile X]
fi
exit
but all the if parts are still not working...
You can check exit status gcc like this:
#!/bin/bash
# execute gcc command
gcc "$2".c -Wall -g -o "$2"> "$1" 2>&1
# grab exit status of gcc
ret=$?
# write appropriate message as per return status value
((ret == 0)) && echo "compile V" || echo "compile X"
# return the exit status of gcc
exit $ret
You can check the success of a program in bash by command $? if echo $? = 0 then success else fail.
this code should work :
#!/bin/bash
gcc -v ${2}.c -Wall -g -o ${2}>${1} 2>&1
exit
Try this out:
#!/bin/bash
gcc "$2"".c" -Wall -g -o "$2" 2>&1 >"$1"
#check for error of previous command
if $? ; then echo compile V >>"$1"
else echo compile X >>"$1"; fi
exit

Resources