Move old MBR into the MBR directory; fix old reference to mbr.bin
[profile/ivi/syslinux.git] / Makefile
1 ## -----------------------------------------------------------------------
2 ##
3 ##   Copyright 1998-2006 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 # Main Makefile for SYSLINUX
15 #
16
17 # No builtin rules
18 MAKEFLAGS = -r
19
20 OSTYPE   = $(shell uname -msr)
21 CC       = gcc
22 INCLUDE  =
23 CFLAGS   = -W -Wall -Os -fomit-frame-pointer -D_FILE_OFFSET_BITS=64
24 PIC      = -fPIC
25 LDFLAGS  = -O2 -s
26 AR       = ar
27 RANLIB   = ranlib
28
29 NASM     = nasm -O99
30 NINCLUDE =
31 BINDIR   = /usr/bin
32 SBINDIR  = /sbin
33 LIBDIR   = /usr/lib
34 AUXDIR   = $(LIBDIR)/syslinux
35 INCDIR   = /usr/include
36
37 PERL     = perl
38
39 VERSION  = $(shell cat version)
40
41 %.o: %.c
42         $(CC) $(INCLUDE) $(CFLAGS) -c $<
43
44 #
45 # The BTARGET refers to objects that are derived from ldlinux.asm; we
46 # like to keep those uniform for debugging reasons; however, distributors
47 # want to recompile the installers (ITARGET).
48 #
49 # BOBJECTS and IOBJECTS are the same thing, except used for
50 # installation, so they include objects that may be in subdirectories
51 # with their own Makefiles.  Finally, there is a list of those
52 # directories.
53 #
54 CSRC     = syslxmod.c gethostip.c
55 NASMSRC  = $(wildcard *.asm)
56 SOURCES = $(CSRC) *.h $(NASMSRC) *.inc
57
58 # _bin.c files required by both BTARGET and ITARGET installers
59 BINFILES = bootsect_bin.c ldlinux_bin.c mbr_bin.c \
60            extlinux_bss_bin.c extlinux_sys_bin.c
61
62 # syslinux.exe is BTARGET so as to not require everyone to have the
63 # mingw suite installed
64 BTARGET  = kwdhash.gen version.gen version.h \
65            ldlinux.bss ldlinux.sys ldlinux.bin \
66            pxelinux.0 isolinux.bin isolinux-debug.bin \
67            extlinux.bin extlinux.bss extlinux.sys
68 BOBJECTS = $(BTARGET) mbr/mbr.bin dos/syslinux.com win32/syslinux.exe memdisk/memdisk
69 # BESUBDIRS and IESUBDIRS are "early", i.e. before the root; BSUBDIRS
70 # and ISUBDIRS are "late", after the root.
71 BESUBDIRS = mbr
72 BSUBDIRS = memdisk dos win32
73 ITARGET  = copybs.com gethostip mkdiskimage
74 IOBJECTS = $(ITARGET) mtools/syslinux unix/syslinux extlinux/extlinux
75 IESUBDIRS =
76 ISUBDIRS = mtools unix extlinux sample com32
77 DOCS     = COPYING NEWS README TODO BUGS *.doc sample menu com32
78 OTHER    = Makefile bin2c.pl now.pl genhash.pl keywords findpatch.pl \
79            keytab-lilo.pl version version.pl sys2ansi.pl \
80            ppmtolss16 lss16toppm memdisk bin2hex.pl mkdiskimage.in
81 OBSOLETE = pxelinux.bin
82
83 # Things to install in /usr/bin
84 INSTALL_BIN   = mtools/syslinux gethostip ppmtolss16 lss16toppm
85 # Things to install in /sbin
86 INSTALL_SBIN  = extlinux/extlinux
87 # Things to install in /usr/lib/syslinux
88 INSTALL_AUX   = pxelinux.0 isolinux.bin isolinux-debug.bin \
89                 dos/syslinux.com copybs.com memdisk/memdisk mbr/mbr.bin
90 INSTALL_AUX_OPT = win32/syslinux.exe
91
92 # The DATE is set on the make command line when building binaries for
93 # official release.  Otherwise, substitute a hex string that is pretty much
94 # guaranteed to be unique to be unique from build to build.
95 ifndef HEXDATE
96 HEXDATE := $(shell $(PERL) now.pl ldlinux.asm pxelinux.asm isolinux.asm)
97 endif
98 ifndef DATE
99 DATE    := $(HEXDATE)
100 endif
101 MAKE    += DATE=$(DATE) HEXDATE=$(HEXDATE)
102
103 #
104 # NOTE: If you don't have the mingw compiler suite installed, you probably
105 # want to remove win32 from this list; otherwise you're going to get an
106 # error every time you try to build.
107 #
108
109 all:
110         set -e ; for i in $(BESUBDIRS) $(IESUBDIRS) ; do $(MAKE) -C $$i $@ ; done
111         $(MAKE) all-local
112         set -e ; for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done
113         -ls -l $(BOBJECTS) $(IOBJECTS)
114
115 all-local: $(BTARGET) $(ITARGET) $(BINFILES)
116
117 installer: installer-local
118         set -e ; for i in $(ISUBDIRS); do $(MAKE) -C $$i all ; done
119         -ls -l $(BOBJECTS) $(IOBJECTS)
120
121 installer-local: $(ITARGET) $(BINFILES)
122
123 version.gen: version version.pl
124         $(PERL) version.pl $< $@ '%define'
125
126 version.h: version version.pl
127         $(PERL) version.pl $< $@ '#define'
128
129 kwdhash.gen: keywords genhash.pl
130         $(PERL) genhash.pl < keywords > kwdhash.gen
131
132 ldlinux.bin: ldlinux.asm kwdhash.gen version.gen
133         $(NASM) -f bin -DDATE_STR="'$(DATE)'" -DHEXDATE="$(HEXDATE)" \
134                 -DMAP=$(@:.bin=.map) -l $(@:.bin=.lst) -o $@ $<
135         $(PERL) checkov.pl ldlinux.map $@
136
137 pxelinux.bin: pxelinux.asm kwdhash.gen version.gen
138         $(NASM) -f bin -DDATE_STR="'$(DATE)'" -DHEXDATE="$(HEXDATE)" \
139                 -DMAP=$(@:.bin=.map) -l $(@:.bin=.lst) -o $@ $<
140         $(PERL) checkov.pl $(@:.bin=.map) $@
141
142 isolinux.bin: isolinux.asm kwdhash.gen version.gen checksumiso.pl
143         $(NASM) -f bin -DDATE_STR="'$(DATE)'" -DHEXDATE="$(HEXDATE)" \
144                 -DMAP=$(@:.bin=.map) -l $(@:.bin=.lst) -o $@ $<
145         $(PERL) checkov.pl $(@:.bin=.map) $@
146         $(PERL) checksumiso.pl $@
147
148 # Special verbose version of isolinux.bin
149 isolinux-debug.bin: isolinux-debug.asm kwdhash.gen version.gen checksumiso.pl
150         $(NASM) -f bin -DDATE_STR="'$(DATE)'" -DHEXDATE="$(HEXDATE)" \
151                 -DMAP=$(@:.bin=.map) -l $(@:.bin=.lst) -o $@ $<
152         $(PERL) checkov.pl $(@:.bin=.map) $@
153         $(PERL) checksumiso.pl $@
154
155 extlinux.bin: extlinux.asm kwdhash.gen version.gen
156         $(NASM) -f bin -DDATE_STR="'$(DATE)'" -DHEXDATE="$(HEXDATE)" \
157                 -DMAP=$(@:.bin=.map) -l $(@:.bin=.lst) -o $@ $<
158         $(PERL) checkov.pl $(@:.bin=.map) $@
159
160 pxelinux.0: pxelinux.bin
161         cp pxelinux.bin pxelinux.0
162
163 ldlinux.bss: ldlinux.bin
164         dd if=$< of=$@ bs=512 count=1
165
166 ldlinux.sys: ldlinux.bin
167         dd if=$< of=$@ bs=512 skip=1
168
169 extlinux.bss: extlinux.bin
170         dd if=$< of=$@ bs=512 count=1
171
172 extlinux.sys: extlinux.bin
173         dd if=$< of=$@ bs=512 skip=1
174
175 mbr_bin.c: mbr/mbr.bin bin2c.pl
176         $(PERL) bin2c.pl syslinux_mbr < $< > $@
177
178 copybs.com: copybs.asm
179         $(NASM) -f bin -l copybs.lst -o copybs.com copybs.asm
180
181 bootsect_bin.c: ldlinux.bss bin2c.pl
182         $(PERL) bin2c.pl syslinux_bootsect < $< > $@
183
184 ldlinux_bin.c: ldlinux.sys bin2c.pl
185         $(PERL) bin2c.pl syslinux_ldlinux < $< > $@
186
187 extlinux_bss_bin.c: extlinux.bss bin2c.pl
188         $(PERL) bin2c.pl extlinux_bootsect < $< > $@
189
190 extlinux_sys_bin.c: extlinux.sys bin2c.pl
191         $(PERL) bin2c.pl extlinux_image < $< > $@
192
193 libsyslinux.a: bootsect_bin.o ldlinux_bin.o mbr_bin.o syslxmod.o
194         rm -f $@
195         $(AR) cq $@ $^
196         $(RANLIB) $@
197
198 $(LIB_SO): bootsect_bin.o ldlinux_bin.o syslxmod.o
199         $(CC) $(LDFLAGS) -shared -Wl,-soname,$(LIB_SONAME) -o $@ $^
200
201 gethostip: gethostip.o
202         $(CC) $(LDFLAGS) -o $@ $^
203
204 mkdiskimage: mkdiskimage.in mbr.bin bin2hex.pl
205         $(PERL) bin2hex.pl < mbr.bin | cat mkdiskimage.in - > $@
206         chmod a+x $@
207
208 install: installer
209         mkdir -m 755 -p $(INSTALLROOT)$(BINDIR)
210         install -m 755 -c $(INSTALL_BIN) $(INSTALLROOT)$(BINDIR)
211         mkdir -m 755 -p $(INSTALLROOT)$(SBINDIR)
212         install -m 755 -c $(INSTALL_SBIN) $(INSTALLROOT)$(SBINDIR)
213         mkdir -m 755 -p $(INSTALLROOT)$(AUXDIR)
214         install -m 644 -c $(INSTALL_AUX) $(INSTALLROOT)$(AUXDIR)
215         -install -m 644 -c $(INSTALL_AUX_OPT) $(INSTALLROOT)$(AUXDIR)
216         $(MAKE) -C com32 install
217
218 install-lib: installer
219
220 install-all: install install-lib
221
222 local-tidy:
223         rm -f *.o *_bin.c stupid.* patch.offset
224         rm -f *.lst *.map
225         rm -f $(OBSOLETE)
226
227 tidy: local-tidy
228         set -e ; for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done
229
230 local-clean:
231         rm -f $(ITARGET)
232
233 clean: local-tidy local-clean
234         set -e ; for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done
235
236 dist: tidy
237         for dir in . sample memdisk ; do \
238                 ( cd $$dir && rm -f *~ \#* core ) ; \
239         done
240
241 local-spotless:
242         rm -f $(BTARGET) .depend *.so.*
243
244 spotless: local-clean dist local-spotless
245         set -e ; for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done
246
247 .depend:
248         rm -f .depend
249         for csrc in $(CSRC) ; do $(CC) $(INCLUDE) -MM $$csrc >> .depend ; done
250         for nsrc in $(NASMSRC) ; do $(NASM) -DDEPEND $(NINCLUDE) -o `echo $$nsrc | sed -e 's/\.asm/\.bin/'` -M $$nsrc >> .depend ; done
251
252 local-depend:
253         rm -f .depend
254         $(MAKE) .depend
255
256 depend: local-depend
257         $(MAKE) -C memdisk depend
258
259 # Shortcut to build unix/syslinux using klibc
260 klibc:
261         $(MAKE) clean
262         $(MAKE) CC=klcc ITARGET= ISUBDIRS='unix extlinux' BSUBDIRS=
263
264 # Hook to add private Makefile targets for the maintainer.
265 -include Makefile.private
266
267 # Include dependencies file
268 include .depend