[e16e8f2] | 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 | |
---|
| 17 | include $(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 |
---|
| 21 | GCCOPT := $(call gcc_ok,-std=gnu99,) |
---|
| 22 | ifeq ($(ARCH),i386) |
---|
| 23 | GCCOPT += $(call gcc_ok,-m32,) |
---|
| 24 | GCCOPT += $(call gcc_ok,-march=i386) |
---|
| 25 | GCCOPT += $(call gcc_ok,-mpreferred-stack-boundary=2,) |
---|
| 26 | endif |
---|
| 27 | ifeq ($(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) |
---|
| 31 | endif |
---|
| 32 | GCCOPT += -Os -fomit-frame-pointer |
---|
| 33 | GCCOPT += $(call gcc_ok,-fno-stack-protector,) |
---|
| 34 | GCCOPT += $(call gcc_ok,-fwrapv,) |
---|
| 35 | GCCOPT += $(call gcc_ok,-freg-struct-return,) |
---|
| 36 | GCCOPT += $(call gcc_ok,-fno-exceptions,) |
---|
| 37 | GCCOPT += $(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? |
---|
| 40 | GCCOPT += $(call gcc_ok,-fPIC) |
---|
| 41 | GCCOPT += $(call gcc_ok,-falign-functions=0,-malign-functions=0) |
---|
| 42 | GCCOPT += $(call gcc_ok,-falign-jumps=0,-malign-jumps=0) |
---|
| 43 | GCCOPT += $(call gcc_ok,-falign-labels=0,-malign-labels=0) |
---|
| 44 | GCCOPT += $(call gcc_ok,-falign-loops=0,-malign-loops=0) |
---|
| 45 | |
---|
| 46 | com32 = $(topdir)/com32 |
---|
| 47 | core = $(topdir)/core |
---|
| 48 | |
---|
| 49 | ifneq ($(NOGPL),1) |
---|
| 50 | GPLLIB = $(objdir)/com32/gpllib/libgpl.c32 |
---|
| 51 | GPLINCLUDE = -I$(com32)/gplinclude |
---|
| 52 | else |
---|
| 53 | GPLLIB = |
---|
| 54 | GPLINCLUDE = |
---|
| 55 | endif |
---|
| 56 | |
---|
| 57 | CFLAGS = $(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)\" |
---|
| 63 | ifndef EFI_BUILD |
---|
| 64 | CFLAGS += -mregparm=3 -DREGPARM=3 |
---|
| 65 | endif |
---|
| 66 | |
---|
| 67 | SFLAGS = $(GCCOPT) -D__COM32__ -D__FIRMWARE_$(FIRMWARE)__ |
---|
| 68 | LDFLAGS = -m elf_$(ARCH) -shared --hash-style=gnu -T $(com32)/lib/$(ARCH)/elf.ld --as-needed |
---|
| 69 | LIBGCC := $(shell $(CC) $(GCCOPT) --print-libgcc) |
---|
| 70 | |
---|
| 71 | LNXCFLAGS = -I$(com32)/libutil/include -W -Wall -O -g -D_GNU_SOURCE |
---|
| 72 | LNXSFLAGS = -g |
---|
| 73 | LNXLDFLAGS = -g |
---|
| 74 | |
---|
| 75 | C_LIBS += $(objdir)/com32/libutil/libutil.c32 $(GPLLIB) \ |
---|
| 76 | $(objdir)/com32/lib/libcom32.c32 |
---|
| 77 | C_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 $< $@ |
---|