Compile Linux Kernel Modules into LLVM .bc bitcode - makefile

Background
I'm trying to compile certain drivers within the Linux kernel: drm (drivers/gpu/drm/drm_drv.o) and radeon (drivers/gpu/drm/radeon/) gpu drivers. I'm using LLVM for the purposes of static analysis (tracking the arguments used in copy_to/from_user() invocations).
So far, I'm able to compile the actual modules using the Makefile as shown below:
make CC=clang CFLAGS=-emit-llvm drivers/gpu/drm/radeon/
But this does not actually emit any llvm bitcode -- I need the .bc files to run my pass with opt.
I only know how to generate .bc files when using clang directly (like below), but not with Makefiles...
clang -emit-llvm hello.c -c -o hello.bc
Since that worked, I grabbed the verbose output of the GNU make operation, changed gcc to clang, and ran it to create the .bc file, which also worked:
clang -emit-llvm [[tons of CFLAGS]] -c -o drm_drv.bc drivers/gpu/drm/drm_drv.c
The only problem with that is I can only process a single C file in the kernel module at a time. Also it's very tedious to do this approach...
Main Problem
Which brings me to my main question: How would you go about emitting llvm .bc bitcode files using the kernel's Makefiles?
Or, if .bc bitcode creation must be done on a per-file basis, then how would I link them all together at the end so that I can run an LLVM opt pass on the aggregate of all the .bc files in a kernel module?

The best way to get LLVM IR in bitcode form out of Clang is to do LTO with the -flto command line flag.
If you have multiple translation units you can combine them together using the llvm-lto tool to "link" the bitcode files. Typically it generates code, but you can get it to drop the merged LLVM IR module with the -save-merged-module flag.
But none of this is really a supported interface. If this is a significantly useful workflow, you should talk to the LLVM developers about supporting something more akin to ld's -r.

I used clang to instrument ext2 module. There are 3 things that you want to do:
1) convert .c into .bc
2) run your optimiser on .bc file, and create an ext2-opt.o file
3) create ext2-instrumented.ko file from the ext2-opt.o file.
along with this, you also require a linux version compiled with clang. I could get linux 4.17 compiled with clang version 3.8.1 after disabling few modules. you can get it here
now, lets move to step 1 - as you said, run Make in verbose mode
make V=1 M=fs/ext2
and grab all options that are spit out by Makefile. the default compiler will be gcc. replace gcc with clang, add --emit-llvm command, and replace .o with .bc. the resultant compilataion command on my machine looks like so:
cd ../../ && clang -emit-llvm -Wp,-MD,fs/ext2/.all.o.d -nostdinc -isystem /usr/local/bin/../lib/clang/3.8.1/include -I./arch/x86/include -Iarch/x86/include/generated/uapi -Iarch/x86/include/generated -Iinclude -I./arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -Qunused-arguments -Wno-unknown-warning-option -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -no-integrated-as -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -O2 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-variable -Wno-format-invalid-specifier -Wno-gnu -Wno-asm-operand-widths -Wno-initializer-overrides -fno-builtin -Wno-tautological-compare -mno-global-merge -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Wno-initializer-overrides -Wno-unused-value -Wno-format -Wno-unknown-warning-option -Wno-sign-compare -Wno-format-zero-length -Wno-uninitialized -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(all)" -D"KBUILD_MODNAME=KBUILD_STR(ext2)" -mcmodel=kernel -c -o fs/ext2_instrumented/all.bc fs/ext2/all.c && cd -
this will create a .bc file for you. note that I have changed the resultant .bc codes directory to ext2_instrumented, i.e. my bc file is not created in fs/ext2 but in another folder called fs/ext2_instrumented. this is my work folder. I want this folder to not have any .c files, only .bc files. I need this because the default KBuild system looks for .c files in a folder. More on this later.
Step 2: Run all optimisation passes on your resultant ext2-instrumented.bc file using opt command like so:
opt -load $(DIR)/build/FSlice.so -constprop -sccp -mergereturn -sink -licm -reg2mem all.bc -o all.inst.bc
llvm-link -o all.inst2.bc $(DIR)/build/libFSlice.bc all.inst.bc
clang -mcmodel=kernel -c all.inst2.bc -o all.o
this will result into a .o file, which we will now compile into a .ko file in the next step:
Step 3:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) ext2instrumented.ko
Kbuild system is tough to understand, and even tougher to make modifications on. I would recommend use this 2 folder hack (1st folder to create .bc file and second folder to create .o and .ko files). To summarise, here is my resultant makefile in ext2_instrumented folder:
DIR=/home/fslice/fslice
obj-m += ext2instrumented.o
ext2instrumented-objs := all.o
all:
cd ../../ && clang -emit-llvm -Wp,-MD,fs/ext2/.all.o.d -nostdinc -isystem /usr/local/bin/../lib/clang/3.8.1/include -I./arch/x86/include -Iarch/x86/include/generated/uapi -Iarch/x86/include/generated -Iinclude -I./arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -Qunused-arguments -Wno-unknown-warning-option -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -no-integrated-as -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -m64 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -DCONFIG_X86_X32_ABI -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_SSSE3=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -DCONFIG_AS_SHA1_NI=1 -DCONFIG_AS_SHA256_NI=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -O2 -Wframe-larger-than=1024 -fno-stack-protector -Wno-unused-variable -Wno-format-invalid-specifier -Wno-gnu -Wno-asm-operand-widths -Wno-initializer-overrides -fno-builtin -Wno-tautological-compare -mno-global-merge -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Wno-initializer-overrides -Wno-unused-value -Wno-format -Wno-unknown-warning-option -Wno-sign-compare -Wno-format-zero-length -Wno-uninitialized -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(all)" -D"KBUILD_MODNAME=KBUILD_STR(ext2)" -mcmodel=kernel -c -o fs/ext2_instrumented/all.bc fs/ext2/all.c && cd -
opt -load $(DIR)/build/FSlice.so -constprop -sccp -mergereturn -sink -licm -reg2mem all.bc -o all.inst.bc
llvm-link -o all.inst2.bc $(DIR)/build/libFSlice.bc all.inst.bc
clang -mcmodel=kernel -c all.inst2.bc -o all.o
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) ext2instrumented.ko
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
rm -rf *.bc

