1 # Copyright (c) 2001, 2002 Eliot Dresselhaus
3 # Permission is hereby granted, free of charge, to any person obtaining
4 # a copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish,
7 # distribute, sublicense, and/or sell copies of the Software, and to
8 # permit persons to whom the Software is furnished to do so, subject to
9 # the following conditions:
11 # The above copyright notice and this permission notice shall be
12 # included in all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 # Basic toolchain defines.
23 CC = $(CROSS_COMPILE)gcc
24 LD = $(CROSS_COMPILE)ld
25 AR = $(CROSS_COMPILE)ar
26 RANLIB = $(CROSS_COMPILE)ranlib
29 ifneq ($(origin CROSS_COMPILE), undefined)
33 CLIB_ARCH = $(shell $(CC) -dumpmachine)
35 # Where to get linux kernel includes.
36 # By default get linux includes from /usr/include/linux...
39 # Where to find compiler include directory (since we may
40 # be using -nostdinc).
41 CC_PREFIX = $(shell dirname `$(CC) --print-libgcc-file-name`)
43 # Where to get LIBC includes for cross compiles
44 LIBC_PREFIX ?= $(CC_PREFIX)/../../../../$(CLIB_ARCH)
46 # Where to find CLIB includes/libraries for cross compiles
47 CLIB_PREFIX ?= /usr/local/$(CLIB_ARCH)
50 SHARED_OBJ = shared.$(OBJ)
51 KERNEL_OBJ = kernel.$(OBJ)
52 MODULE_OBJ = module.$(OBJ)
55 SHARED_DEP = shared.$(DEP)
56 KERNEL_DEP = kernel.$(DEP)
58 STATIC_LIB = $(CLIB_ARCH).a
59 SHARED_LIB = $(CLIB_ARCH).so
60 KERNEL_LIB = kernel.$(CLIB_ARCH).a
62 STATIC_CFLAGS = $(DEFAULT_CFLAGS)
63 SHARED_CFLAGS = $(STATIC_CFLAGS) -fPIC
65 # Compile flags common to user/kernel
66 CLIB_COMMON_CFLAGS += -Wall
71 CLIB_COMMON_CFLAGS += -DDEBUG
76 CLIB_COMMON_CFLAGS += $(COPTS)
78 CLIB_USER_CFLAGS = $(CLIB_COMMON_CFLAGS)
80 ifeq ($(IS_CROSS_COMPILE),yes)
81 CLIB_USER_CFLAGS += -nostdinc
82 CLIB_USER_CFLAGS += -idirafter $(CC_PREFIX)/include
83 CLIB_USER_CFLAGS += -idirafter $(KERNEL_PREFIX)/include
84 CLIB_USER_CFLAGS += -idirafter $(LIBC_PREFIX)/include
85 CLIB_COMMON_CFLAGS += -idirafter $(CLIB_PREFIX)/include
88 STATIC_CFLAGS = $(CLIB_USER_CFLAGS)
89 SHARED_CFLAGS = $(STATIC_CFLAGS) -fPIC
92 $(CC) -c $(SHARED_CFLAGS) -o $@ $<
95 $(CC) -c $(STATIC_CFLAGS) -o $@ $<
97 # Kernel version of clib
99 CLIB_KERNEL_CFLAGS = $(CLIB_COMMON_CFLAGS)
101 CLIB_KERNEL_CFLAGS += -nostdinc
102 CLIB_KERNEL_CFLAGS += -idirafter $(CC_PREFIX)/include
103 CLIB_KERNEL_CFLAGS += -idirafter $(KERNEL_PREFIX)/include
105 # Kernel always uses mheap allocator (no malloc)
106 CLIB_KERNEL_CFLAGS += -DCLIB_MEM_MHEAP
108 CLIB_KERNEL_CFLAGS += -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB
110 CLIB_KERNEL_CFLAGS += -fno-common -fomit-frame-pointer -fno-strict-aliasing
112 ifeq ($(findstring mips,$(CLIB_ARCH)),mips)
113 CLIB_KERNEL_CFLAGS += -G0 \
114 -mno-abicalls -fno-pic -mlong-calls \
115 -mcpu=r8000 -mips2 -Wa,--trap
119 $(CC) $(CLIB_KERNEL_CFLAGS) -c -o $@ $<
123 $(CC) $(CLIB_USER_CFLAGS) -c -M $< | sed -e s/.o:/.$(OBJ):/ > $@
126 $(CC) $(CLIB_USER_CFLAGS) -c -M $< | sed -e s/.o:/.$(SHARED_OBJ):/ > $@
129 $(CC) $(CLIB_KERNEL_CFLAGS) -c -M $< | sed -e s/.o:/.$(KERNEL_OBJ):/ > $@