add new bits to the compiler.h file
[newos.git] / make.syscfg
blob65593691c488772fc918ae36d3597c1c191e86c0
2 # figure out a few things about the host build system
3 ifeq ($(HOSTTYPE),)
4         HOSTTYPE := $(shell uname -m)
5 endif
6 ifeq ($(OSTYPE),)
7         OSTYPE := $(shell uname -s | awk -F_ '{print $$1}' | tr A-Z a-z)
8 endif
9 ifeq ($(HOSTTYPE),i586)
10         HOSTTYPE := i386
11 endif
12 ifeq ($(HOSTTYPE),i686)
13         HOSTTYPE := i386
14 endif
15 ifeq ($(HOSTTYPE), )
16         HOSTTYPE := i386
17 endif
18 ifeq ($(findstring Macintosh,$(HOSTTYPE)),Macintosh)
19         HOSTTYPE := ppc
20 endif
21 ifeq ($(HOSTTYPE),macintosh)
22         ifeq ($(MACHTYPE),powerpc)
23                 HOSTTYPE := ppc
24         endif
25 endif
27 # default platform and arch
28 ifeq ($(PLATFORM),)
29         ifeq ($(ARCH),)
30                 #       by default, build for a i386-pc
31                 ARCH := i386
32                 PLATFORM := pc
33         endif
34 endif
36 # some platforms only support one arch
37 ifeq ($(PLATFORM),pegasos)
38 ARCH := ppc
39 endif
40 ifeq ($(PLATFORM),mac)
41 ARCH := ppc
42 endif
43 ifeq ($(PLATFORM),xbox)
44 ARCH := i386
45 endif
46 ifeq ($(PLATFORM),dreamcast)
47 ARCH := sh4
48 endif
50 # some arches only support one platform
51 ifeq ($(ARCH),x86_64)
52 PLATFORM := pc
53 endif
54 ifeq ($(ARCH),sh4)
55 PLATFORM := dreamcast
56 endif
58 # build the TARGET variable
59 TARGET := $(ARCH)-$(PLATFORM)
61 # HOST_* is for local targets (tools)
62 HOST_CC := gcc
63 HOST_LD := $(LD)
64 HOST_AS := $(AS)
65 HOST_AR := $(AR)
66 HOST_OBJCOPY := objcopy
67 HOST_OBJDUMP := objdump
68 HOST_STRIP := strip
69 HOST_SIZE := size
71 # setup some local commands
72 ECHO := echo
73 AWK := awk
74 ifeq ($(OSTYPE),SunOS)
75         ECHO := /usr/ucb/echo
76         AWK := gawk
77 endif
78 ifeq ($(findstring solaris,$(OSTYPE)),solaris)
79         ECHO := /usr/ucb/echo
80         AWK := gawk
81 endif
83 # TOOLCHAIN_ARCH is usually ARCH, except in a few cases
84 TOOLCHAIN_ARCH := $(ARCH)
85 ifeq ($(ARCH),sh4)
86 TOOLCHAIN_ARCH := sh
87 endif
89 # try to detect if the user has ARCH-newos-gcc installed
91 #  NOTE:
92 #       the "| cat" below looks unnecesary, this is
93 #       to avoid a bug in liberty in certain versions
94 #       of gmake for BeOS
95 CC :=
96 FOO := $(shell $(TOOLCHAIN_ARCH)-newos-gcc --version | cat)
97 ifneq ($(FOO),)
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
107 endif 
109 FOO := $(shell $(TOOLCHAIN_ARCH)-elf-gcc --version | cat)
110 ifneq ($(FOO),)
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
121 endif
122 ifeq ($(CC),)
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)
127         CC = $(HOST_CC)
128         LD = $(HOST_LD)
129         AS = $(HOST_AS)
130         AR = $(HOST_AR)
131         OBJCOPY = $(HOST_OBJCOPY)
132         OBJDUMP = $(HOST_OBJDUMP)
133         STRIP = $(HOST_STRIP)
134         SIZE = $(HOST_SIZE)
135 endif
137 # set up some particular options for various architectures
138 ifeq ($(ARCH),i386)
139         GLOBAL_CFLAGS = -O2 -g
140         KERNEL_CFLAGS = -fno-pic
141         USER_CFLAGS = -fpic
142         GLOBAL_LDFLAGS = -g
143 endif
145 ifeq ($(ARCH),x86_64)
146         GLOBAL_CFLAGS = -O2 -g 
147         KERNEL_CFLAGS = -fno-pic -mcmodel=kernel
148         USER_CFLAGS = -fpic
149         GLOBAL_LDFLAGS = -g -m elf_x86_64
150 endif
152 ifeq ($(ARCH),ppc)
153         GLOBAL_CFLAGS = -fno-pic -O -D__PPC__ -mregnames
154         GLOBAL_LDFLAGS =
155 endif
157 ifeq ($(ARCH),ppc64)
158         GLOBAL_CFLAGS =
159         GLOBAL_LDFLAGS =
160 endif
162 ifeq ($(ARCH),arm)
163         GLOBAL_CFLAGS = -O2 -g
164         KERNEL_CFLAGS = -fno-pic
165         USER_CFLAGS = -fpic
166         GLOBAL_LDFLAGS =
167 endif
169 ifeq ($(ARCH),sh4)
170         GLOBAL_CFLAGS = -ml -m4-single-only -mhitachi -O2 -g -D__SH4__
171         KERNEL_CFLAGS = -fno-pic
172         USER_CFLAGS = -fpic
173         GLOBAL_LDFLAGS = -EL
174 endif
176 ifeq ($(ARCH),sparc64)
177         GLOBAL_CFLAGS =
178         GLOBAL_LDFLAGS =
179 endif
181 ifeq ($(ARCH),sparc)
182         GLOBAL_CFLAGS =
183         GLOBAL_LDFLAGS =
184 endif
186 ifeq ($(ARCH),m68k)
187         GLOBAL_CFLAGS = -O0 -g -m68040
188         KERNEL_CFLAGS = -fno-pic
189         USER_CFLAGS = -fpic
190         GLOBAL_LDFLAGS = -g
191 endif
193 ifeq ($(ARCH),alpha)
194         GLOBAL_CFLAGS =
195         GLOBAL_LDFLAGS =
196 endif
198 ifeq ($(ARCH),mips)
199         GLOBAL_CFLAGS = -fno-pic -mips4 -meb -G 0
200         GLOBAL_LDFLAGS =
201 endif
203 # check to see if we should use distcc and/or ccache
204 ifneq ($(USE_DISTCC),)
205 $(warning using distcc)
206         CC := distcc $(CC)
207 endif
209 ifneq ($(USE_CCACHE),)
210 $(warning using ccache)
211         CC := ccache $(CC)
212 endif
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__
225 # find libgcc
226 LIBGCC := -lgcc
227 LIBGCC_PATH := $(dir $(shell $(CC) $(GLOBAL_CFLAGS) -print-libgcc-file-name))
228 ifeq ($(ARCH),arm)
229 LIBGCC_PATH := /usr/local/arm-newos/lib/gcc-lib/arm-newos/3.3.3
230 endif
231 $(warning LIBGCC_PATH = $(LIBGCC_PATH))
232 ifneq ($(ARCH),sh4)
233 LIBGCC_INCLUDE += -I$(LIBGCC_PATH)/include
234 endif
235 ifeq ($(ARCH),x86_64)
236 LIBGCC32_PATH := $(dir $(shell $(CC) $(GLOBAL_CFLAGS) -m32 -print-libgcc-file-name))
237 $(warning LIBGCC32_PATH = $(LIBGCC32_PATH))
238 endif
241 # print some info
242 $(warning ARCH = $(ARCH))
243 $(warning PLATFORM = $(PLATFORM))
244 $(warning TARGET = $(TARGET))
246 # figure out where the build dir will be
247 BUILD_DIR = build/$(TARGET)
248 $(warning build dir will be $(BUILD_DIR))
249 $(shell mkdir -p $(BUILD_DIR))