Related

Where should I put cblas.h so that my build of mxnet will find it?

I'm trying to install mxnet by cloning a git repository as follows:
git clone --recursive https://github.com/dmlc/mxnet
However, when I try to build it by dropping into the mxnet directory and running make as follows:
make -j $(nproc) USE_OPENCV=1 USE_BLAS=openblas USE_CUDA=1 USE_CUDA_PATH=/usr/local/cuda USE_CUDNN=1
I get errors indicating that cblas.h cannot be found - e.g.
/home/me/mxnet/3rdparty/mshadow/mshadow/./base.h:162:14: fatal error: cblas.h: No such file or directory
#include <cblas.h>
The output of make is a series of nvcc compilation commands that seem to be as follows:
/usr/local/cuda/bin/nvcc -std=c++11 -Xcompiler -D_FORCE_INLINES -O3 -ccbin /home/me/anaconda2/envs/deepnets/bin/x86_64-conda_cos6-linux-gnu-c++ -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=[sm_75,compute_75] --fatbin-options -compress-all -Xcompiler "-DMSHADOW_FORCE_STREAM -Wall -Wsign-compare -O3 -DNDEBUG=1 -I/home/me/mxnet/3rdparty/mshadow/ -I/home/me/mxnet/3rdparty/dmlc-core/include -fPIC -I/home/me/mxnet/3rdparty/tvm/nnvm/include -I/home/me/mxnet/3rdparty/dlpack/include -I/home/me/mxnet/3rdparty/tvm/include -Iinclude -funroll-loops -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-local-typedefs -msse3 -mf16c -I/usr/local/cuda/include -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0 -I/home/me/mxnet/3rdparty/mkldnn/build/install/include -DMSHADOW_RABIT_PS=0 -DMSHADOW_DIST_PS=0 -DMSHADOW_USE_PASCAL=0 -DMXNET_USE_MKLDNN=1 -DUSE_MKL=1 -I/home/me/mxnet/src/operator/nn/mkldnn/ -I/home/me/mxnet/3rdparty/mkldnn/build/install/include -DMXNET_USE_OPENCV=1 -I/usr/local/include/opencv -I/usr/local/include -fopenmp -DMXNET_USE_OPERATOR_TUNING=1 -DMXNET_USE_LAPACK -DMSHADOW_USE_CUDNN=1 -I/home/me/mxnet/3rdparty/cub -DMXNET_ENABLE_CUDA_RTC=1 -DMXNET_USE_NCCL=0 -DMXNET_USE_LIBJPEG_TURBO=0" --generate-dependencies -MT build/src/operator/tensor/elemwise_unary_op_trig_gpu.o src/operator/tensor/elemwise_unary_op_trig.cu >build/src/operator/tensor/elemwise_unary_op_trig_gpu.d
If I break out (what I believe) to be all the include directories, I can pick out these directories:
-I/home/me/mxnet/3rdparty/mshadow/
-I/home/me/mxnet/3rdparty/dmlc-core/include -fPIC
-I/home/me/mxnet/3rdparty/tvm/nnvm/include
-I/home/me/mxnet/3rdparty/dlpack/include
-I/home/me/mxnet/3rdparty/tvm/include
-Iinclude -funroll-loops -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-local-typedefs -msse3 -mf16c
-I/usr/local/cuda/include -DMSHADOW_USE_CBLAS=1 -DMSHADOW_USE_MKL=0
-I/home/me/mxnet/3rdparty/mkldnn/build/install/include -DMSHADOW_RABIT_PS=0 -DMSHADOW_DIST_PS=0 -DMSHADOW_USE_PASCAL=0 -DMXNET_USE_MKLDNN=1 -DUSE_MKL=1
-I/home/me/mxnet/src/operator/nn/mkldnn/
-I/home/me/mxnet/3rdparty/mkldnn/build/install/include -DMXNET_USE_OPENCV=1
-I/usr/local/include/opencv
-I/usr/local/include -fopenmp -DMXNET_USE_OPERATOR_TUNING=1 -DMXNET_USE_LAPACK -DMSHADOW_USE_CUDNN=1
-I/home/me/mxnet/3rdparty/cub
When I look for cblas.h, I get see these copies:
(deepnets) me#Chanticleer:~/mxnet$ sudo find /home -name 'cblas.h'
[sudo] password for me:
/home/me/anaconda2/pkgs/openblas-0.3.3-h9ac9557_1001/include/cblas.h
/home/me/anaconda2/pkgs/lapack-3.6.1-ha44fe06_2/include/cblas.h
/home/me/anaconda2/pkgs/openblas-0.3.5-h9ac9557_1001/include/cblas.h
/home/me/anaconda2/envs/deepnets/include/cblas.h
/home/me/mxnet/julia/deps/cblas.h
(deepnets) me#Chanticleer:~/mxnet$ sudo find /usr -name 'cblas.h'
/usr/include/atlas/cblas.h
/usr/include/openblas/cblas.h
/usr/include/cblas.h
Clearly none of these seem to be where the Makefile has been directed to look. Do I need to change the Makefile in some way (how?), or do I need to put a copy of cblas.h in some other directory, or at least a soft link to it. If so, which directory and how?
If you're compiling with nvcc, you can just use the last include file, since it's in your include directory already, like this:
nvcc -I/usr/include <other stuff here...>
You don't have to do anything as drastic as manually copying; in fact I would really recommend against it because you're going to have to remember to re-do this when there's an update.
To answer your question about the makefile, if you were going to add the declaration I would say it's pretty common to see it being added to the $(CPPFLAGS) variable, which stands for C/C++ Preprocessor Flags. However, I would do this instead:
INCLUDE_DIRS = -I/usr/include
COMPILE.cpp = $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDE_DIRS) $(TARGET_ARCH) -c
OUTPUT_OPTION = -o $#
%.o: %.cpp
$(COMPILE.cpp) $(OUTPUT_OPTION) $^
The (proper) convention is for your users to be able to customize the $(CXX), $(CXXFLAGS), and $(CPPFLAGS) variables. Essentially, you want them to pick and customize their compiler, flags, and build options. Since you obviously need this include file, however (or you wouldn't have gotten this error), I would recommend setting it completely separately to avoid any confusion.
Anyways, good luck, man. I hope this helps.

multiplatform makefile defines were -dlinux_64 for linux, what use for mac

My makefile has the following defines for linux. What would the equivalent be for the mac build? I'm not seeing anything in an internet search for linux and mac defines or -dlinux_64.
DEFINES=-D_INCLUDE_POSIX_SOURCE -DLINUX -DLINUX_64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
DEBUG_DEFINES=$(DEFINES)
PROFILE_DEFINES=$(DEFINES)
During the build, it's showing like this:
/usr/bin/gcc -MM -fPIC -O2 -m64 -Wall -D_INCLUDE_POSIX_SOURCE -DLINUX -DLINUX_64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -I../inc -I. jdmainct.c > jdmainct.d
/usr/bin/gcc -fPIC -O2 -m64 -Wall -D_INCLUDE_POSIX_SOURCE -DLINUX -DLINUX_64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -I../inc -I. -c jdmarker.c -o jdmarker.o
...
Do I need to change that for the mac build? What is the equivalent for mac? Thanks!

How to compile boost async_client.cpp

What is the correct command to compile this code?
http://www.boost.org/doc/libs/1_45_0/doc/html/boost_asio/example/http/client/async_client.cpp
I had installed boost library in /usr/include/boost
E.g.
clang++ -std=c++03 -Wall -pedantic -g -O2 async_client.cpp -o async_client -lboost_system -lboost_thread -lpthread
Assuming your system's packaged version of Boost (or pre-configured include & lib paths). To make use of your custom built Boost library tree in ~/custom/boost:
clang++ -std=c++03 -Wall -pedantic -g -O2 \
-isystem ~/custom/boost/ ~/custom/boost/libs/asio/example/cpp03/http/client/ \
async_client.cpp -o async_client \
-L ~/custom/boost/stage/lib/ -Wl,-rpath,/home/sehe/custom/boost/stage/lib \
-lboost_system -lboost_thread -lpthread
Replace clang++ by g++ at will.
-std=c++03 -Wall -pedantic -g -O2 only for expositional purposes.

Library fails to build if "autoreconf -i" is run before ./configure

I'm working with a tool that is supposed to simplify the build process of Unix-based apps. One of the things it does automatically is run "autoreconf -i" before doing "./configure". However, when it tries to build the expat library on OSX (Lion), the build fails:
$ tar xfz expat-2.0.1.tar.gz; cd expat-2.0.1
$ autoreconf -i
glibtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `conftools'.
glibtoolize: copying file `conftools/ltmain.sh'
glibtoolize: You should add the contents of the following files to `aclocal.m4':
glibtoolize: `/usr/bin/../share/aclocal/libtool.m4'
glibtoolize: `/usr/bin/../share/aclocal/ltoptions.m4'
glibtoolize: `/usr/bin/../share/aclocal/ltversion.m4'
glibtoolize: `/usr/bin/../share/aclocal/ltsugar.m4'
glibtoolize: `/usr/bin/../share/aclocal/lt~obsolete.m4'
glibtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.in and
glibtoolize: rerunning glibtoolize, to keep the correct libtool macros in-tree.
glibtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
$ ./configure
(Lots of output here)
configure: creating ./config.status
config.status: creating Makefile
config.status: WARNING: Makefile.in seems to ignore the --datarootdir setting
config.status: creating expat_config.h
$ make
bin/sh ./libtool --silent --mode=compile gcc -std=gnu99 -I./lib -I. -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -DHAVE_EXPAT_CONFIG_H -o lib/xmlparse.lo -c lib/xmlparse.c
./libtool: line 473: CDPATH: command not found
./libtool: line 1297: func_opt_split: command not found
libtool: Version mismatch error. This is libtool 2.2.10, but the
libtool: definition of this LT_INIT comes from an older release.
libtool: You should recreate aclocal.m4 with macros from libtool 2.2.10
libtool: and run autoconf again.
On the other hand, if I don't do autoreconf first, it build just fiine:
$ cd ..; rm -r expat-2.0.1; tar xfz expat-2.0.1.tar.gz; cd expat-2.0.1
$ ./configure
(Lots of output here)
configure: creating ./config.status
config.status: creating Makefile
config.status: creating expat_config.h
$ make
/bin/sh ./libtool --silent --mode=compile gcc -I./lib -I. -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -DHAVE_EXPAT_CONFIG_H -o lib/xmlparse.lo -c lib/xmlparse.c
/bin/sh ./libtool --silent --mode=compile gcc -I./lib -I. -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -DHAVE_EXPAT_CONFIG_H -o lib/xmltok.lo -c lib/xmltok.c
/bin/sh ./libtool --silent --mode=compile gcc -I./lib -I. -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -DHAVE_EXPAT_CONFIG_H -o lib/xmlrole.lo -c lib/xmlrole.c
/bin/sh ./libtool --silent --mode=link gcc -I./lib -I. -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -DHAVE_EXPAT_CONFIG_H -no-undefined -version-info 6:2:5 -rpath /usr/local/lib -o libexpat.la lib/xmlparse.lo lib/xmltok.lo lib/xmlrole.lo
gcc -I./lib -I. -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -DHAVE_EXPAT_CONFIG_H -o xmlwf/xmlwf.o -c xmlwf/xmlwf.c
gcc -I./lib -I. -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -DHAVE_EXPAT_CONFIG_H -o xmlwf/xmlfile.o -c xmlwf/xmlfile.c
gcc -I./lib -I. -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -DHAVE_EXPAT_CONFIG_H -o xmlwf/codepage.o -c xmlwf/codepage.c
gcc -I./lib -I. -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -DHAVE_EXPAT_CONFIG_H -o xmlwf/unixfilemap.o -c xmlwf/unixfilemap.c
/bin/sh ./libtool --silent --mode=link gcc -I./lib -I. -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -fexceptions -DHAVE_EXPAT_CONFIG_H -o xmlwf/xmlwf xmlwf/xmlwf.o xmlwf/xmlfile.o xmlwf/codepage.o xmlwf/unixfilemap.o libexpat.la
What is "autoreconf -i" doing, and why is it causing the build to fail?
I think the problem is here:
libtool: Version mismatch error. This is libtool 2.2.10, but the
libtool: definition of this LT_INIT comes from an older release.
libtool: You should recreate aclocal.m4 with macros from libtool 2.2.10
libtool: and run autoconf again.
In my experience with OS X Leopard and Snow Leopard (I have not tried Lion yet), the autotools actually installed with OS X are not recent enough to actually reconfigure anything for the system. So I usually grab the latest autotools from a GNU mirror and make a local version of them if I need to reconfigure.
"autoreconf -i" copies files from the installed GNU autotools to AC_CONFIG_AUX_DIR, an in this case is probably ltmain.sh.
A user should never run autoreconf. As ldav1s points out (+1), the autotools installed on your box do not match the tools used to generate the tarball. There are many packages in the wild that recommend (or even require) the user to run autoconf in some form to build the package; those packages are broken. A properly built package should build on a machine that does not have any of the autotools installed, and unless you are a package maintainer you should probably just uninstall them. IMO, they should not be included in default installations.
If you use a package that requires the autotools to build, please report that as a bug to the package maintainer. If a version control system (eg git, hg, svn ) is being used as the distribution mechanism, then you will either need to run the autotools to build the package or the package will have to include autotools generated files in the repository. This is why version control systems should not be used as a distribution tool for packages that use the autotools.

Suppress all make output except for errors and warnings

I have a makefile which builds a project composed of many files which all need to be built.
To make matters more complicated, I have a number of included directories in each call to gcc (so each call to gcc looks long on the command line).
I'd like to suppress all output except for errors and warnings (so that I can actually see them when make runs!)
Is there any way to do this?
make -s should do what you're after a bit more neatly. I don't know of a way to force it on the makefiles, but the GNU manual might have one.
Failing that you could check the Linux kernel build system, since that seems to automatically hide stdout.
By adding a "#" to the front of a command, the command line string is suppressed
e.g.
from
$(addprefix $(OUTPUT_PATH)/,$(C_OBJ)): $(OUTPUT_PATH)/%.o: %.c
$(CC) -c $(CFLAGS) $< -o $#
to
$(addprefix $(OUTPUT_PATH)/,$(C_OBJ)): $(OUTPUT_PATH)/%.o: %.c
#$(CC) -c $(CFLAGS) $< -o $#
will take
make[1]: Entering directory `.../libraries/libgcdc/build'
/home/crowe/arm-tools/gcc-arm-none-eabi-4_6-2012q2/bin/arm-none-eabi-gcc -c -Wall -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Werror-implicit-function-declaration -Wmain -Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings -Wsign-compare -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations -Wpacked -Wredundant-decls -Wnested-externs -Winline -Wlong-long -Wunreachable-code -Wcast-align --param max-inline-insns-single=500 -mcpu=cortex-m3 -mthumb -mlong-calls -ffunction-sections -g -O0 -D DEBUG -I.. -I../include -I../../libchip_sam3s -I../../libboard_arm_demo -I../../libboard_generic -I../../libusb/include -Dsam3s4 -DTRACE_LEVEL=5 -Dprintf=iprintf ../source/hid_callbacks.c -o debug_sam3s_svn2/hid_callbacks.o
make[1]: Leaving directory ` .../libraries/libgcdc/build'
to
make[1]: Entering directory `.../libraries/libgcdc/build'
make[1]: Leaving directory `.../libraries/libgcdc/build'
You can also force the -s option as suggested by PaulW directly in the Makefile. Just add:
.SILENT:
Depending on how "errors and warnings" are reported ...
make > /dev/null
That will redirect all STDOUT (Standard Output) from the make command (and thus all sub-processes it spawns) to the endless bit-bucket of nothingness. This may be too greedy though, as some programs use STDOUT (and not STDERR) to report warnings.
I do not know of a way globally change STDOUT of all sub-processes from within the context of the Makefile itself.
Happy coding.

Resources