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