Reputation: 1147
I am reading the code of xv6, and find it hard to read the Makefile. Could you tell me how the following statements work:
1. "CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)"
2. "LDFLAGS += -m $(shell $(LD) -V | grep elf_i386 2>/dev/null)"
3. "xv6.img:
bootblock kernel fs.img
dd if=/dev/zero of=xv6.img count=10000
dd if=bootblock of=xv6.img conv=notrunc
dd if=kernel of=xv6.img seek=1 conv=notrunc"
And how to learn Makefile in details? Could you recommand some good books?
Thank you!
Upvotes: 1
Views: 4323
Reputation: 41
To add to the answer, the dd
command acts like a copy command essentially taking an input file[if] and copying it's contents to the output file [of]. Count is an indicator of the number of the blocks that are to be copied.
The code provided by you relates with the building of the xv6.img file which contains the bootloader, file system and the kernel. The code is essentially copying 10000 blocks of zeros from the /dev/zero file into xv6.img. This is followed by copying from the bootblock(created by bootasm.S and bootmain.c as seen by the Makefile target) into sector 0. This is followed by seeking one sector and then copying the kernel into the image file.
Upvotes: 1
Reputation: 28525
CFLAGS
are the options ( like -fno-stack-protector
-E
etc ) you pass to your compiler CC
. $(CC)
will be replaced by the actual compiler. ie CC
should be initialized before this with something like set CC=gcc
.
LDFLAGS
are the options ( to your linker LD
. +=
is just like your +=
operator in C. It updates to the already existing value of CFLAGS
and LDFLAGS
This line means that xv6.img
is dependent on bootblock
kernel
fs.img
. That is we are telling make
that, in order to build xv6.img
, you need to build bootblock
kernel
and fs.img
first
You can learn about dd command here
Here is the complete encyclopedic guide to make
and Makefiles
http://www.gnu.org/software/make/manual/make.html
Upvotes: 2