Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | # 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. |
| 23 | CC = $(CROSS_COMPILE)gcc |
| 24 | LD = $(CROSS_COMPILE)ld |
| 25 | AR = $(CROSS_COMPILE)ar |
| 26 | RANLIB = $(CROSS_COMPILE)ranlib |
| 27 | INSTALL = install |
| 28 | |
| 29 | ifneq ($(origin CROSS_COMPILE), undefined) |
| 30 | IS_CROSS_COMPILE=yes |
| 31 | endif |
| 32 | |
| 33 | CLIB_ARCH = $(shell $(CC) -dumpmachine) |
| 34 | |
| 35 | # Where to get linux kernel includes. |
| 36 | # By default get linux includes from /usr/include/linux... |
| 37 | KERNEL_PREFIX ?= /usr |
| 38 | |
| 39 | # Where to find compiler include directory (since we may |
| 40 | # be using -nostdinc). |
| 41 | CC_PREFIX = $(shell dirname `$(CC) --print-libgcc-file-name`) |
| 42 | |
| 43 | # Where to get LIBC includes for cross compiles |
| 44 | LIBC_PREFIX ?= $(CC_PREFIX)/../../../../$(CLIB_ARCH) |
| 45 | |
| 46 | # Where to find CLIB includes/libraries for cross compiles |
| 47 | CLIB_PREFIX ?= /usr/local/$(CLIB_ARCH) |
| 48 | |
| 49 | OBJ = $(CLIB_ARCH).o |
| 50 | SHARED_OBJ = shared.$(OBJ) |
| 51 | KERNEL_OBJ = kernel.$(OBJ) |
| 52 | MODULE_OBJ = module.$(OBJ) |
| 53 | |
| 54 | DEP = $(CLIB_ARCH).d |
| 55 | SHARED_DEP = shared.$(DEP) |
| 56 | KERNEL_DEP = kernel.$(DEP) |
| 57 | |
| 58 | STATIC_LIB = $(CLIB_ARCH).a |
| 59 | SHARED_LIB = $(CLIB_ARCH).so |
| 60 | KERNEL_LIB = kernel.$(CLIB_ARCH).a |
| 61 | |
| 62 | STATIC_CFLAGS = $(DEFAULT_CFLAGS) |
| 63 | SHARED_CFLAGS = $(STATIC_CFLAGS) -fPIC |
| 64 | |
| 65 | # Compile flags common to user/kernel |
| 66 | CLIB_COMMON_CFLAGS += -Wall |
| 67 | |
| 68 | DEBUG ?= no |
| 69 | ifeq ($(DEBUG),yes) |
| 70 | COPTS ?= -g -O0 |
| 71 | CLIB_COMMON_CFLAGS += -DDEBUG |
| 72 | else |
| 73 | COPTS ?= -O2 |
| 74 | endif |
| 75 | |
| 76 | CLIB_COMMON_CFLAGS += $(COPTS) |
| 77 | |
| 78 | CLIB_USER_CFLAGS = $(CLIB_COMMON_CFLAGS) |
| 79 | |
| 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 |
| 86 | endif |
| 87 | |
| 88 | STATIC_CFLAGS = $(CLIB_USER_CFLAGS) |
| 89 | SHARED_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 | |
| 99 | CLIB_KERNEL_CFLAGS = $(CLIB_COMMON_CFLAGS) |
| 100 | |
| 101 | CLIB_KERNEL_CFLAGS += -nostdinc |
| 102 | CLIB_KERNEL_CFLAGS += -idirafter $(CC_PREFIX)/include |
| 103 | CLIB_KERNEL_CFLAGS += -idirafter $(KERNEL_PREFIX)/include |
| 104 | |
| 105 | # Kernel always uses mheap allocator (no malloc) |
| 106 | CLIB_KERNEL_CFLAGS += -DCLIB_MEM_MHEAP |
| 107 | |
| 108 | CLIB_KERNEL_CFLAGS += -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB |
| 109 | |
| 110 | CLIB_KERNEL_CFLAGS += -fno-common -fomit-frame-pointer -fno-strict-aliasing |
| 111 | |
| 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 |
| 116 | endif |
| 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):/ > $@ |