Solved Difference make and gmake.

File below is a descend gmake (gnu) makefile but it fails with make (bsd). Why ?
Code:
cat makefile 
COMPILER= c++11
MYFLAGS= -Wstrict-aliasing -fPIC -fpic -fPIE -fcf-protection -O2 -pipe -fPIE -fPIC -fstack-protector -Werror=implicit-function-declaration -Werror=format-security -fno-short-enums -fexceptions -fident -fverbose-asm -frecord-gcc-switches -fvisibility=default -fomit-frame-pointer -fstrict-aliasing -mstackrealign -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS  -Wformat -Wformat-security -Wall -Wpedantic -Wextra
all:    myapp
myapp:  myapp.o
    $(COMPILER)  $(MYFLAGS) -o myapp myapp.o 
myapp.o:    myapp.cpp
    $(COMPILER) -c $(CXXFLAGS) -o myapp.o myapp.cpp
clean:
    rm myapp.o
    rm myapp
 
For me gmake works fine ie
Code:
make clean ; gmake
rm myapp.o
rm myapp
c++11 -c  -o myapp.o myapp.cpp
c++11  -Wstrict-aliasing -fPIC -fpic -fPIE -fcf-protection -O2 -pipe -fPIE -fPIC -fstack-protector -Werror=implicit-function-declaration -Werror=format-security -fno-short-enums -fexceptions -fident -fverbose-asm -frecord-gcc-switches -fvisibility=default -fomit-frame-pointer -fstrict-aliasing -mstackrealign -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS  -Wformat -Wformat-security -Wall -Wpedantic -Wextra -o myapp myapp.o 
HOST:x: /home/x/Dirs/Src/languages/C_CPP/makefile1 >

But make for the same compiler c+11 errors :
Code:
make clean ; make
rm myapp.o
rm: myapp.o: No such file or directory
*** Error code 1
Stop.
make: stopped in /usr/home/x/Dirs/Src/languages/C_CPP/makefile1
c++11 -c -O2 -pipe "-Wstrict-aliasing -fPIC -fpic -fPIE -fcf-protection -O2 -pipe -fPIE -fPIC -fstack-protector -Werror=implicit-function-declaration -Werror=format-security -fno-short-enums -fexceptions -fident -fverbose-asm -frecord-gcc-switches -fvisibility=default -fomit-frame-pointer -fstrict-aliasing -mstackrealign -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS  -Wformat -Wformat-security -Wall -Wpedantic -Wextra" "-Wstrict-aliasing -fPIC -fpic -fPIE -fcf-protection -O2 -pipe -fPIE -fPIC -fstack-protector -Werror=implicit-function-declaration -Werror=format-security -fno-short-enums -fexceptions -fident -fverbose-asm -frecord-gcc-switches -fvisibility=default -fomit-frame-pointer -fstrict-aliasing -mstackrealign -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS  -Wformat -Wformat-security -Wall -Wpedantic -Wextra" -o myapp.o myapp.cpp
c++11: error: unrecognized command-line option '-Wstrict-aliasing -fPIC -fpic -fPIE -fcf-protection -O2 -pipe -fPIE -fPIC -fstack-protector -Werror=implicit-function-declaration -Werror=format-security -fno-short-enums -fexceptions -fident -fverbose-asm -frecord-gcc-switches -fvisibility=default -fomit-frame-pointer -fstrict-aliasing -mstackrealign -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS  -Wformat -Wformat-security -Wall -Wpedantic -Wextra'
c++11: error: unrecognized command-line option '-Wstrict-aliasing -fPIC -fpic -fPIE -fcf-protection -O2 -pipe -fPIE -fPIC -fstack-protector -Werror=implicit-function-declaration -Werror=format-security -fno-short-enums -fexceptions -fident -fverbose-asm -frecord-gcc-switches -fvisibility=default -fomit-frame-pointer -fstrict-aliasing -mstackrealign -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS  -Wformat -Wformat-security -Wall -Wpedantic -Wextra'
*** Error code 1
Stop.
make: stopped in /usr/home/x/Dirs/Src/languages/C_CPP/makefile1
 
Code:
~/builds$make
c++ -c -O2 -pipe -o myapp.o myapp.cpp
c++  -Wstrict-aliasing -fPIC -fpic -fPIE -fcf-protection -O2 -pipe -fPIE -fPIC -fstack-protector -Werror=implicit-function-declaration -Werror=format-security -fno-short-enums -fexceptions -fident -fverbose-asm -frecord-gcc-switches -fvisibility=default -fomit-frame-pointer -fstrict-aliasing -mstackrealign -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS  -Wformat -Wformat-security -Wall -Wpedantic -Wextra -o myapp myapp.o
c++: warning: argument unused during compilation: '-fident' [-Wunused-command-line-argument]
i dont have c++11 so i used c++
my make.conf is vanilla
 
That explains all. But it was hard to find. I seem to have two different c++ 11 compilers . i.e.
Code:
c++ -v
FreeBSD clang version 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c3fe)
Target: x86_64-unknown-freebsd13.0
Thread model: posix
InstalledDir: /usr/bin
And slightly different:
Code:
c++11 -v
Using built-in specs.
COLLECT_GCC=c++11
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc11/gcc/x86_64-portbld-freebsd13.0/11.2.0/lto-wrapper
Target: x86_64-portbld-freebsd13.0
Configured with: /wrkdirs/usr/ports/lang/gcc11/work/gcc-11.2.0/configure --enable-multilib --with-build-config=bootstrap-debug --disable-nls --enable-gnu-indirect-function --enable-host-shared --enable-plugin --libdir=/usr/local/lib/gcc11 --libexecdir=/usr/local/libexec/gcc11 --program-suffix=11 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc11/include/c++/ --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --without-zstd --with-isl=/usr/local --enable-languages=c,c++,objc,fortran,jit --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/man --infodir=/usr/local/share/info/gcc11 --build=x86_64-portbld-freebsd13.0
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.0 (FreeBSD Ports Collection)
 
Makefile below works for both compilers,
Code:
COMPILER:= c++
ONLY_C_FLAG:= -Werror=implicit-function-declaration
MYFLAGS:= -fno-lto -fPIE -fPIC -O2 -pipe -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -malign-double -mstackrealign -fno-short-enums -fexceptions -fident -fverbose-asm -frecord-gcc-switches -fvisibility=default -fomit-frame-pointer -fstrict-aliasing -fstack-protector-all  -fstack-protector-strong -fstack-clash-protection -fstack-protector -fcf-protection -Werror=format-security -Wformat-security -Wformat -Wall -Wpedantic -Wextra -Wstrict-aliasing
all:    myapp
myapp:  myapp.o
        $(COMPILER)  $(MYFLAGS) -o myapp myapp.o
myapp.o:        myapp.cpp
        $(COMPILER) -c $(MYFLAGS) -o myapp.o myapp.cpp
clean:
        rm myapp.o
        rm myapp
 
I suspect the problem is in the variable setting. For example, there is a space after the "=" in MYFLAGS=. Does that mean that the flags start with a space? What might the compiler do if the first argument is " -Werrorr..." (with a space before the hyphen)?

Also, it is not clear that the path that is used when running commands from inside make is the same path that is used interactively. Try defining the compiler as /usr/bin/c++ (or wherever the real compiler you want is stored), and see what that changes.
 
Back
Top