syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / memdisk / Makefile
1 #ident "$Id: Makefile,v 1.29 2004/12/29 01:58:02 hpa Exp $"
2 ## -----------------------------------------------------------------------
3 ##   
4 ##   Copyright 2001-2004 H. Peter Anvin - All Rights Reserved
5 ##
6 ##   This program is free software; you can redistribute it and/or modify
7 ##   it under the terms of the GNU General Public License as published by
8 ##   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ##   Boston MA 02111-1307, USA; either version 2 of the License, or
10 ##   (at your option) any later version; incorporated herein by reference.
11 ##
12 ## -----------------------------------------------------------------------
13
14 VERSION := $(shell cat ../version)
15
16 gcc_ok   = $(shell if gcc $(1) -c -x c /dev/null -o /dev/null 2>/dev/null; \
17                    then echo $(1); else echo $(2); fi)
18
19 M32     := $(call gcc_ok,-m32,)
20 ALIGN   := $(call gcc_ok,-falign-functions=0 -falign-jumps=0 -falign-loops=0,-malign-functions=0 -malign-jumps=0 -malign-loops=0)
21
22 CC       = gcc $(M32)
23 CFLAGS   = -g -W -Wall -Wno-sign-compare \
24            -Os -fomit-frame-pointer -march=i386 $(ALIGN) \
25            -DVERSION='"$(VERSION)"' -DDATE='"$(DATE)"'
26 LDFLAGS  = -g
27 INCLUDE  = -I../com32/include
28 LD       = ld -m elf_i386
29 NASM     = nasm -O99
30 NFLAGS   = -dVERSION='"$(VERSION)"' -dDATE='"$(DATE)"'
31 NINCLUDE = 
32 OBJCOPY  = objcopy
33 PERL     = perl
34
35 # Important: init.o16 must be first!!
36 OBJS16   = init.o16 init32.o
37 OBJS32   = start32.o setup.o msetup.o e820func.o conio.o memcpy.o memset.o \
38            unzip.o memdisk.o
39
40 CSRC     = setup.c msetup.c e820func.c conio.c unzip.c
41 SSRC     = 
42 NASMSRC  = memdisk.asm memdisk16.asm
43
44 all: memdisk e820test
45
46 # tidy, clean removes everything except the final binary
47 tidy:
48         rm -f *.o *.s *.o16 *.s16 *.bin *.lst *.elf e820test
49
50 clean: tidy
51
52 # spotless also removes the product binary
53 spotless: clean
54         rm -f memdisk .depend
55
56 %.o: %.asm
57         $(NASM) $(NFLAGS) -f elf -l $*.lst -o $@ $<
58
59 %.o: %.s
60         $(CC) -x assembler -c -o $@ $<
61
62 %.o16: %.s16
63         $(CC) -x assembler -c -o $@ $<
64
65 %.o: %.c
66         $(CC) $(INCLUDE) $(CFLAGS) -c -o $@ $<
67
68 %.s16: %.s
69         echo '.code16gcc' | cat - $< > $@
70
71 %.s: %.S
72         $(CC) -x c $(INCLUDE) $(CFLAGS) -traditional -E -o $@ $<
73
74 %.s16: %.S16
75         $(CC) -x c $(INCLUDE) $(CFLAGS) -traditional -E -o $@ $<
76
77 %.s: %.c
78         $(CC) $(INCLUDE) $(CFLAGS) -S -o $@ $<
79
80 %.i: %.c
81         $(CC) $(INCLUDE) $(CFLAGS) -E -o $@ $<
82
83 # Cancel default rule
84 %.o: %.c
85
86 %.bin: %.asm
87         $(NASM) -f bin $(NFLAGS) $(NINCLUDE) -o $@ -l $*.lst $<
88
89 memdisk16.elf: $(OBJS16)
90         $(LD) -Ttext 0 -o $@ $^
91
92 memdisk32.elf: $(OBJS32)
93         $(LD) -Ttext 0x100000 -o $@ $^
94
95 %.bin: %.elf
96         $(OBJCOPY) -O binary $< $@
97
98 memdisk: memdisk16.bin memdisk32.bin postprocess.pl
99         $(PERL) postprocess.pl $@ memdisk16.bin memdisk32.bin
100
101 e820test: e820func.o msetup.o e820test.o memdisk.o
102         $(CC) $(LDFLAGS) -o $@ $^
103
104 memdisk.o: memdisk.bin
105         $(LD) -r -b binary -o $@ $<
106
107 .depend:
108         rm -f .depend
109         for csrc in *.c ; do $(CC) $(INCLUDE) -MM $$csrc | sed -e 's/\.o/\.s/' >> .depend ; done
110         for ssrc in $(SSRC) ; do $(CC) $(INCLUDE) -x c -traditional -MM $$ssrc | sed -e 's/\.S16\.o/\.o16/' >> .depend ; done
111         for nsrc in $(NASMSRC) ; do $(NASM) -DDEPEND $(NINCLUDE) -o `echo $$nsrc | sed -e 's/\.asm/\.bin/'` -M $$nsrc >> .depend ; done
112
113 depend:
114         rm -f .depend
115         $(MAKE) .depend
116
117 # This file contains the version number, so add a dependency for it
118 setup.s: ../version
119
120 # Include dependencies file
121 include .depend