blob: dcb51e16ab76dc3d4ecdae7ed737010581f33aee [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001# Copyright (c) 2001, 2002 Eliot Dresselhaus
2#
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:
10#
11# The above copyright notice and this permission notice shall be
12# included in all copies or substantial portions of the Software.
13#
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.
21
22# Basic toolchain defines.
23CC = $(CROSS_COMPILE)gcc
24LD = $(CROSS_COMPILE)ld
25AR = $(CROSS_COMPILE)ar
26RANLIB = $(CROSS_COMPILE)ranlib
27INSTALL = install
28
29ifneq ($(origin CROSS_COMPILE), undefined)
30 IS_CROSS_COMPILE=yes
31endif
32
33CLIB_ARCH = $(shell $(CC) -dumpmachine)
34
35# Where to get linux kernel includes.
36# By default get linux includes from /usr/include/linux...
37KERNEL_PREFIX ?= /usr
38
39# Where to find compiler include directory (since we may
40# be using -nostdinc).
41CC_PREFIX = $(shell dirname `$(CC) --print-libgcc-file-name`)
42
43# Where to get LIBC includes for cross compiles
44LIBC_PREFIX ?= $(CC_PREFIX)/../../../../$(CLIB_ARCH)
45
46# Where to find CLIB includes/libraries for cross compiles
47CLIB_PREFIX ?= /usr/local/$(CLIB_ARCH)
48
49OBJ = $(CLIB_ARCH).o
50SHARED_OBJ = shared.$(OBJ)
51KERNEL_OBJ = kernel.$(OBJ)
52MODULE_OBJ = module.$(OBJ)
53
54DEP = $(CLIB_ARCH).d
55SHARED_DEP = shared.$(DEP)
56KERNEL_DEP = kernel.$(DEP)
57
58STATIC_LIB = $(CLIB_ARCH).a
59SHARED_LIB = $(CLIB_ARCH).so
60KERNEL_LIB = kernel.$(CLIB_ARCH).a
61
62STATIC_CFLAGS = $(DEFAULT_CFLAGS)
63SHARED_CFLAGS = $(STATIC_CFLAGS) -fPIC
64
65# Compile flags common to user/kernel
66CLIB_COMMON_CFLAGS += -Wall
67
68DEBUG ?= no
69ifeq ($(DEBUG),yes)
70 COPTS ?= -g -O0
71 CLIB_COMMON_CFLAGS += -DDEBUG
72else
73 COPTS ?= -O2
74endif
75
76CLIB_COMMON_CFLAGS += $(COPTS)
77
78CLIB_USER_CFLAGS = $(CLIB_COMMON_CFLAGS)
79
80ifeq ($(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
86endif
87
88STATIC_CFLAGS = $(CLIB_USER_CFLAGS)
89SHARED_CFLAGS = $(STATIC_CFLAGS) -fPIC
90
91%.$(SHARED_OBJ): %.c
92 $(CC) -c $(SHARED_CFLAGS) -o $@ $<
93
94%.$(OBJ): %.c
95 $(CC) -c $(STATIC_CFLAGS) -o $@ $<
96
97# Kernel version of clib
98
99CLIB_KERNEL_CFLAGS = $(CLIB_COMMON_CFLAGS)
100
101CLIB_KERNEL_CFLAGS += -nostdinc
102CLIB_KERNEL_CFLAGS += -idirafter $(CC_PREFIX)/include
103CLIB_KERNEL_CFLAGS += -idirafter $(KERNEL_PREFIX)/include
104
105# Kernel always uses mheap allocator (no malloc)
106CLIB_KERNEL_CFLAGS += -DCLIB_MEM_MHEAP
107
108CLIB_KERNEL_CFLAGS += -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB
109
110CLIB_KERNEL_CFLAGS += -fno-common -fomit-frame-pointer -fno-strict-aliasing
111
112ifeq ($(findstring mips,$(CLIB_ARCH)),mips)
113 CLIB_KERNEL_CFLAGS += -G0 \
114 -mno-abicalls -fno-pic -mlong-calls \
115 -mcpu=r8000 -mips2 -Wa,--trap
116endif
117
118%.$(KERNEL_OBJ): %.c
119 $(CC) $(CLIB_KERNEL_CFLAGS) -c -o $@ $<
120
121# Dependencies
122%.$(DEP): %.c
123 $(CC) $(CLIB_USER_CFLAGS) -c -M $< | sed -e s/.o:/.$(OBJ):/ > $@
124
125%.$(SHARED_DEP): %.c
126 $(CC) $(CLIB_USER_CFLAGS) -c -M $< | sed -e s/.o:/.$(SHARED_OBJ):/ > $@
127
128%.$(KERNEL_DEP): %.c
129 $(CC) $(CLIB_KERNEL_CFLAGS) -c -M $< | sed -e s/.o:/.$(KERNEL_OBJ):/ > $@