Build _bin.c files in libinstaller; clean up B/I separation
[profile/ivi/syslinux.git] / mbr / Makefile
1 ## -----------------------------------------------------------------------
2 ##
3 ##   Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
4 ##
5 ##   This program is free software; you can redistribute it and/or modify
6 ##   it under the terms of the GNU General Public License as published by
7 ##   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ##   Boston MA 02111-1307, USA; either version 2 of the License, or
9 ##   (at your option) any later version; incorporated herein by reference.
10 ##
11 ## -----------------------------------------------------------------------
12
13 #
14 # Makefile for MBR
15 #
16
17 TMPFILE = $(shell mktemp /tmp/gcc_ok.XXXXXX)
18
19 gcc_ok   = $(shell tmpf=$(TMPFILE); if $(CC) $(1) -c -x c /dev/null -o $$tmpf 2>/dev/null; \
20                    then echo $(1); else echo $(2); fi; rm -f $$tmpf)
21
22 M32       := $(call gcc_ok,-m32,) $(call gcc_ok,-ffreestanding,) $(call gcc_ok,-fno-stack-protector)
23
24 CC         = gcc
25 LD         = ld 
26 LDFLAGS    = -m elf_i386
27 SFLAGS     = $(M32) -march=i386
28 OBJCOPY    = objcopy
29 PERL       = perl
30
31 .SUFFIXES: .S .s .o .elf
32
33 all:    mbr.bin gptmbr.bin
34
35 .PRECIOUS: %.o
36 %.o: %.S
37         $(CC) $(SFLAGS) -Wa,-a=$*.lst -c -o $@ $<
38
39 mbr.elf: mbr.o mbr.ld
40         $(LD) $(LDFLAGS) -T mbr.ld -e _start -o $@ $<
41
42 mbr.bin: mbr.elf checksize.pl
43         $(OBJCOPY) -O binary $< $@
44         $(PERL) checksize.pl mbr.bin 440
45
46 mbr_bin.c: mbr.bin
47
48 gptmbr.elf: gptmbr.o mbr.ld
49         $(LD) $(LDFLAGS) -T mbr.ld -e _start -o $@ $<
50
51 gptmbr.bin: gptmbr.elf checksize.pl
52         $(OBJCOPY) -O binary $< $@
53         $(PERL) checksize.pl gptmbr.bin 424
54
55 tidy dist:
56         rm -f *.o *.elf *.lst
57
58 clean: tidy
59
60 spotless: clean
61         rm -f *.bin