[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: output of a command
From: |
Brian Dessent |
Subject: |
Re: output of a command |
Date: |
Sun, 22 Jul 2007 07:12:04 -0700 |
Martin Knappe wrote:
> Suppose I want to write a makefile with target "all"
> the command sequence for building "all" is as follows:
>
> -first, file "foo1.asm" should be compiled to "foo1.bin"
> -then, file foo2.asm should be compiled to foo2.bin: in the sourcefile
> "foo2.asm", the environment variable FOO is referenced, and must contain
> the size of "foo1.bin" IN BYTES..i have tried for 2 days now and i cant
> get it working :-( how can i set this environment variable for the
> second compilation?
> -after that, the file "binarydisk.bin" shall be built by placing the
> content of "foo1.bin" at the start of it, and then placing "foo2.bin" in
> "binarydisk.bin":
>
> -at sector X / Y, if X % sextorsize = 0
> -at sector X / Y + 1, if X % sectorsize <> 0
>
> ...where X is the size of foo1.bin in bytes and Y is the sectorsize in bytes
Ultimately, make is just a tool for invoking commands -- specifically
shell commands. So just break each of those steps down into a shell
script or shell fragment that does what you want. Remember that if you
want to do more than one thing in a shell fragment, you need to specify
it as one line to make using continuation-\ since otherwise make invokes
each command in a new shell process. And secondly remember that if you
want to reference a $var in the shell fragment you need to use $$ so
that it's not interpreted as a make variable.
Something like this (untested):
.SUFFIXES: .asm .o .bin
.PHONY: all
all: binarydisk.bin
%.bin: %.asm
$(AS) $< -o $@
foo1.bin: foo1.asm
foo2.bin: foo2.asm foo1.bin
$(AS) -DFOO=`stat -c %s $(word 2,$^)` $< -o $@
# or:
# env FOO=`stat -c %s $(word 2,$^)` $(AS) $< -o $@
sectorsize := 512
binarydisk.bin: foo1.bin foo2.bin
len=`stat -c %s $(word 1,$^)`; \
start=`expr $$len / $(sectorsize)`; \
if [ `expr $$len % $(sectorsize)` != 0 ]; then \
start=`expr $$start + 1`; \
fi; \
dd if=$(word 1,$^) of=$@ bs=$(sectorsize) && \
dd if=$(word 2,$^) of=$@ bs=$(sectorsize) seek=$$start
Brian