Update Makefile to handle subdirectories cleaner; fix qsort
[profile/ivi/syslinux.git] / Makefile
1 ## -----------------------------------------------------------------------
2 ##  $Id$
3 ##
4 ##   Copyright 1998-2003 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., 675 Mass Ave, Cambridge MA 02139,
9 ##   USA; either version 2 of the License, or (at your option) any later
10 ##   version; incorporated herein by reference.
11 ##
12 ## -----------------------------------------------------------------------
13
14 #
15 # Main Makefile for SYSLINUX
16 #
17
18 OSTYPE   = $(shell uname -msr)
19 CC       = gcc
20 INCLUDE  =
21 CFLAGS   = -W -Wall -Os -fomit-frame-pointer -D_FILE_OFFSET_BITS=64
22 PIC      = -fPIC
23 LDFLAGS  = -O2 -s
24 AR       = ar
25 RANLIB   = ranlib
26
27 NASM     = nasm -O99
28 NINCLUDE = 
29 BINDIR   = /usr/bin
30 LIBDIR   = /usr/lib
31 AUXDIR   = $(LIBDIR)/syslinux
32 INCDIR   = /usr/include
33
34 PERL     = perl
35
36 VERSION  = $(shell cat version)
37
38 .c.o:
39         $(CC) $(INCLUDE) $(CFLAGS) -c $<
40
41 # libsyslinux.so
42 LIB_SONAME = libsyslinux.so.2
43 LIB_SO  = libsyslinux.so.$(VERSION)
44
45 #
46 # The BTARGET refers to objects that are derived from ldlinux.asm; we
47 # like to keep those uniform for debugging reasons; however, distributors 
48 # want to recompile the installers (ITARGET).
49 #
50 CSRC    = syslinux.c syslinux-nomtools.c syslxmod.c gethostip.c
51 NASMSRC  = ldlinux.asm syslinux.asm copybs.asm \
52           pxelinux.asm mbr.asm isolinux.asm isolinux-debug.asm
53 SOURCES = $(CSRC) *.h $(NASMSRC) *.inc
54 # syslinux.exe is BTARGET so as to not require everyone to have the
55 # mingw suite installed
56 BTARGET = kwdhash.gen version.gen ldlinux.bss ldlinux.sys ldlinux.bin \
57           pxelinux.0 mbr.bin isolinux.bin isolinux-debug.bin \
58           libsyslinux.a syslinux.exe $(LIB_SO) 
59 ITARGET = syslinux.com syslinux syslinux-nomtools copybs.com gethostip \
60           mkdiskimage
61 DOCS    = COPYING NEWS README TODO BUGS *.doc sample menu com32
62 OTHER   = Makefile bin2c.pl now.pl genhash.pl keywords findpatch.pl \
63           keytab-lilo.pl version version.pl sys2ansi.pl \
64           ppmtolss16 lss16toppm memdisk bin2hex.pl mkdiskimage.in
65 OBSOLETE = pxelinux.bin
66
67 # Things to install in /usr/bin
68 INSTALL_BIN   = syslinux gethostip ppmtolss16 lss16toppm
69 # Things to install in /usr/lib/syslinux
70 INSTALL_AUX   = pxelinux.0 isolinux.bin isolinux-debug.bin \
71                 syslinux.com syslinux.exe copybs.com memdisk/memdisk
72 # Things to install in /usr/lib
73 INSTALL_LIB   = $(LIB_SO) libsyslinux.a
74 # Things to install in /usr/include
75 INSTALL_INC   = syslinux.h
76
77 # The DATE is set on the make command line when building binaries for
78 # official release.  Otherwise, substitute a hex string that is pretty much
79 # guaranteed to be unique to be unique from build to build.
80 ifndef HEXDATE
81 HEXDATE := $(shell $(PERL) now.pl ldlinux.asm pxelinux.asm isolinux.asm)
82 endif
83 ifndef DATE
84 DATE    := $(HEXDATE)
85 endif
86
87 BSUBDIRS = memdisk win32
88 ISUBDIRS = sample com32
89
90 all:    $(BTARGET) $(ITARGET)
91         for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done
92         ls -l $(BTARGET) $(ITARGET) memdisk/memdisk
93
94 installer: $(ITARGET)
95         $(MAKE) -C $(ISUBDIRS) all
96         ls -l $(BTARGET) $(ITARGET)
97
98 version.gen: version version.pl
99         $(PERL) version.pl version
100
101 kwdhash.gen: keywords genhash.pl
102         $(PERL) genhash.pl < keywords > kwdhash.gen
103
104 ldlinux.bin: ldlinux.asm kwdhash.gen version.gen
105         $(NASM) -f bin -DDATE_STR="'$(DATE)'" -DHEXDATE="$(HEXDATE)" \
106                 -l ldlinux.lst -o ldlinux.bin ldlinux.asm
107
108 pxelinux.bin: pxelinux.asm kwdhash.gen version.gen
109         $(NASM) -f bin -DDATE_STR="'$(DATE)'" -DHEXDATE="$(HEXDATE)" \
110                 -l pxelinux.lst -o pxelinux.bin pxelinux.asm
111
112 isolinux.bin: isolinux.asm kwdhash.gen version.gen
113         $(NASM) -f bin -DDATE_STR="'$(DATE)'" -DHEXDATE="$(HEXDATE)" \
114                 -l isolinux.lst -o isolinux.bin isolinux.asm
115
116 pxelinux.0: pxelinux.bin
117         cp pxelinux.bin pxelinux.0
118
119 # Special verbose version of isolinux.bin
120 isolinux-debug.bin: isolinux-debug.asm kwdhash.gen
121         $(NASM) -f bin -DDATE_STR="'$(DATE)'" -DHEXDATE="$(HEXDATE)" \
122                 -l isolinux-debug.lst -o isolinux-debug.bin isolinux-debug.asm
123
124 ldlinux.bss: ldlinux.bin
125         dd if=ldlinux.bin of=ldlinux.bss bs=512 count=1
126
127 ldlinux.sys: ldlinux.bin
128         dd if=ldlinux.bin of=ldlinux.sys  bs=512 skip=1
129
130 patch.offset: ldlinux.sys findpatch.pl
131         $(PERL) findpatch.pl > patch.offset
132
133 mbr.bin: mbr.asm
134         $(NASM) -f bin -l mbr.lst -o mbr.bin mbr.asm
135
136 syslinux.com: syslinux.asm ldlinux.bss ldlinux.sys patch.offset
137         $(NASM) -f bin -DPATCH_OFFSET=`cat patch.offset` \
138                 -l syslinux.lst -o syslinux.com syslinux.asm
139
140 copybs.com: copybs.asm
141         $(NASM) -f bin -l copybs.lst -o copybs.com copybs.asm
142
143 bootsect_bin.c: ldlinux.bss bin2c.pl
144         $(PERL) bin2c.pl syslinux_bootsect < ldlinux.bss > bootsect_bin.c
145
146 ldlinux_bin.c: ldlinux.sys bin2c.pl
147         $(PERL) bin2c.pl syslinux_ldlinux < ldlinux.sys > ldlinux_bin.c
148
149 libsyslinux.a: bootsect_bin.o ldlinux_bin.o syslxmod.o
150         rm -f $@
151         $(AR) cq $@ $^
152         $(RANLIB) $@
153
154 $(LIB_SO): bootsect_bin.o ldlinux_bin.o syslxmod.o
155         $(CC) $(LDFLAGS) -shared -Wl,-soname,$(LIB_SONAME) -o $@ $^
156
157 syslinux: syslinux.o libsyslinux.a
158         $(CC) $(LDFLAGS) -o $@ $^
159
160 syslinux-nomtools: syslinux-nomtools.o libsyslinux.a
161         $(CC) $(LDFLAGS) -o $@ $^
162
163 syslxmod.o: syslxmod.c patch.offset
164         $(CC) $(INCLUDE) $(CFLAGS) $(PIC) -DPATCH_OFFSET=`cat patch.offset` \
165                 -c -o $@ $<
166
167 syslinux.exe: win32/syslinux-mingw.c libsyslinux.a
168         $(MAKE) -C win32 all
169
170 gethostip.o: gethostip.c
171
172 gethostip: gethostip.o
173
174 mkdiskimage: mkdiskimage.in mbr.bin bin2hex.pl
175         $(PERL) bin2hex.pl < mbr.bin | cat mkdiskimage.in - > $@
176         chmod a+x $@
177
178 install: installer
179         mkdir -m 755 -p $(INSTALLROOT)$(BINDIR) $(INSTALLROOT)$(AUXDIR)
180         install -m 755 -c $(INSTALL_BIN) $(INSTALLROOT)$(BINDIR)
181         install -m 644 -c $(INSTALL_AUX) $(INSTALLROOT)$(AUXDIR)
182
183 install-lib: installer
184         mkdir -m 755 -p $(INSTALLROOT)$(LIBDIR) $(INSTALLDIR)$(INCDIR)
185         install -m 644 -c $(INSTALL_LIB) $(INSTALLROOT)$(LIBDIR)
186         install -m 644 -c $(INSTALL_INC) $(INSTALLROOT)$(INCDIR)
187         cd $(INSTALLROOT)$(LIBDIR) && ln -sf $(LIB_SO) libsyslinux.so
188         if [ -z '$(INSTALLROOT)' ]; then ldconfig; fi
189
190 install-all: install install-all
191
192 local-tidy:
193         rm -f *.o *_bin.c stupid.* patch.offset
194         rm -f syslinux.lst copybs.lst pxelinux.lst isolinux*.lst
195         rm -f $(OBSOLETE)
196
197 tidy: local-tidy
198         for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done
199
200 local-clean:
201         rm -f $(ITARGET)
202
203 clean: local-tidy local-clean
204         for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done
205
206 dist: tidy
207         for dir in . sample memdisk ; do \
208                 ( cd $$dir && rm -f *~ \#* core ) ; \
209         done
210
211 local-spotless:
212         rm -f $(BTARGET) .depend *.so.*
213
214 spotless: local-clean dist local-spotless
215         for i in $(BSUBDIRS) $(ISUBDIRS) ; do $(MAKE) -C $$i $@ ; done
216
217 .depend:
218         rm -f .depend
219         for csrc in $(CSRC) ; do $(CC) $(INCLUDE) -MM $$csrc >> .depend ; done
220         for nsrc in $(NASMSRC) ; do $(NASM) -DDEPEND $(NINCLUDE) -o `echo $$nsrc | sed -e 's/\.asm/\.bin/'` -M $$nsrc >> .depend ; done
221
222 local-depend:
223         rm -f .depend
224         $(MAKE) .depend
225
226 depend: local-depend
227         $(MAKE) -C memdisk depend
228
229 # Hook to add private Makefile targets for the maintainer.
230 -include Makefile.private
231
232 # Include dependencies file
233 -include .depend