Turn a makefile into a list of build commands

43 views Asked by At

Currently I'm building the Linux kernel with the command make LLVM=1 CFLAGS_KERNEL="-mspeculative-load-hardening" Image but the build is failing because some files can't handle the -mspeculative-load-hardening flag. So what I want to do is turn the make command into a shell script consisting of the raw compile commands used to build the kernel. Then I can remove the -mspeculative-load-hardening flag from the problematic files manually.

I tried doing this by using make -n and piping the output to a file, but it looks like this:

make --no-print-directory -C /home/rutvik/kernel-asahi-slh \
-f /home/rutvik/kernel-asahi-slh/Makefile Image
make -f ./scripts/Makefile.build obj=scripts/basic
:
:
make -f ./scripts/Makefile.build obj=scripts/dtc
set -e;  echo '  HOSTCC  scripts/dtc/dtc.o';   trap 'rm -f scripts/dtc/dtc.o; trap - HUP; kill -s HUP $$' HUP;  trap 'rm -f scripts/dtc/dtc.o; trap - INT; kill -s INT $$' INT;  trap 'rm -f scripts/dtc/dtc.o; trap - QUIT; kill -s QUIT $$' QUIT;  trap 'rm -f scripts/dtc/dtc.o; trap - TERM; kill -s TERM $$' TERM;  trap 'rm -f scripts/dtc/dtc.o; trap - PIPE; kill -s PIPE $$' PIPE; clang -Wp,-MMD,scripts/dtc/.dtc.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu11   -I ./scripts/dtc/libfdt -DNO_YAML  -c -o scripts/dtc/dtc.o scripts/dtc/dtc.c; scripts/basic/fixdep scripts/dtc/.dtc.o.d scripts/dtc/dtc.o 'clang -Wp,-MMD,scripts/dtc/.dtc.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu11   -I ./scripts/dtc/libfdt -DNO_YAML  -c -o scripts/dtc/dtc.o scripts/dtc/dtc.c' > scripts/dtc/.dtc.o.cmd; rm -f scripts/dtc/.dtc.o.d
set -e;  echo '  HOSTCC  scripts/dtc/flattree.o';   trap 'rm -f scripts/dtc/flattree.o; trap - HUP; kill -s HUP $$' HUP;  trap 'rm -f scripts/dtc/flattree.o; trap - INT; kill -s INT $$' INT;  trap 'rm -f scripts/dtc/flattree.o; trap - QUIT; kill -s QUIT $$' QUIT;  trap 'rm -f scripts/dtc/flattree.o; trap - TERM; kill -s TERM $$' TERM;  trap 'rm -f scripts/dtc/flattree.o; trap - PIPE; kill -s PIPE $$' PIPE; clang -Wp,-MMD,scripts/dtc/.flattree.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu11   -I ./scripts/dtc/libfdt -DNO_YAML  -c -o scripts/dtc/flattree.o scripts/dtc/flattree.c; scripts/basic/fixdep scripts/dtc/.flattree.o.d scripts/dtc/flattree.o 'clang -Wp,-MMD,scripts/dtc/.flattree.o.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu11   -I ./scripts/dtc/libfdt -DNO_YAML  -c -o scripts/dtc/flattree.o scripts/dtc/flattree.c' > scripts/dtc/.flattree.o.cmd; rm -f scripts/dtc/.flattree.o.d

All the make commands are shown as part of the file. It looks like it's expanding them recursively, but if I try to run this file directly as a shell script, it'll run make which is what I want to avoid; I just want the compile commands that make eventually runs.

Is there a way to extract this info from a Makefile? Ideally I'd like to do it without having to modify the Makefile itself since it's quite complicated, but if that's the only way to accomplish my goal then so be it I suppose.

UPDATE: It looks like make -n by itself isn't extracting all the work that needs to be performed. A lot of preprocessing of files is done by the makefile that isn't part of the make -n output. I first need to do an actual build before the dry run even succeeds...

0

There are 0 answers