Home | History | Annotate | Download | only in syslinux
      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.
     11 ##
     12 ## -----------------------------------------------------------------------
     13 
     14 #
     15 # Main Makefile for SYSLINUX
     16 #
     17 
     18 all_firmware := bios efi32 efi64
     19 
     20 #
     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.
     23 #
     24 ifeq ($(topdir),)
     25 
     26 topdir = $(CURDIR)
     27 
     28 #
     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.
     32 #
     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.
     36 #
     37 ifeq ("$(origin O)", "command line")
     38 	OBJDIR := $(O)
     39 else
     40 	OBJDIR = $(topdir)
     41 endif
     42 
     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))
     48 
     49 #
     50 # These environment variables are exported to every invocation of
     51 # make,
     52 #
     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
     57 #
     58 # There are also a handful of variables that are passed to each
     59 # sub-make,
     60 #
     61 # SRC - source tree location of the module being compiled
     62 # OBJ - output tree location of the module being compiled
     63 #
     64 # A couple of rules for writing Makefiles,
     65 #
     66 # - Do not use relative paths, use the above variables
     67 # - You can write $(SRC) a lot less if you add it to VPATH
     68 #
     69 
     70 MAKEDIR = $(topdir)/mk
     71 export MAKEDIR topdir OBJDIR
     72 
     73 include $(MAKEDIR)/syslinux.mk
     74 -include $(OBJDIR)/version.mk
     75 
     76 private-targets = prerel unprerel official release burn isolinux.iso \
     77 		  preupload upload test unittest regression spotless
     78 
     79 ifeq ($(MAKECMDGOALS),)
     80 	MAKECMDGOALS += all
     81 endif
     82 
     83 #
     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.
     88 #
     89 firmware = $(all_firmware)
     90 real-target := $(filter-out $(firmware), $(MAKECMDGOALS))
     91 real-firmware := $(filter $(firmware), $(MAKECMDGOALS))
     92 
     93 ifeq ($(real-target),)
     94 	real-target = all
     95 endif
     96 
     97 ifeq ($(real-firmware),)
     98 	real-firmware = $(firmware)
     99 endif
    100 
    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)
    105 
    106 unittest:
    107 	printf "Executing unit tests\n"
    108 	$(MAKE) -C core/mem/tests all
    109 	$(MAKE) -C com32/lib/syslinux/tests all
    110 
    111 regression:
    112 	$(MAKE) -C tests SRC="$(topdir)/tests" OBJ="$(topdir)/tests" \
    113 		objdir=$(OBJDIR) \
    114 		-f $(topdir)/tests/Makefile all
    115 
    116 test: unittest regression
    117 
    118 # Hook to add private Makefile targets for the maintainer.
    119 -include $(topdir)/Makefile.private
    120 
    121 else # ifeq ($(topdir),)
    122 
    123 include $(MAKEDIR)/syslinux.mk
    124 
    125 # Hook to add private Makefile targets for the maintainer.
    126 -include $(topdir)/Makefile.private
    127 
    128 #
    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).
    132 #
    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.
    137 #
    138 
    139 ifndef EFI_BUILD
    140 MODULES = memdisk/memdisk \
    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 # FIXME: Prune other BIOS-centric modules
    148 MODULES = com32/menu/*.c32 com32/modules/*.c32 com32/mboot/*.c32 \
    149 	com32/hdt/*.c32 com32/rosh/*.c32 com32/gfxboot/*.c32 \
    150 	com32/sysdump/*.c32 com32/lua/src/*.c32 com32/chain/*.c32 \
    151 	com32/lib/*.c32 com32/libutil/*.c32 com32/gpllib/*.c32 \
    152 	com32/cmenu/libmenu/*.c32 com32/elflink/ldlinux/$(LDLINUX)
    153 endif
    154 
    155 # List of module objects that should be installed for all derivatives
    156 INSTALLABLE_MODULES = $(MODULES)
    157 
    158 # syslinux.exe is BTARGET so as to not require everyone to have the
    159 # mingw suite installed
    160 BTARGET  = version.gen version.h $(OBJDIR)/version.mk
    161 BOBJECTS = $(BTARGET) \
    162 	mbr/*.bin \
    163 	core/pxelinux.0 core/lpxelinux.0 \
    164 	core/isolinux.bin core/isolinux-debug.bin \
    165 	gpxe/gpxelinux.0 dos/syslinux.com \
    166 	win32/syslinux.exe win64/syslinux64.exe \
    167 	dosutil/*.com dosutil/*.sys \
    168 	$(MODULES)
    169 
    170 # BSUBDIRs build the on-target binary components.
    171 # ISUBDIRs build the installer (host) components.
    172 #
    173 # Note: libinstaller is both a BSUBDIR and an ISUBDIR.  It contains
    174 # files that depend only on the B phase, but may have to be regenerated
    175 # for "make installer".
    176 
    177 ifdef EFI_BUILD
    178 
    179 BSUBDIRS = codepage com32 lzo core mbr sample efi txt
    180 ISUBDIRS =
    181 
    182 INSTALLSUBDIRS = efi
    183 
    184 NETINSTALLABLE = efi/syslinux.efi $(INSTALLABLE_MODULES)
    185 
    186 else
    187 
    188 BSUBDIRS = codepage com32 lzo core memdisk mbr gpxe sample \
    189 	   diag libinstaller dos win32 win64 dosutil txt
    190 
    191 ITARGET  =
    192 IOBJECTS = $(ITARGET) \
    193 	utils/gethostip utils/isohybrid utils/mkdiskimage \
    194 	mtools/syslinux linux/syslinux extlinux/extlinux
    195 ISUBDIRS = libinstaller mtools linux extlinux utils
    196 
    197 # Things to install in /usr/bin
    198 INSTALL_BIN   =	mtools/syslinux
    199 # Things to install in /sbin
    200 INSTALL_SBIN  = extlinux/extlinux
    201 # Things to install in /usr/lib/syslinux
    202 INSTALL_AUX   =	core/pxelinux.0 gpxe/gpxelinux.0 gpxe/gpxelinuxk.0 \
    203 		core/isolinux.bin core/isolinux-debug.bin \
    204 		dos/syslinux.com core/lpxelinux.0 \
    205 		mbr/*.bin $(INSTALLABLE_MODULES)
    206 INSTALL_AUX_OPT = win32/syslinux.exe win64/syslinux64.exe
    207 INSTALL_DIAG  =	diag/mbr/handoff.bin \
    208 		diag/geodsp/geodsp1s.img.xz diag/geodsp/geodspms.img.xz
    209 
    210 # These directories manage their own installables
    211 INSTALLSUBDIRS = com32 utils dosutil
    212 
    213 # Things to install in /boot/extlinux
    214 EXTBOOTINSTALL = $(INSTALLABLE_MODULES)
    215 
    216 # Things to install in /tftpboot
    217 NETINSTALLABLE = core/pxelinux.0 gpxe/gpxelinux.0 core/lpxelinux.0 \
    218 		 $(INSTALLABLE_MODULES)
    219 
    220 endif # ifdef EFI_BUILD
    221 
    222 .PHONY: subdirs $(BSUBDIRS) $(ISUBDIRS) test
    223 
    224 ifeq ($(HAVE_FIRMWARE),)
    225 
    226 firmware = $(all_firmware)
    227 
    228 # If no firmware was specified the rest of MAKECMDGOALS applies to all
    229 # firmware.
    230 ifeq ($(filter $(firmware),$(MAKECMDGOALS)),)
    231 all strip tidy clean dist install installer netinstall: $(all_firmware)
    232 
    233 else
    234 
    235 # Don't do anything for the rest of MAKECMDGOALS at this level. It
    236 # will be handled for each of $(firmware).
    237 strip tidy clean dist install installer netinstall:
    238 
    239 endif
    240 
    241 # Convert 'make bios strip' to 'make strip', etc for rest of the Makefiles.
    242 MAKECMDGOALS := $(filter-out $(firmware),$(MAKECMDGOALS))
    243 ifeq ($(MAKECMDGOALS),)
    244 	MAKECMDGOALS += all
    245 endif
    246 
    247 #
    248 # You'd think that we'd be able to use the 'define' directive to
    249 # abstract the code for invoking make(1) in the output directory, but
    250 # by using 'define' we lose the ability to build in parallel.
    251 #
    252 .PHONY: $(firmware)
    253 bios:
    254 	@mkdir -p $(OBJ)/bios
    255 	$(MAKE) -C $(OBJ)/bios -f $(SRC)/Makefile SRC="$(SRC)" \
    256 		objdir=$(OBJ)/bios OBJ=$(OBJ)/bios HAVE_FIRMWARE=1 \
    257 		FIRMWARE=BIOS \
    258 		ARCH=i386 LDLINUX=ldlinux.c32 $(MAKECMDGOALS)
    259 
    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 		FIRMWARE=EFI32 \
    266 		$(MAKECMDGOALS)
    267 
    268 efi64:
    269 	@mkdir -p $(OBJ)/efi64
    270 	$(MAKE) -C $(OBJ)/efi64 -f $(SRC)/Makefile SRC="$(SRC)" \
    271 		objdir=$(OBJ)/efi64 OBJ=$(OBJ)/efi64 HAVE_FIRMWARE=1 \
    272 		ARCH=x86_64 BITS=64 EFI_BUILD=1 LDLINUX=ldlinux.e64 \
    273 		FIRMWARE=EFI64 \
    274 		$(MAKECMDGOALS)
    275 
    276 else # ifeq($(HAVE_FIRMWARE),)
    277 
    278 all: all-local subdirs
    279 
    280 all-local: $(BTARGET) $(ITARGET)
    281 	-ls -l $(BOBJECTS) $(IOBJECTS)
    282 subdirs: $(BSUBDIRS) $(ISUBDIRS)
    283 
    284 $(sort $(ISUBDIRS) $(BSUBDIRS)):
    285 	@mkdir -p $@
    286 	$(MAKE) -C $@ SRC="$(SRC)/$@" OBJ="$(OBJ)/$@" \
    287 		-f $(SRC)/$@/Makefile $(MAKECMDGOALS)
    288 
    289 $(ITARGET):
    290 	@mkdir -p $@
    291 	$(MAKE) -C $@ SRC="$(SRC)/$@" OBJ="$(OBJ)/$@" \
    292 		-f $(SRC)/$@/Makefile $(MAKECMDGOALS)
    293 
    294 $(BINFILES):
    295 	@mkdir -p $@
    296 	$(MAKE) -C $@ SRC="$(SRC)/$@" OBJ="$(OBJ)/$@" \
    297 		-f $(SRC)/$@/Makefile $(MAKECMDGOALS)
    298 
    299 #
    300 # List the dependencies to help out parallel builds.
    301 dos extlinux linux mtools win32 win64: libinstaller
    302 libinstaller: core
    303 utils: mbr
    304 core: com32
    305 efi: core
    306 gpxe: core
    307 
    308 installer: installer-local
    309 	set -e; for i in $(ISUBDIRS); \
    310 		do $(MAKE) -C $$i SRC="$(SRC)/$$i" OBJ="$(OBJ)/$$i" \
    311 		-f $(SRC)/$$i/Makefile all; done
    312 
    313 
    314 installer-local: $(ITARGET) $(BINFILES)
    315 
    316 strip: strip-local
    317 	set -e; for i in $(ISUBDIRS); \
    318 		do $(MAKE) -C $$i SRC="$(SRC)/$$i" OBJ="$(OBJ)/$$i" \
    319 		-f $(SRC)/$$i/Makefile strip; done
    320 	-ls -l $(BOBJECTS) $(IOBJECTS)
    321 
    322 strip-local:
    323 
    324 version.gen: $(topdir)/version $(topdir)/version.pl
    325 	$(PERL) $(topdir)/version.pl $< $@ '%define < @'
    326 version.h: $(topdir)/version $(topdir)/version.pl
    327 	$(PERL) $(topdir)/version.pl $< $@ '#define < @'
    328 
    329 local-install: installer
    330 	mkdir -m 755 -p $(INSTALLROOT)$(BINDIR)
    331 	install -m 755 -c $(INSTALL_BIN) $(INSTALLROOT)$(BINDIR)
    332 	mkdir -m 755 -p $(INSTALLROOT)$(SBINDIR)
    333 	install -m 755 -c $(INSTALL_SBIN) $(INSTALLROOT)$(SBINDIR)
    334 	mkdir -m 755 -p $(INSTALLROOT)$(AUXDIR)
    335 	install -m 644 -c $(INSTALL_AUX) $(INSTALLROOT)$(AUXDIR)
    336 	-install -m 644 -c $(INSTALL_AUX_OPT) $(INSTALLROOT)$(AUXDIR)
    337 	mkdir -m 755 -p $(INSTALLROOT)$(DIAGDIR)
    338 	install -m 644 -c $(INSTALL_DIAG) $(INSTALLROOT)$(DIAGDIR)
    339 	mkdir -m 755 -p $(INSTALLROOT)$(MANDIR)/man1
    340 	install -m 644 -c $(topdir)/man/*.1 $(INSTALLROOT)$(MANDIR)/man1
    341 	: mkdir -m 755 -p $(INSTALLROOT)$(MANDIR)/man8
    342 	: install -m 644 -c man/*.8 $(INSTALLROOT)$(MANDIR)/man8
    343 
    344 ifndef EFI_BUILD
    345 install: local-install
    346 	set -e ; for i in $(INSTALLSUBDIRS) ; \
    347 		do $(MAKE) -C $$i SRC="$(SRC)/$$i" OBJ="$(OBJ)/$$i" \
    348 		-f $(SRC)/$$i/Makefile $@; done
    349 else
    350 install:
    351 	mkdir -m 755 -p $(INSTALLROOT)$(AUXDIR)/efi$(BITS)
    352 	set -e ; for i in $(INSTALLSUBDIRS) ; \
    353 		do $(MAKE) -C $$i SRC="$(SRC)/$$i" OBJ="$(OBJ)/$$i" \
    354 		BITS="$(BITS)" AUXDIR="$(AUXDIR)/efi$(BITS)" \
    355 		-f $(SRC)/$$i/Makefile $@; done
    356 	-install -m 644 $(INSTALLABLE_MODULES) $(INSTALLROOT)$(AUXDIR)/efi$(BITS)
    357 	install -m 644 com32/elflink/ldlinux/$(LDLINUX) $(INSTALLROOT)$(AUXDIR)/efi$(BITS)
    358 endif
    359 
    360 ifdef EFI_BUILD
    361 netinstall:
    362 	mkdir -p $(INSTALLROOT)$(TFTPBOOT)/efi$(BITS)
    363 	install -m 644 $(NETINSTALLABLE) $(INSTALLROOT)$(TFTPBOOT)/efi$(BITS)
    364 else
    365 netinstall: installer
    366 	mkdir -p $(INSTALLROOT)$(TFTPBOOT)
    367 	install -m 644 $(NETINSTALLABLE) $(INSTALLROOT)$(TFTPBOOT)
    368 endif
    369 
    370 extbootinstall: installer
    371 	mkdir -m 755 -p $(INSTALLROOT)$(EXTLINUXDIR)
    372 	install -m 644 $(EXTBOOTINSTALL) $(INSTALLROOT)$(EXTLINUXDIR)
    373 
    374 install-all: install netinstall extbootinstall
    375 
    376 local-tidy:
    377 	rm -f *.o *.elf *_bin.c stupid.* patch.offset
    378 	rm -f *.lsr *.lst *.map *.sec *.tmp
    379 	rm -f $(OBSOLETE)
    380 
    381 tidy: local-tidy $(BESUBDIRS) $(IESUBDIRS) $(BSUBDIRS) $(ISUBDIRS)
    382 
    383 local-clean:
    384 	rm -f $(ITARGET)
    385 
    386 clean: local-tidy local-clean $(BESUBDIRS) $(IESUBDIRS) $(BSUBDIRS) $(ISUBDIRS)
    387 
    388 local-dist:
    389 	find . \( -name '*~' -o -name '#*' -o -name core \
    390 		-o -name '.*.d' -o -name .depend \) -type f -print0 \
    391 	| xargs -0rt rm -f
    392 
    393 dist: local-dist local-tidy $(BESUBDIRS) $(IESUBDIRS) $(BSUBDIRS) $(ISUBDIRS)
    394 
    395 # Shortcut to build linux/syslinux using klibc
    396 klibc:
    397 	$(MAKE) clean
    398 	$(MAKE) CC=klcc ITARGET= ISUBDIRS='linux extlinux' BSUBDIRS=
    399 endif # ifeq ($(HAVE_FIRMWARE),)
    400 
    401 endif # ifeq ($(topdir),)
    402 
    403 local-spotless:
    404 	find . \( -name '*~' -o -name '#*' -o -name core \
    405 		-o -name '.*.d' -o -name .depend -o -name '*.so.*' \) \
    406 		-type f -print0 \
    407 	| xargs -0rt rm -f
    408 
    409 spotless: local-spotless
    410 	rm -rf $(all_firmware)
    411 
    412 #
    413 # Common rules that are needed by every invocation of make.
    414 #
    415 $(OBJDIR)/version.mk: $(topdir)/version $(topdir)/version.pl
    416 	$(PERL) $(topdir)/version.pl $< $@ '< := @'
    417