help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: someone make me understand make please


From: Paul Smith
Subject: Re: someone make me understand make please
Date: Sun, 05 Aug 2007 15:37:27 -0400

On Sun, 2007-08-05 at 20:00 +0100, Martin Knappe wrote:

> im trying to write a makefile; it doesnt work out the way i want; ill 
> just put part of it here so you're not put off:

It's very difficult to understand code examples when your mail client
reformats them.  Please find a way to avoid that (or get a better mail
client).

> BOOT_SIZE = $(shell stat -c %s boot.bin)
> 
> 512.bin: 512.asm Makefile boot.bin.bin

I don't understand: why does 512.bin depend on "boot.bin.bin", instead
of "boot.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

There is no guarantee in make that each line of the command script will
be expanded one at a time.  In fact, it's quite possible that the entire
command script, all lines, will all be expanded by make FIRST, before
the first command runs.

Since you are using a make $(shell ...) function here to find the size
of boot.bin, all instances will be expanded before any commands are run.
Including the instances in the dd command at the end.  This will
obviously not give you the right answer.

Since the command script is a shell script anyway, why are you using
make's $(shell ...) function?  Instead, just use the shell's `` (or, for
more modern shells, $( ... ) but don't forget to escape the "$" as "$$")
and then you know it won't be expanded until the right time.

> 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 kilobytes
> 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).

> Someone please help me with this. I've tried all I can think of...I'm 
> starting to think this isn't even possible with make...

It's much easier to help you if, in addition to what you want to happen,
you explain what actually happens.  Cut and paste of any error messages,
etc. would be very helpful (be sure to provide them EXACTLY, don't
paraphrase).

I see absolutely no reason why make cannot do what you want, but since
you haven't told us what doesn't work it's difficult for us to help you
fix it, beyond the information above.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

[Prev in Thread] Current Thread [Next in Thread]