aboutsummaryrefslogtreecommitdiff
path: root/Android.mk
blob: 3f57042374b54cbef5f97dd3a6fc739e6ae8931e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
## Copyright 2008, The Android Open Source Project
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##     http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##


LOCAL_PATH := $(call my-dir)

ifeq ($(TARGET_ARCH),x86)

include $(CLEAR_VARS)

############################
# First, build stage1

LOCAL_SRC_FILES := \
        stage1/stage1.S

LOCAL_CFLAGS := \
        -Wall -Wmissing-prototypes -Wunused -Wshadow \
        -Wpointer-arith -falign-jumps=1 -falign-loops=1 \
        -falign-functions=1 -Wundef
LOCAL_CFLAGS += -m32 -O2 -fno-builtin -nostdinc

LOCAL_C_INCLUDES := $(LOCAL_PATH)/stage1

LOCAL_MODULE := grub_stage1
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/grub

LOCAL_SYSTEM_SHARED_LIBRARIES :=
LOCAL_SHARED_LIBRARIES :=

include $(BUILD_RAW_EXECUTABLE)

$(LOCAL_BUILT_MODULE) : PRIVATE_LINK_SCRIPT :=
$(LOCAL_BUILT_MODULE) : PRIVATE_LIBS :=
$(LOCAL_BUILT_MODULE) : PRIVATE_RAW_EXECUTABLE_LDFLAGS := \
	-nostdlib -N -Ttext=0x7C00 -melf_i386

###################################################################
###################################################################
## For stage2, we have to do it in several parts.
##   1) Build pre_stage2 that contains all the source.
##   2) Get the size of pre_stage2 from (1) and generate a header file.
##   3) Build the "start sector" with the header file.
##   4) concatenate start + pre_stage2 into stage2.
###################################################################
###################################################################

###################################
## So, build pre_stage2 target  (1)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
	stage2/asm.S \
	stage2/bios.c \
	stage2/boot.c \
	stage2/builtins.c \
	stage2/char_io.c \
	stage2/cmdline.c \
	stage2/common.c \
	stage2/console.c \
	stage2/disk_io.c \
	stage2/fsys_ext2fs.c \
	stage2/gunzip.c \
	stage2/serial.c \
	stage2/smp-imps.c \
	stage2/stage2.c \
	stage2/terminfo.c \
	stage2/tparm.c \
	stage2/preset_menu.c

LOCAL_CFLAGS := \
	-Wall -Wmissing-prototypes -Wunused -Wshadow \
	-Wpointer-arith -falign-jumps=1 -falign-loops=1 \
	-falign-functions=1 -Wundef

LOCAL_CFLAGS += -m32 -Os -fno-builtin -nostdinc

LOCAL_CFLAGS += -DHAVE_CONFIG_H -DFSYS_EXT2FS=1 -DSUPPORT_SERIAL=1

LOCAL_CFLAGS += -DPRESET_MENU_EXTERNAL

LOCAL_C_INCLUDES := \
	$(LOCAL_PATH)/stage1 \
	$(LOCAL_PATH)/stage2

LOCAL_MODULE := grub_pre_stage2
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/grub

LOCAL_SYSTEM_SHARED_LIBRARIES :=
LOCAL_SHARED_LIBRARIES :=

include $(BUILD_RAW_EXECUTABLE)

$(LOCAL_BUILT_MODULE) : PRIVATE_LINK_SCRIPT :=
$(LOCAL_BUILT_MODULE) : PRIVATE_LIBS :=
$(LOCAL_BUILT_MODULE) : PRIVATE_RAW_EXECUTABLE_LDFLAGS := \
	-nostdlib -N -Ttext=0x8200 -melf_i386

#############################################
## Generate the stage2 start file  (2) + (3)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
	stage2/start.S

LOCAL_CFLAGS := \
	-Wall -Wmissing-prototypes -Wunused -Wshadow \
	-Wpointer-arith -falign-jumps=1 -falign-loops=1 \
	-falign-functions=1 -Wundef

LOCAL_CFLAGS += -m32 -Os -fno-builtin -nostdinc

LOCAL_CFLAGS += -DHAVE_CONFIG_H -DFSYS_EXT2FS=1 -DSUPPORT_SERIAL=1

LOCAL_C_INCLUDES := \
	$(LOCAL_PATH)/stage1 \
	$(LOCAL_PATH)/stage2

LOCAL_SYSTEM_SHARED_LIBRARIES :=
LOCAL_SHARED_LIBRARIES :=

LOCAL_MODULE := grub_start_stage2
LOCAL_MODULE_TAGS := eng
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/grub

# <generate the header file>
LOCAL_MODULE_CLASS := EXECUTABLES
intermediates := $(call local-intermediates-dir)

STAGE2_SIZE_OBJ := $(intermediates)/stage2_size.h
$(STAGE2_SIZE_OBJ) : PRIVATE_CUSTOM_TOOL = \
	echo "\#define STAGE2_SIZE `stat -c '%s' $<`" > $@

LOCAL_GENERATED_SOURCES := $(STAGE2_SIZE_OBJ)
$(STAGE2_SIZE_OBJ): $(PRODUCT_OUT)/grub/grub_pre_stage2
	@echo "target Generating: $@" 
	$(transform-generated-source)
# </generate the header file>

include $(BUILD_RAW_EXECUTABLE)

$(all_objects): $(STAGE2_SIZE_OBJ)
$(LOCAL_BUILT_MODULE) : PRIVATE_LINK_SCRIPT :=
$(LOCAL_BUILT_MODULE) : PRIVATE_LIBS :=
$(LOCAL_BUILT_MODULE) : PRIVATE_RAW_EXECUTABLE_LDFLAGS := \
	-nostdlib -N -Ttext=0x8200 -melf_i386

#############################################
## Generate the real deal stage2  (4)

include $(CLEAR_VARS)

my_files := $(PRODUCT_OUT)/grub/grub_start_stage2 \
	$(PRODUCT_OUT)/grub/grub_pre_stage2

file := $(PRODUCT_OUT)/grub/grub_stage2
$(file) : $(my_files) 
	@echo "target Creating: $@"
	$(hide) cat $^ > $@
#ALL_PREBUILT += $(file)


#############################################################################
## Generate a full stage1+stage2 bin that we can just drop @ offset 0 on disk
include $(CLEAR_VARS)
grub_stage1 := $(PRODUCT_OUT)/grub/grub_stage1
grub_stage2 := $(PRODUCT_OUT)/grub/grub_stage2
grub_full := $(PRODUCT_OUT)/grub/grub.bin

$(grub_full) : $(grub_stage1) $(grub_stage2)
	@echo "target Generating GRUB bin: $@"
	$(hide) rm -f $@
	$(hide) dd if=$(grub_stage1) of=$@ bs=512 count=1 2>/dev/null
	$(hide) dd if=$(grub_stage2) of=$@ bs=512 seek=1 2>/dev/null
#ALL_PREBUILT += $(grub_full)

endif # x86