1## -*- makefile -*- ------------------------------------------------------- 2## 3## Copyright 2008 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., 51 Franklin St, Fifth Floor, 8## Boston MA 02110-1301, USA; either version 2 of the License, or 9## (at your option) any later version; incorporated herein by reference. 10## 11## ----------------------------------------------------------------------- 12 13## 14## ELF common configurables 15## 16 17include $(MAKEDIR)/syslinux.mk 18 19# Support IA32 and x86_64 platforms with one build 20# Set up architecture specifics; for cross compilation, set ARCH as apt 21GCCOPT := $(call gcc_ok,-std=gnu99,) 22ifeq ($(ARCH),i386) 23 GCCOPT += $(call gcc_ok,-m32,) 24 GCCOPT += $(call gcc_ok,-march=i386) 25 GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=2,) 26endif 27ifeq ($(ARCH),x86_64) 28 GCCOPT += $(call gcc_ok,-m64,) 29 GCCOPT += $(call gcc_ok,-march=x86-64) 30 #let preferred-stack-boundary be default (=4) 31endif 32GCCOPT += -Os -fomit-frame-pointer 33GCCOPT += $(call gcc_ok,-fno-stack-protector,) 34GCCOPT += $(call gcc_ok,-fwrapv,) 35GCCOPT += $(call gcc_ok,-freg-struct-return,) 36GCCOPT += $(call gcc_ok,-fno-exceptions,) 37GCCOPT += $(call gcc_ok,-fno-asynchronous-unwind-tables,) 38# Note -fPIE does not work with ld on x86_64, try -fPIC instead 39# Does BIOS build depend on -fPIE? 40GCCOPT += $(call gcc_ok,-fPIC) 41GCCOPT += $(call gcc_ok,-falign-functions=0,-malign-functions=0) 42GCCOPT += $(call gcc_ok,-falign-jumps=0,-malign-jumps=0) 43GCCOPT += $(call gcc_ok,-falign-labels=0,-malign-labels=0) 44GCCOPT += $(call gcc_ok,-falign-loops=0,-malign-loops=0) 45 46com32 = $(topdir)/com32 47core = $(topdir)/core 48 49ifneq ($(NOGPL),1) 50GPLLIB = $(objdir)/com32/gpllib/libgpl.c32 51GPLINCLUDE = -I$(com32)/gplinclude 52else 53GPLLIB = 54GPLINCLUDE = 55endif 56 57CFLAGS = $(GCCOPT) $(GCCWARN) -W -Wall \ 58 -fomit-frame-pointer -D__COM32__ -D__FIRMWARE_$(FIRMWARE)__ -DDYNAMIC_MODULE \ 59 -nostdinc -iwithprefix include \ 60 -I$(com32)/libutil/include -I$(com32)/include \ 61 -I$(com32)/include/sys $(GPLINCLUDE) -I$(core)/include \ 62 -I$(objdir) -DLDLINUX=\"$(LDLINUX)\" 63ifndef EFI_BUILD 64CFLAGS += -mregparm=3 -DREGPARM=3 65endif 66 67SFLAGS = $(GCCOPT) -D__COM32__ -D__FIRMWARE_$(FIRMWARE)__ 68LDFLAGS = -m elf_$(ARCH) -shared --hash-style=gnu -T $(com32)/lib/$(ARCH)/elf.ld --as-needed 69LIBGCC := $(shell $(CC) $(GCCOPT) --print-libgcc) 70 71LNXCFLAGS = -I$(com32)/libutil/include -W -Wall -O -g -D_GNU_SOURCE 72LNXSFLAGS = -g 73LNXLDFLAGS = -g 74 75C_LIBS += $(objdir)/com32/libutil/libutil.c32 $(GPLLIB) \ 76 $(objdir)/com32/lib/libcom32.c32 77C_LNXLIBS = $(objdir)/com32/libutil/libutil_lnx.a \ 78 $(objdir)/com32/elflink/ldlinux/ldlinux_lnx.a 79 80.SUFFIXES: .lss .c .o 81 82.PRECIOUS: %.o 83%.o: %.S 84 $(CC) $(SFLAGS) -c -o $@ $< 85 86.PRECIOUS: %.o 87%.o: %.c 88 $(CC) $(CFLAGS) -c -o $@ $< 89 90.PRECIOUS: %.lo 91%.lo: %.S 92 $(CC) $(LNXSFLAGS) -c -o $@ $< 93 94.PRECIOUS: %.lo 95%.lo: %.c 96 $(CC) $(LNXCFLAGS) -c -o $@ $< 97 98.PRECIOUS: %.lnx 99%.lnx: %.lo $(LNXLIBS) $(C_LNXLIBS) 100 $(CC) $(LNXCFLAGS) -o $@ $^ 101 102.PRECIOUS: %.elf 103%.elf: %.o $(C_LIBS) 104 $(LD) $(LDFLAGS) -o $@ $^ 105 106%.c32: %.elf 107 $(OBJCOPY) --strip-debug --strip-unneeded $< $@ 108