Merge branch 'syslinux-5.xx'
[syslinux.git] / Makefile
blobd0dc5140017f77a4d14edfdfbf8105f4e35779ba
1 ## -----------------------------------------------------------------------
2 ##
3 ## Copyright 1998-2009 H. Peter Anvin - All Rights Reserved
4 ## Copyright 2009-2014 Intel Corporation; author: H. Peter Anvin
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.
12 ## -----------------------------------------------------------------------
15 # Main Makefile for SYSLINUX
18 all_firmware := bios efi32 efi64
21 # topdir is only set when we are doing a recursive make. Do a bunch of
22 # initialisation if it's unset since this is the first invocation.
24 ifeq ($(topdir),)
26 topdir = $(CURDIR)
29 # Because we need to build modules multiple times, e.g. for BIOS,
30 # efi32, efi64, we output all object and executable files to a
31 # separate object directory for each firmware.
33 # The output directory can be customised by setting the O=/obj/path/
34 # variable when invoking make. If no value is specified the default
35 # directory is the top-level of the Syslinux source.
37 ifeq ("$(origin O)", "command line")
38 OBJDIR := $(O)
39 else
40 OBJDIR = $(topdir)
41 endif
43 # If the output directory does not exist we bail because that is the
44 # least surprising thing to do.
45 cd-output := $(shell cd $(OBJDIR) && /bin/pwd)
46 $(if $(cd-output),, \
47 $(error output directory "$(OBJDIR)" does not exist))
50 # These environment variables are exported to every invocation of
51 # make,
53 # 'topdir' - the top-level directory containing the Syslinux source
54 # 'objdir' - the top-level directory of output files for this firmware
55 # 'MAKEDIR' - contains Makefile fragments
56 # 'OBJDIR' - the top-level directory of output files
58 # There are also a handful of variables that are passed to each
59 # sub-make,
61 # SRC - source tree location of the module being compiled
62 # OBJ - output tree location of the module being compiled
64 # A couple of rules for writing Makefiles,
66 # - Do not use relative paths, use the above variables
67 # - You can write $(SRC) a lot less if you add it to VPATH
70 MAKEDIR = $(topdir)/mk
71 export MAKEDIR topdir OBJDIR
73 include $(MAKEDIR)/syslinux.mk
74 -include $(OBJDIR)/version.mk
76 private-targets = prerel unprerel official release burn isolinux.iso \
77 preupload upload test unittest regression spotless
79 ifeq ($(MAKECMDGOALS),)
80 MAKECMDGOALS += all
81 endif
84 # The 'bios', 'efi32' and 'efi64' are dummy targets. Their only
85 # purpose is to instruct us which output directories need
86 # creating. Which means that we always need a *real* target, such as
87 # 'all', appended to the make goals.
89 firmware = $(all_firmware)
90 real-target := $(filter-out $(firmware), $(MAKECMDGOALS))
91 real-firmware := $(filter $(firmware), $(MAKECMDGOALS))
93 ifeq ($(real-target),)
94 real-target = all
95 endif
97 ifeq ($(real-firmware),)
98 real-firmware = $(firmware)
99 endif
101 .PHONY: $(filter-out $(private-targets), $(MAKECMDGOALS))
102 $(filter-out $(private-targets), $(MAKECMDGOALS)):
103 $(MAKE) -C $(OBJDIR) -f $(CURDIR)/Makefile SRC="$(topdir)" \
104 OBJ=$(OBJDIR) objdir=$(OBJDIR) $(MAKECMDGOALS)
106 unittest:
107 printf "Executing unit tests\n"
108 $(MAKE) -C core/mem/tests all
109 $(MAKE) -C com32/lib/syslinux/tests all
111 regression:
112 $(MAKE) -C tests SRC="$(topdir)/tests" OBJ="$(topdir)/tests" \
113 objdir=$(OBJDIR) \
114 -f $(topdir)/tests/Makefile all
116 test: unittest regression
118 # Hook to add private Makefile targets for the maintainer.
119 -include $(topdir)/Makefile.private
121 else # ifeq ($(topdir),)
123 include $(MAKEDIR)/syslinux.mk
125 # Hook to add private Makefile targets for the maintainer.
126 -include $(topdir)/Makefile.private
129 # The BTARGET refers to objects that are derived from ldlinux.asm; we
130 # like to keep those uniform for debugging reasons; however, distributors
131 # want to recompile the installers (ITARGET).
133 # BOBJECTS and IOBJECTS are the same thing, except used for
134 # installation, so they include objects that may be in subdirectories
135 # with their own Makefiles. Finally, there is a list of those
136 # directories.
139 ifndef EFI_BUILD
140 MODULES = memdisk/memdisk memdump/memdump.com \
141 com32/menu/*.c32 com32/modules/*.c32 com32/mboot/*.c32 \
142 com32/hdt/*.c32 com32/rosh/*.c32 com32/gfxboot/*.c32 \
143 com32/sysdump/*.c32 com32/lua/src/*.c32 com32/chain/*.c32 \
144 com32/lib/*.c32 com32/libutil/*.c32 com32/gpllib/*.c32 \
145 com32/elflink/ldlinux/*.c32 com32/cmenu/libmenu/*.c32
146 else
147 # memdump is BIOS specific code exclude it for EFI
148 # FIXME: Prune other BIOS-centric modules
149 MODULES = com32/menu/*.c32 com32/modules/*.c32 com32/mboot/*.c32 \
150 com32/hdt/*.c32 com32/rosh/*.c32 com32/gfxboot/*.c32 \
151 com32/sysdump/*.c32 com32/lua/src/*.c32 com32/chain/*.c32 \
152 com32/lib/*.c32 com32/libutil/*.c32 com32/gpllib/*.c32 \
153 com32/cmenu/libmenu/*.c32 com32/elflink/ldlinux/$(LDLINUX)
154 endif
156 # List of module objects that should be installed for all derivatives
157 INSTALLABLE_MODULES = $(MODULES)
159 # syslinux.exe is BTARGET so as to not require everyone to have the
160 # mingw suite installed
161 BTARGET = version.gen version.h $(OBJDIR)/version.mk
162 BOBJECTS = $(BTARGET) \
163 mbr/*.bin \
164 core/pxelinux.0 core/lpxelinux.0 \
165 core/isolinux.bin core/isolinux-debug.bin \
166 gpxe/gpxelinux.0 dos/syslinux.com \
167 win32/syslinux.exe win64/syslinux64.exe \
168 dosutil/*.com dosutil/*.sys \
169 $(MODULES)
171 # BSUBDIRs build the on-target binary components.
172 # ISUBDIRs build the installer (host) components.
174 # Note: libinstaller is both a BSUBDIR and an ISUBDIR. It contains
175 # files that depend only on the B phase, but may have to be regenerated
176 # for "make installer".
178 ifdef EFI_BUILD
180 BSUBDIRS = codepage com32 lzo core mbr sample efi txt
181 ISUBDIRS =
183 INSTALLSUBDIRS = efi
185 NETINSTALLABLE = efi/syslinux.efi $(INSTALLABLE_MODULES)
187 else
189 BSUBDIRS = codepage com32 lzo core memdisk mbr memdump gpxe sample \
190 diag libinstaller dos win32 win64 dosutil txt
192 ITARGET =
193 IOBJECTS = $(ITARGET) \
194 utils/gethostip utils/isohybrid utils/mkdiskimage \
195 mtools/syslinux linux/syslinux extlinux/extlinux
196 ISUBDIRS = libinstaller mtools linux extlinux utils
198 # Things to install in /usr/bin
199 INSTALL_BIN = mtools/syslinux
200 # Things to install in /sbin
201 INSTALL_SBIN = extlinux/extlinux
202 # Things to install in /usr/lib/syslinux
203 INSTALL_AUX = core/pxelinux.0 gpxe/gpxelinux.0 gpxe/gpxelinuxk.0 \
204 core/isolinux.bin core/isolinux-debug.bin \
205 dos/syslinux.com core/lpxelinux.0 \
206 mbr/*.bin $(INSTALLABLE_MODULES)
207 INSTALL_AUX_OPT = win32/syslinux.exe win64/syslinux64.exe
208 INSTALL_DIAG = diag/mbr/handoff.bin \
209 diag/geodsp/geodsp1s.img.xz diag/geodsp/geodspms.img.xz
211 # These directories manage their own installables
212 INSTALLSUBDIRS = com32 utils dosutil
214 # Things to install in /boot/extlinux
215 EXTBOOTINSTALL = $(INSTALLABLE_MODULES)
217 # Things to install in /tftpboot
218 NETINSTALLABLE = core/pxelinux.0 gpxe/gpxelinux.0 core/lpxelinux.0 \
219 $(INSTALLABLE_MODULES)
221 endif # ifdef EFI_BUILD
223 .PHONY: subdirs $(BSUBDIRS) $(ISUBDIRS) test
225 ifeq ($(HAVE_FIRMWARE),)
227 firmware = $(all_firmware)
229 # If no firmware was specified the rest of MAKECMDGOALS applies to all
230 # firmware.
231 ifeq ($(filter $(firmware),$(MAKECMDGOALS)),)
232 all strip tidy clean dist install installer netinstall: $(all_firmware)
234 else
236 # Don't do anything for the rest of MAKECMDGOALS at this level. It
237 # will be handled for each of $(firmware).
238 strip tidy clean dist install installer netinstall:
240 endif
242 # Convert 'make bios strip' to 'make strip', etc for rest of the Makefiles.
243 MAKECMDGOALS := $(filter-out $(firmware),$(MAKECMDGOALS))
244 ifeq ($(MAKECMDGOALS),)
245 MAKECMDGOALS += all
246 endif
249 # You'd think that we'd be able to use the 'define' directive to
250 # abstract the code for invoking make(1) in the output directory, but
251 # by using 'define' we lose the ability to build in parallel.
253 .PHONY: $(firmware)
254 bios:
255 @mkdir -p $(OBJ)/bios
256 $(MAKE) -C $(OBJ)/bios -f $(SRC)/Makefile SRC="$(SRC)" \
257 objdir=$(OBJ)/bios OBJ=$(OBJ)/bios HAVE_FIRMWARE=1 \
258 ARCH=i386 LDLINUX=ldlinux.c32 $(MAKECMDGOALS)
260 efi32:
261 @mkdir -p $(OBJ)/efi32
262 $(MAKE) -C $(OBJ)/efi32 -f $(SRC)/Makefile SRC="$(SRC)" \
263 objdir=$(OBJ)/efi32 OBJ=$(OBJ)/efi32 HAVE_FIRMWARE=1 \
264 ARCH=i386 BITS=32 EFI_BUILD=1 LDLINUX=ldlinux.e32 \
265 $(MAKECMDGOALS)
267 efi64:
268 @mkdir -p $(OBJ)/efi64
269 $(MAKE) -C $(OBJ)/efi64 -f $(SRC)/Makefile SRC="$(SRC)" \
270 objdir=$(OBJ)/efi64 OBJ=$(OBJ)/efi64 HAVE_FIRMWARE=1 \
271 ARCH=x86_64 BITS=64 EFI_BUILD=1 LDLINUX=ldlinux.e64 \
272 $(MAKECMDGOALS)
274 else # ifeq($(HAVE_FIRMWARE),)
276 all: all-local subdirs
278 all-local: $(BTARGET) $(ITARGET)
279 -ls -l $(BOBJECTS) $(IOBJECTS)
280 subdirs: $(BSUBDIRS) $(ISUBDIRS)
282 $(sort $(ISUBDIRS) $(BSUBDIRS)):
283 @mkdir -p $@
284 $(MAKE) -C $@ SRC="$(SRC)/$@" OBJ="$(OBJ)/$@" \
285 -f $(SRC)/$@/Makefile $(MAKECMDGOALS)
287 $(ITARGET):
288 @mkdir -p $@
289 $(MAKE) -C $@ SRC="$(SRC)/$@" OBJ="$(OBJ)/$@" \
290 -f $(SRC)/$@/Makefile $(MAKECMDGOALS)
292 $(BINFILES):
293 @mkdir -p $@
294 $(MAKE) -C $@ SRC="$(SRC)/$@" OBJ="$(OBJ)/$@" \
295 -f $(SRC)/$@/Makefile $(MAKECMDGOALS)
298 # List the dependencies to help out parallel builds.
299 dos extlinux linux mtools win32 win64: libinstaller
300 libinstaller: core
301 utils: mbr
302 core: com32
303 efi: core
304 gpxe: core
306 installer: installer-local
307 set -e; for i in $(ISUBDIRS); \
308 do $(MAKE) -C $$i SRC="$(SRC)/$$i" OBJ="$(OBJ)/$$i" \
309 -f $(SRC)/$$i/Makefile all; done
312 installer-local: $(ITARGET) $(BINFILES)
314 strip: strip-local
315 set -e; for i in $(ISUBDIRS); \
316 do $(MAKE) -C $$i SRC="$(SRC)/$$i" OBJ="$(OBJ)/$$i" \
317 -f $(SRC)/$$i/Makefile strip; done
318 -ls -l $(BOBJECTS) $(IOBJECTS)
320 strip-local:
322 version.gen: $(topdir)/version $(topdir)/version.pl
323 $(PERL) $(topdir)/version.pl $< $@ '%define < @'
324 version.h: $(topdir)/version $(topdir)/version.pl
325 $(PERL) $(topdir)/version.pl $< $@ '#define < @'
327 local-install: installer
328 mkdir -m 755 -p $(INSTALLROOT)$(BINDIR)
329 install -m 755 -c $(INSTALL_BIN) $(INSTALLROOT)$(BINDIR)
330 mkdir -m 755 -p $(INSTALLROOT)$(SBINDIR)
331 install -m 755 -c $(INSTALL_SBIN) $(INSTALLROOT)$(SBINDIR)
332 mkdir -m 755 -p $(INSTALLROOT)$(AUXDIR)
333 install -m 644 -c $(INSTALL_AUX) $(INSTALLROOT)$(AUXDIR)
334 -install -m 644 -c $(INSTALL_AUX_OPT) $(INSTALLROOT)$(AUXDIR)
335 mkdir -m 755 -p $(INSTALLROOT)$(DIAGDIR)
336 install -m 644 -c $(INSTALL_DIAG) $(INSTALLROOT)$(DIAGDIR)
337 mkdir -m 755 -p $(INSTALLROOT)$(MANDIR)/man1
338 install -m 644 -c $(topdir)/man/*.1 $(INSTALLROOT)$(MANDIR)/man1
339 : mkdir -m 755 -p $(INSTALLROOT)$(MANDIR)/man8
340 : install -m 644 -c man/*.8 $(INSTALLROOT)$(MANDIR)/man8
342 ifndef EFI_BUILD
343 install: local-install
344 set -e ; for i in $(INSTALLSUBDIRS) ; \
345 do $(MAKE) -C $$i SRC="$(SRC)/$$i" OBJ="$(OBJ)/$$i" \
346 -f $(SRC)/$$i/Makefile $@; done
347 else
348 install:
349 mkdir -m 755 -p $(INSTALLROOT)$(AUXDIR)/efi$(BITS)
350 set -e ; for i in $(INSTALLSUBDIRS) ; \
351 do $(MAKE) -C $$i SRC="$(SRC)/$$i" OBJ="$(OBJ)/$$i" \
352 BITS="$(BITS)" AUXDIR="$(AUXDIR)/efi$(BITS)" \
353 -f $(SRC)/$$i/Makefile $@; done
354 -install -m 644 $(INSTALLABLE_MODULES) $(INSTALLROOT)$(AUXDIR)/efi$(BITS)
355 install -m 644 com32/elflink/ldlinux/$(LDLINUX) $(INSTALLROOT)$(AUXDIR)/efi$(BITS)
356 endif
358 ifdef EFI_BUILD
359 netinstall:
360 mkdir -p $(INSTALLROOT)$(TFTPBOOT)/efi$(BITS)
361 install -m 644 $(NETINSTALLABLE) $(INSTALLROOT)$(TFTPBOOT)/efi$(BITS)
362 else
363 netinstall: installer
364 mkdir -p $(INSTALLROOT)$(TFTPBOOT)
365 install -m 644 $(NETINSTALLABLE) $(INSTALLROOT)$(TFTPBOOT)
366 endif
368 extbootinstall: installer
369 mkdir -m 755 -p $(INSTALLROOT)$(EXTLINUXDIR)
370 install -m 644 $(EXTBOOTINSTALL) $(INSTALLROOT)$(EXTLINUXDIR)
372 install-all: install netinstall extbootinstall
374 local-tidy:
375 rm -f *.o *.elf *_bin.c stupid.* patch.offset
376 rm -f *.lsr *.lst *.map *.sec *.tmp
377 rm -f $(OBSOLETE)
379 tidy: local-tidy $(BESUBDIRS) $(IESUBDIRS) $(BSUBDIRS) $(ISUBDIRS)
381 local-clean:
382 rm -f $(ITARGET)
384 clean: local-tidy local-clean $(BESUBDIRS) $(IESUBDIRS) $(BSUBDIRS) $(ISUBDIRS)
386 local-dist:
387 find . \( -name '*~' -o -name '#*' -o -name core \
388 -o -name '.*.d' -o -name .depend \) -type f -print0 \
389 | xargs -0rt rm -f
391 dist: local-dist local-tidy $(BESUBDIRS) $(IESUBDIRS) $(BSUBDIRS) $(ISUBDIRS)
393 # Shortcut to build linux/syslinux using klibc
394 klibc:
395 $(MAKE) clean
396 $(MAKE) CC=klcc ITARGET= ISUBDIRS='linux extlinux' BSUBDIRS=
397 endif # ifeq ($(HAVE_FIRMWARE),)
399 endif # ifeq ($(topdir),)
401 local-spotless:
402 find . \( -name '*~' -o -name '#*' -o -name core \
403 -o -name '.*.d' -o -name .depend -o -name '*.so.*' \) \
404 -type f -print0 \
405 | xargs -0rt rm -f
407 spotless: local-spotless
408 rm -rf $(all_firmware)
411 # Common rules that are needed by every invocation of make.
413 $(OBJDIR)/version.mk: $(topdir)/version $(topdir)/version.pl
414 $(PERL) $(topdir)/version.pl $< $@ '< := @'