2 # figure out a few things about the host build system
4 HOSTTYPE := $(shell uname -m)
7 OSTYPE := $(shell uname -s | awk -F_ '{print $$1}' | tr A-Z a-z)
9 ifeq ($(HOSTTYPE),i586)
12 ifeq ($(HOSTTYPE),i686)
18 ifeq ($(findstring Macintosh,$(HOSTTYPE)),Macintosh)
21 ifeq ($(HOSTTYPE),macintosh)
22 ifeq ($(MACHTYPE),powerpc)
27 # default platform and arch
30 # by default, build for a i386-pc
36 # some platforms only support one arch
37 ifeq ($(PLATFORM),pegasos)
40 ifeq ($(PLATFORM),mac)
43 ifeq ($(PLATFORM),xbox)
46 ifeq ($(PLATFORM),dreamcast)
50 # some arches only support one platform
58 # build the TARGET variable
59 TARGET := $(ARCH)-$(PLATFORM)
61 # HOST_* is for local targets (tools)
66 HOST_OBJCOPY := objcopy
67 HOST_OBJDUMP := objdump
71 # setup some local commands
74 ifeq ($(OSTYPE),SunOS)
78 ifeq ($(findstring solaris,$(OSTYPE)),solaris)
83 # TOOLCHAIN_ARCH is usually ARCH, except in a few cases
84 TOOLCHAIN_ARCH := $(ARCH)
89 # try to detect if the user has ARCH-newos-gcc installed
92 # the "| cat" below looks unnecesary, this is
93 # to avoid a bug in liberty in certain versions
96 FOO := $(shell $(TOOLCHAIN_ARCH)-newos-gcc --version | cat)
98 $(warning found newos toolchain!)
99 CC = $(TOOLCHAIN_ARCH)-newos-gcc
100 LD = $(TOOLCHAIN_ARCH)-newos-ld
101 AS = $(TOOLCHAIN_ARCH)-newos-as
102 AR = $(TOOLCHAIN_ARCH)-newos-ar
103 OBJCOPY = $(TOOLCHAIN_ARCH)-newos-objcopy
104 OBJDUMP = $(TOOLCHAIN_ARCH)-newos-objdump
105 STRIP = $(TOOLCHAIN_ARCH)-newos-strip
106 SIZE = $(TOOLCHAIN_ARCH)-newos-size
109 FOO := $(shell $(TOOLCHAIN_ARCH)-elf-gcc --version | cat)
111 $(warning WARNING: custom newos toolchain not found!)
112 $(warning falling back to elf toolchain)
113 CC = $(TOOLCHAIN_ARCH)-elf-gcc
114 LD = $(TOOLCHAIN_ARCH)-elf-ld
115 AS = $(TOOLCHAIN_ARCH)-elf-as
116 AR = $(TOOLCHAIN_ARCH)-elf-ar
117 OBJCOPY = $(TOOLCHAIN_ARCH)-elf-objcopy
118 OBJDUMP = $(TOOLCHAIN_ARCH)-elf-objdump
119 STRIP = $(TOOLCHAIN_ARCH)-elf-strip
120 SIZE = $(TOOLCHAIN_ARCH)-elf-size
123 $(warning WARNING: custom newos toolchain not found!)
124 $(warning This build will probably fail miserably)
125 $(warning Download the appropriate toolchain for your build environment)
126 $(warning at http://newos.sourceforge.net/download.php)
131 OBJCOPY = $(HOST_OBJCOPY)
132 OBJDUMP = $(HOST_OBJDUMP)
133 STRIP = $(HOST_STRIP)
137 # set up some particular options for various architectures
139 GLOBAL_CFLAGS = -O2 -g
140 KERNEL_CFLAGS = -fno-pic
145 ifeq ($(ARCH),x86_64)
146 GLOBAL_CFLAGS = -O2 -g
147 KERNEL_CFLAGS = -fpic
149 GLOBAL_LDFLAGS = -g -m elf_x86_64
153 GLOBAL_CFLAGS = -fno-pic -O -D__PPC__ -mregnames
163 GLOBAL_CFLAGS = -O2 -g
164 KERNEL_CFLAGS = -fno-pic
170 GLOBAL_CFLAGS = -ml -m4-single-only -mhitachi -O2 -g
171 KERNEL_CFLAGS = -fno-pic
176 ifeq ($(ARCH),sparc64)
187 GLOBAL_CFLAGS = -O0 -g -m68040
188 KERNEL_CFLAGS = -fno-pic
199 GLOBAL_CFLAGS = -fno-pic -mips4 -meb -G 0
203 # check to see if we should use distcc and/or ccache
204 ifneq ($(USE_DISTCC),)
205 $(warning using distcc)
209 ifneq ($(USE_CCACHE),)
210 $(warning using ccache)
214 # these options are on for all architectures
215 GLOBAL_CFLAGS += -finline -fno-builtin
216 GLOBAL_CFLAGS += -Wall -W -Wno-multichar -Wno-unused-parameter -Wmissing-prototypes
217 GLOBAL_CFLAGS += -DNEWOS=1
218 GLOBAL_CFLAGS += -DARCH_$(ARCH)=1 -D__ARCH__=$(ARCH) -U$(ARCH)
219 GLOBAL_CFLAGS += -DPLATFORM_$(PLATFORM)=1
221 GLOBAL_CPPFLAGS = $(GLOBAL_CFLAGS)
223 GLOBAL_ASFLAGS += -D__ASSEMBLY__
227 LIBGCC_PATH := $(dir $(shell $(CC) $(GLOBAL_CFLAGS) -print-libgcc-file-name))
229 LIBGCC_PATH := /usr/local/arm-newos/lib/gcc-lib/arm-newos/3.3.3
231 $(warning LIBGCC_PATH = $(LIBGCC_PATH))
233 LIBGCC_INCLUDE += -I$(LIBGCC_PATH)/include
238 $(warning ARCH = $(ARCH))
239 $(warning PLATFORM = $(PLATFORM))
240 $(warning TARGET = $(TARGET))
242 # figure out where the build dir will be
243 BUILD_DIR = build/$(TARGET)
244 $(warning build dir will be $(BUILD_DIR))
245 $(shell mkdir -p $(BUILD_DIR))