make me understand make

Programming, for all ages and all languages.
Post Reply
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

make me understand make

Post by sancho1980 »

hi

im really desperate here, i dont understand make, really
have a look at this:

Code: Select all

#begin Makefile

BOOT_SIZE = $(shell stat -c %s boot.bin)

512.bin: 512.asm Makefile boot.bin.bin
    -rm 512.bin
    export BOOT_SIZE=$(BOOT_SIZE); nasm -f bin 512.asm -o 512.bin

boot.bin: main.o video.o utilities.o Makefile
    ld main.o video.o utilities.o -e start -N -M > boot.mem -o boot.bin --oformat binary -T script
    ndisasm -b 32 boot.bin > boot.ndisasm
    dd if=/dev/null of=gdt.bin seek=$(shell expr $(shell expr $(BOOT_SIZE) / 512) + 1) count=1

#end Makefile
Let me explain what this is *supposed* to do:

When boot.bin is made, the following things should occur (in this order):

1) Execute "ld main.o video.o utilities.o -e start -N -M > boot.mem -o boot.bin --oformat binary -T script"
2) Set BOOT_SIZE to contain the size of the newly created file "boot.bin" in bytes
3) Append zeroes to the end of "boot.bin" until the size (in bytes) of "boot.bin" is a multiple of 512.

When 512.bin is made, the following should occur (in this order):

1) "make boot.bin"
2) Make 512.bin via execution of "nasm -f bin 512.asm -o 512.bin" passing BOOT_SIZE to the compiler as an environment variable. This time, however, I want to refer to BOOT_SIZE as the NEW size of boot.bin (i.e. the multiple of 512).

When will I get this done? Any ideas?

Thanks

Martin
Solidus117
Posts: 23
Joined: Sun Dec 03, 2006 5:29 pm

Post by Solidus117 »

The power of Stallman compels you!
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

Maybe you could try getting rid of the extra .bin at the end of this line

Code: Select all

512.bin: 512.asm Makefile boot.bin.bin
Also you need to tell the makefile how to compile the .o files. You could add something like this

Code: Select all

main.o : main.c
    gcc main.c -o main.o
You would need to add the other .o files and the compiler options but that should work. Theres a better way to do that but I am posting at 1:46 in the morning.

One more thing, every line that is supposed to be executed eg. ld <something>, gcc <something> has to be started with a tab. Not 4 or 8 space characters, it has to be an actual tab character.
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Post by sancho1980 »

frank wrote: Also you need to tell the makefile how to compile the .o files. You could add something like this

Code: Select all

main.o : main.c
    gcc main.c -o main.o
You would need to add the other .o files and the compiler options but that should work.
Actually, my post was only a snippet showing where the problem lies (variables). Of course I had told make how to compile the .o files and this...
frank wrote:One more thing, every line that is supposed to be executed eg. ld <something>, gcc <something> has to be started with a tab. Not 4 or 8 space characters, it has to be an actual tab character.
Yes I know. I've got the solution now from someone on the make forum. My problem was with assigning the size in bytes of a file to a variable that doesnt even exist before running tha makefile so what you have to do is play around with $ and $$ and then it works (I haven't really understood it myself)...Cheers

Martin
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

Without digging through it, two thoughts:

- makefile variables and shell variables are two different things; don't use BOOT_SIZE for an environment variable and a makefile variable at once.

- use := to assign a value once (at script start); use = to assign a value evaluated at every occurrence of the variable name.
Every good solution is obvious once you've found it.
Post Reply