fc607cedbd40064243df4834f241b20b579ec635
[debian/elilo] / debian / patches / cross-build.diff
1 diff --git a/Make.defaults b/Make.defaults
2 index e541ea8..7812807 100644
3 --- a/Make.defaults
4 +++ b/Make.defaults
5 @@ -62,13 +62,15 @@ EFICRT0        = /usr/lib
6  CDIR    := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
7  TOPDIR  =
8  
9 -ARCH      = $(shell uname -m | sed s,i[3456789]86,ia32,)
10 +HOSTARCH   = $(shell dpkg-architecture -qDEB_BUILD_ARCH | sed s,i[3456789]86,ia32, | sed s,amd64,x86_64, )
11 +ARCH      := $(shell dpkg-architecture -qDEB_BUILD_ARCH | sed s,i[3456789]86,ia32, | sed s,amd64,x86_64, )
12  INCDIR    = -I. -I$(TOPDIR) -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol -I$(TOPDIR)/efi110
13  CPPFLAGS   = -DCONFIG_$(ARCH) 
14  
15  OPTIMFLAGS = -O2 
16  DEBUGFLAGS = -Wall
17 -CFLAGS     = $(OPTIMFLAGS) -fno-stack-protector -fno-strict-aliasing -fpic -fshort-wchar $(DEBUGFLAGS)
18 +CFLAGS     = $(ARCH3264) $(OPTIMFLAGS) -fpic -fshort-wchar $(DEBUGFLAGS)
19 +ASFLAGS    = $(ARCH3264)
20  LDFLAGS           = -nostdlib -znocombreloc
21  INSTALL           = install
22  
23 @@ -108,10 +110,30 @@ OBJCOPY           = $(prefix)objcopy
24  
25  # Use Modified binutils that supports x86_64 using UEFI ABI
26  ifeq ($(ARCH), x86_64)
27 +  ifeq ($(HOSTARCH), ia32)
28 +       ARCH3264 = -m64
29 +       LD3264 = -melf_x86_64
30 +
31 +       GNUEFILIB := $(GNUEFILIB)64
32 +       EFILIB    := $(EFILIB)64
33 +       EFICRT0   := $(EFICRT0)64
34 +  endif
35 +
36          CFLAGS   += -DEFI_FUNCTION_WRAPPER
37         OBJCOPY   = /usr/bin/objcopy
38  endif
39  
40 +ifeq ($(ARCH), ia32)
41 +  ifeq ($(HOSTARCH), x86_64)
42 +       ARCH3264 = -m32
43 +       LD3264 = -melf_i386
44 +
45 +       GNUEFILIB := /usr/lib32
46 +       EFILIB    := /usr/lib32
47 +       EFICRT0   := /usr/lib32
48 +  endif
49 +endif
50 +
51  ifeq ($(ARCH),ia64)
52   GCC_VERSION=$(shell $(CROSS_COMPILE)$(CC) -v 2>&1 | fgrep 'gcc version' | cut -f3 -d' ' | cut -f1 -d'.')
53  
54 diff --git a/Makefile b/Makefile
55 index f0efebd..9d82cbf 100644
56 --- a/Makefile
57 +++ b/Makefile
58 @@ -25,15 +25,19 @@
59  # to use this program.
60  #
61  
62 -include Make.defaults
63 -TOPDIR=.
64 +SRCDIR = .
65 +
66 +VPATH = $(SRCDIR)
67 +
68 +include $(SRCDIR)/Make.defaults
69 +TOPDIR = $(SRCDIR)
70  
71  
72  CRTOBJS       = $(EFICRT0)/crt0-efi-$(ARCH).o
73  LDSCRIPT      = $(EFICRT0)/elf_$(ARCH)_efi.lds
74  
75  LDFLAGS             += -T $(LDSCRIPT) -shared -Bsymbolic -L$(EFILIB) -L$(GNUEFILIB) $(CRTOBJS)
76 -LOADLIBES     = -lefi -lgnuefi $(shell $(CC) -print-libgcc-file-name)
77 +LOADLIBES     = -lefi -lgnuefi $(shell $(CC) $(ARCH3264) -print-libgcc-file-name)
78  FORMAT        = efi-app-$(ARCH)
79  
80  FILESYSTEM    =
81 @@ -87,7 +91,8 @@ fileops.o : Make.defaults
82  chooser.o : Make.defaults
83  
84  $(SUBDIRS): dummy
85 -       $(MAKE) -C $@
86 +       mkdir -p $@
87 +       $(MAKE) -C $@ -f $(SRCDIR)/../$@/Makefile SRCDIR=$(SRCDIR)/../$@ ARCH=$(ARCH)
88  
89  dummy:
90  
91 @@ -106,4 +111,4 @@ ifeq ($(GCC_VERSION),2)
92         @exit 1
93  endif
94  
95 -include Make.rules
96 +include $(SRCDIR)/Make.rules
97 diff --git a/choosers/Makefile b/choosers/Makefile
98 index 9915f48..85d31c7 100644
99 --- a/choosers/Makefile
100 +++ b/choosers/Makefile
101 @@ -23,10 +23,15 @@
102  # to use this program.
103  #
104  
105 -include ../Make.defaults
106 -include ../Make.rules
107 +SRCDIR = .
108 +
109 +VPATH = $(SRCDIR)
110 +
111 +include $(SRCDIR)/../Make.defaults
112 +include $(SRCDIR)/../Make.rules
113 +
114 +TOPDIR=$(SRCDIR)/..
115  
116 -TOPDIR=$(CDIR)/..
117  
118  FILES=
119  
120 @@ -47,7 +52,8 @@ $(TARGET): $(TOPDIR)/Make.defaults $(FILES)
121                 echo "You need to define at least one chooser in Make.defaults"; \
122                 exit 1; \
123         fi
124 -       $(LD) -o $@ -r $(FILES)
125 +       $(LD) $(LD3264) -o $@ -r $(FILES)
126 +
127  
128  clean:
129         $(RM) -f $(TARGET) $(FILES)
130 diff --git a/devschemes/Makefile b/devschemes/Makefile
131 index 6ac05af..5328cb1 100644
132 --- a/devschemes/Makefile
133 +++ b/devschemes/Makefile
134 @@ -23,10 +23,15 @@
135  # to use this program.
136  #
137  
138 -include ../Make.defaults
139 -include ../Make.rules
140 +SRCDIR = .
141 +
142 +VPATH = $(SRCDIR)
143 +
144 +include $(SRCDIR)/../Make.defaults
145 +include $(SRCDIR)/../Make.rules
146 +
147 +TOPDIR=$(SRCDIR)/..
148  
149 -TOPDIR=$(CDIR)/..
150  
151  FILES=simple.o
152  
153 @@ -40,7 +45,7 @@ all: $(TARGET)
154  #      without doing make clean.
155  #
156  $(TARGET): $(FILES)
157 -       $(LD) -r -o $@ $(FILES)
158 +       $(LD) $(LD3264) -r -o $@ $(FILES)
159  
160  clean:
161         $(RM) -f $(TARGET) $(FILES)
162 diff --git a/fs/Makefile b/fs/Makefile
163 index 8e422b2..0bb303f 100644
164 --- a/fs/Makefile
165 +++ b/fs/Makefile
166 @@ -23,10 +23,15 @@
167  # to use this program.
168  #
169  
170 -include ../Make.defaults
171 -include ../Make.rules
172 +SRCDIR = .
173 +
174 +VPATH = $(SRCDIR)
175 +
176 +include $(SRCDIR)/../Make.defaults
177 +include $(SRCDIR)/../Make.rules
178 +
179 +TOPDIR=$(SRCDIR)/..
180  
181 -TOPDIR=$(CDIR)/..
182  
183  FILES=
184  ifeq ($(CONFIG_localfs),y)
185 @@ -59,7 +64,7 @@ $(TARGET): $(TOPDIR)/Make.defaults $(FILES)
186                 echo "You need to define at least one filesystem in Make.defaults"; \
187                 exit 1; \
188         fi
189 -       $(LD) -r -o $@ $(FILES)
190 +       $(LD) $(LD3264) -r -o $@ $(FILES)
191  
192  clean:
193         $(RM) -f $(TARGET) $(FILES)
194 diff --git a/ia32/Makefile b/ia32/Makefile
195 index 353ae67..c5f421b 100644
196 --- a/ia32/Makefile
197 +++ b/ia32/Makefile
198 @@ -23,10 +23,15 @@
199  # to use this program.
200  #
201  
202 -include ../Make.defaults
203 -include ../Make.rules
204 +SRCDIR = .
205 +
206 +VPATH = $(SRCDIR)
207 +
208 +include $(SRCDIR)/../Make.defaults
209 +include $(SRCDIR)/../Make.rules
210 +
211 +TOPDIR=$(SRCDIR)/..
212  
213 -TOPDIR=$(CDIR)/..
214  
215  FILES=system.o config.o bzimage.o plain_loader.o gzip_loader.o gzip.o
216  
217 @@ -37,13 +42,13 @@ all: $(TARGET)
218  system.o: rmswitch.h
219  
220  rmswitch.h: bin_to_h.c rmswitch.S
221 -       $(CC) -o bin_to_h bin_to_h.c
222 -       $(AS) -o rmswitch.o rmswitch.S
223 +       $(CC) -o bin_to_h $(SRCDIR)/bin_to_h.c
224 +       $(AS) -o rmswitch.o $(SRCDIR)/rmswitch.S
225         $(LD) -Ttext 0x0 -s --oformat binary -o rmswitch rmswitch.o
226         ./bin_to_h <rmswitch >rmswitch.h
227  
228  $(TARGET): $(FILES)
229 -       $(LD) -r -o $@ $(FILES)
230 +       $(LD) $(LD3264) -r -o $@ $(FILES)
231  
232  clean:
233         $(RM) -f $(TARGET) $(FILES)
234 diff --git a/ia64/Makefile b/ia64/Makefile
235 index a243d0f..bee0a2b 100644
236 --- a/ia64/Makefile
237 +++ b/ia64/Makefile
238 @@ -23,10 +23,15 @@
239  # to use this program.
240  #
241  
242 -include ../Make.defaults
243 -include ../Make.rules
244 +SRCDIR = .
245 +
246 +VPATH = $(SRCDIR)
247 +
248 +include $(SRCDIR)/../Make.defaults
249 +include $(SRCDIR)/../Make.rules
250 +
251 +TOPDIR=$(SRCDIR)/..
252  
253 -TOPDIR=$(CDIR)/..
254  
255  FILES=system.o config.o fpswa.o plain_loader.o gzip_loader.o \
256        gzip.o memset.o memcpy.o setjmp.o longjmp.o
257 diff --git a/tools/Makefile b/tools/Makefile
258 index 8858224..97083d7 100644
259 --- a/tools/Makefile
260 +++ b/tools/Makefile
261 @@ -23,10 +23,15 @@
262  # to use this program.
263  #
264  
265 -include ../Make.defaults
266 -include ../Make.rules
267 +SRCDIR = .
268 +
269 +VPATH = $(SRCDIR)
270 +
271 +include $(SRCDIR)/../Make.defaults
272 +include $(SRCDIR)/../Make.rules
273 +
274 +TOPDIR=$(SRCDIR)/..
275  
276 -TOPDIR=$(CDIR)/..
277  
278  FILES=eliloalt.o
279  TARGET=eliloalt
280 diff --git a/x86_64/Makefile b/x86_64/Makefile
281 index 4af4b8d..7ade312 100644
282 --- a/x86_64/Makefile
283 +++ b/x86_64/Makefile
284 @@ -23,10 +23,15 @@
285  # to use this program.
286  #
287  
288 -include ../Make.defaults
289 -include ../Make.rules
290 +SRCDIR = .
291 +
292 +VPATH = $(SRCDIR)
293 +
294 +include $(SRCDIR)/../Make.defaults
295 +include $(SRCDIR)/../Make.rules
296 +
297 +TOPDIR=$(SRCDIR)/..
298  
299 -TOPDIR=$(CDIR)/..
300  
301  FILES=system.o config.o bzimage.o plain_loader.o gzip_loader.o gzip.o
302  #FILES=system.o config.o plain_loader.o
303 @@ -38,13 +43,13 @@ all: $(TARGET)
304  system.o: rmswitch.h
305  
306  rmswitch.h: bin_to_h.c rmswitch.S
307 -       $(CC) -o bin_to_h bin_to_h.c
308 -       $(AS) -o rmswitch.o rmswitch.S
309 +       $(CC) -o bin_to_h $(SRCDIR)/bin_to_h.c
310 +       $(AS) -o rmswitch.o $(SRCDIR)/rmswitch.S
311         $(LD) -Ttext 0x0 -s --oformat binary -o rmswitch rmswitch.o
312         ./bin_to_h <rmswitch >rmswitch.h
313  
314  $(TARGET): $(FILES)
315 -       $(LD) -r -o $@ $(FILES)
316 +       $(LD) $(LD3264) -r -o $@ $(FILES)
317  
318  clean:
319         $(RM) -f $(TARGET) $(FILES)