[1b1164e8] | 1 | #
|
---|
| 2 | # Copyright (c) 2005 Martin Decky
|
---|
| 3 | # Copyright (c) 2007 Jakub Jermar
|
---|
| 4 | # All rights reserved.
|
---|
| 5 | #
|
---|
| 6 | # Redistribution and use in source and binary forms, with or without
|
---|
| 7 | # modification, are permitted provided that the following conditions
|
---|
| 8 | # are met:
|
---|
| 9 | #
|
---|
| 10 | # - Redistributions of source code must retain the above copyright
|
---|
| 11 | # notice, this list of conditions and the following disclaimer.
|
---|
| 12 | # - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | # notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | # documentation and/or other materials provided with the distribution.
|
---|
| 15 | # - The name of the author may not be used to endorse or promote products
|
---|
| 16 | # derived from this software without specific prior written permission.
|
---|
| 17 | #
|
---|
| 18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | #
|
---|
| 29 |
|
---|
| 30 | # Individual makefiles set:
|
---|
| 31 | #
|
---|
| 32 | # USPACE_PREFIX (*) relative path to uspace/ directory
|
---|
| 33 | # SOURCES (*) list of source files
|
---|
| 34 | # LIBS libraries to link with
|
---|
| 35 | # DEFS compiler defines
|
---|
| 36 | # EXTRA_CFLAGS additional flags to pass to C compiler
|
---|
| 37 | # LINKER_SCRIPT linker script
|
---|
| 38 | # PRE_DEPEND targets required for dependency check
|
---|
| 39 | #
|
---|
| 40 | # BINARY (/) binary output name (like appname)
|
---|
| 41 | # LIBRARY (/) library output name (like libname)
|
---|
| 42 | # EXTRA_OUTPUT additional output targets
|
---|
| 43 | # EXTRA_CLEAN additional cleanup targets
|
---|
| 44 | #
|
---|
| 45 | # (x) required variables
|
---|
| 46 | # (/) exactly one of the variables must be defined
|
---|
| 47 | #
|
---|
| 48 |
|
---|
| 49 | ROOT_PATH = $(USPACE_PREFIX)/..
|
---|
| 50 |
|
---|
| 51 | VERSION_DEF = $(ROOT_PATH)/version
|
---|
| 52 |
|
---|
| 53 | COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
|
---|
| 54 | COMMON_HEADER = $(ROOT_PATH)/common.h
|
---|
| 55 |
|
---|
| 56 | CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
|
---|
| 57 | CONFIG_HEADER = $(ROOT_PATH)/config.h
|
---|
| 58 |
|
---|
| 59 | -include $(VERSION_DEF)
|
---|
| 60 | -include $(COMMON_MAKEFILE)
|
---|
| 61 | -include $(CONFIG_MAKEFILE)
|
---|
| 62 |
|
---|
| 63 | ifneq ($(BINARY),)
|
---|
| 64 | JOB = $(BINARY).job
|
---|
| 65 | OUTPUT = $(BINARY)
|
---|
| 66 | EXTRA_OUTPUT += $(BINARY).disasm
|
---|
| 67 | EXTRA_CLEAN += $(BINARY).map
|
---|
| 68 | endif
|
---|
| 69 |
|
---|
| 70 | ifneq ($(LIBRARY),)
|
---|
| 71 | JOB = $(LIBRARY).job
|
---|
| 72 | OUTPUT = $(LIBRARY).a
|
---|
| 73 | endif
|
---|
| 74 |
|
---|
| 75 | DEPEND = Makefile.depend
|
---|
| 76 | DEPEND_PREV = $(DEPEND).prev
|
---|
| 77 |
|
---|
[36a75a2] | 78 | LIB_PREFIX = $(USPACE_PREFIX)/lib
|
---|
[849ed54] | 79 |
|
---|
| 80 | LIBC_PREFIX = $(LIB_PREFIX)/c
|
---|
| 81 | LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
|
---|
| 82 | LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
|
---|
| 83 |
|
---|
| 84 | LIBBLOCK_PREFIX = $(LIB_PREFIX)/block
|
---|
| 85 | LIBFS_PREFIX = $(LIB_PREFIX)/fs
|
---|
[ee7e82a9] | 86 | LIBCLUI_PREFIX = $(LIB_PREFIX)/clui
|
---|
[849ed54] | 87 |
|
---|
[efedee77] | 88 |
|
---|
[c0e1be7] | 89 | LIBUSB_PREFIX = $(LIB_PREFIX)/usb
|
---|
[3e4f2e0] | 90 | LIBUSBHOST_PREFIX = $(LIB_PREFIX)/usbhost
|
---|
| 91 | LIBUSBDEV_PREFIX = $(LIB_PREFIX)/usbdev
|
---|
| 92 | LIBUSBHID_PREFIX = $(LIB_PREFIX)/usbhid
|
---|
[b8100da] | 93 | LIBUSBVIRT_PREFIX = $(LIB_PREFIX)/usbvirt
|
---|
[c47e1a8] | 94 | LIBDRV_PREFIX = $(LIB_PREFIX)/drv
|
---|
[f63a591d] | 95 | LIBPACKET_PREFIX = $(LIB_PREFIX)/packet
|
---|
[849ed54] | 96 | LIBNET_PREFIX = $(LIB_PREFIX)/net
|
---|
| 97 |
|
---|
| 98 | BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
|
---|
[1b1164e8] | 99 |
|
---|
| 100 | LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
|
---|
| 101 |
|
---|
[3c664d6] | 102 | ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
|
---|
| 103 | OPTIMIZATION = s
|
---|
| 104 | else
|
---|
| 105 | OPTIMIZATION = 3
|
---|
| 106 | endif
|
---|
| 107 |
|
---|
[1b1164e8] | 108 | .PHONY: all clean
|
---|
| 109 |
|
---|
| 110 | all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(EXTRA_OUTPUT)
|
---|
| 111 | -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
|
---|
| 112 |
|
---|
| 113 | clean:
|
---|
| 114 | rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
|
---|
| 115 | find . -name '*.o' -follow -exec rm \{\} \;
|
---|
| 116 |
|
---|
| 117 | GCC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
|
---|
| 118 | -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
|
---|
| 119 | -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
|
---|
| 120 | -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
|
---|
| 121 | -Werror-implicit-function-declaration -Wwrite-strings \
|
---|
[e805e2f] | 122 | -pipe -g -D__$(ENDIANESS)__
|
---|
[1b1164e8] | 123 |
|
---|
| 124 | ICC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
|
---|
| 125 | -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
|
---|
| 126 | -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
|
---|
| 127 | -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
|
---|
| 128 | -Werror-implicit-function-declaration -Wwrite-strings \
|
---|
[e805e2f] | 129 | -pipe -g -D__$(ENDIANESS)__
|
---|
[1b1164e8] | 130 |
|
---|
| 131 | CLANG_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
|
---|
| 132 | -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
|
---|
| 133 | -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
|
---|
| 134 | -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
|
---|
| 135 | -Werror-implicit-function-declaration -Wwrite-strings \
|
---|
| 136 | -pipe -g -arch $(CLANG_ARCH) -D__$(ENDIANESS)__
|
---|
| 137 |
|
---|
[e805e2f] | 138 | ifeq ($(CONFIG_DEBUG),y)
|
---|
| 139 | GCC_CFLAGS += -Werror
|
---|
| 140 | ICC_CFLAGS += -Werror
|
---|
| 141 | endif
|
---|
| 142 |
|
---|
[1e00216] | 143 | ifeq ($(CONFIG_LINE_DEBUG),y)
|
---|
| 144 | GCC_CFLAGS += -g
|
---|
| 145 | ICC_CFLAGS += -g
|
---|
| 146 | SUNCC_CFLAGS += -g
|
---|
| 147 | CLANG_CFLAGS += -g
|
---|
| 148 | endif
|
---|
| 149 |
|
---|
[1b1164e8] | 150 | ## Setup platform configuration
|
---|
| 151 | #
|
---|
| 152 |
|
---|
| 153 | -include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
|
---|
| 154 |
|
---|
| 155 | ## Compilation options
|
---|
| 156 | #
|
---|
| 157 |
|
---|
| 158 | JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py
|
---|
| 159 |
|
---|
| 160 | ifeq ($(COMPILER),gcc_cross)
|
---|
| 161 | CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS)
|
---|
| 162 | DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
|
---|
| 163 | endif
|
---|
| 164 |
|
---|
| 165 | ifeq ($(COMPILER),gcc_native)
|
---|
| 166 | CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS)
|
---|
| 167 | DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
|
---|
| 168 | endif
|
---|
| 169 |
|
---|
| 170 | ifeq ($(COMPILER),icc)
|
---|
| 171 | CFLAGS = $(ICC_CFLAGS) $(EXTRA_CFLAGS)
|
---|
| 172 | DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
|
---|
| 173 | endif
|
---|
| 174 |
|
---|
| 175 | ifeq ($(COMPILER),clang)
|
---|
| 176 | CFLAGS = $(CLANG_CFLAGS) $(EXTRA_CFLAGS)
|
---|
| 177 | DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
|
---|
| 178 | endif
|
---|
| 179 |
|
---|
| 180 | -include $(DEPEND)
|
---|
| 181 |
|
---|
| 182 | OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
|
---|
| 183 |
|
---|
| 184 | ifneq ($(BINARY),)
|
---|
| 185 | %.disasm: $(BINARY)
|
---|
[9ded977] | 186 | ifeq ($(CONFIG_LINE_DEBUG),y)
|
---|
| 187 | $(OBJDUMP) -d -S $< > $@
|
---|
| 188 | else
|
---|
[1b1164e8] | 189 | $(OBJDUMP) -d $< > $@
|
---|
[9ded977] | 190 | endif
|
---|
[1b1164e8] | 191 |
|
---|
| 192 | $(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS)
|
---|
| 193 | $(LD) -N $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS)
|
---|
[1cb092d] | 194 | ifeq ($(CONFIG_STRIP_BINARIES),y)
|
---|
| 195 | $(STRIP) $(BINARY)
|
---|
| 196 | endif
|
---|
[1b1164e8] | 197 | endif
|
---|
| 198 |
|
---|
| 199 | ifneq ($(LIBRARY),)
|
---|
| 200 | %.a: $(OBJECTS)
|
---|
| 201 | $(AR) rc $@ $(OBJECTS)
|
---|
| 202 | endif
|
---|
| 203 |
|
---|
| 204 | %.o: %.S $(DEPEND)
|
---|
| 205 | $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
|
---|
| 206 | ifeq ($(PRECHECK),y)
|
---|
| 207 | $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
|
---|
| 208 | endif
|
---|
| 209 |
|
---|
| 210 | %.o: %.s $(DEPEND)
|
---|
| 211 | $(AS) $(AFLAGS) -o $@ $<
|
---|
| 212 | ifeq ($(PRECHECK),y)
|
---|
| 213 | $(JOBFILE) $(JOB) $< $@ as asm
|
---|
| 214 | endif
|
---|
| 215 |
|
---|
| 216 | %.o: %.c $(DEPEND)
|
---|
| 217 | $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
|
---|
| 218 | ifeq ($(PRECHECK),y)
|
---|
| 219 | $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
|
---|
| 220 | endif
|
---|
| 221 |
|
---|
| 222 | $(DEPEND): $(PRE_DEPEND)
|
---|
| 223 | makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(SOURCES) > $@ 2> /dev/null
|
---|
| 224 | -[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
|
---|
[664af708] | 225 |
|
---|
| 226 | ##
|
---|
| 227 | # This explicit dependecy of the output binary on the object files seems to be
|
---|
| 228 | # necessary to prevent parallel build failures (GNU make bug #26893 ???).
|
---|
| 229 | $(OUTPUT): $(OBJECTS)
|
---|
| 230 |
|
---|