source: mainline/uspace/Makefile.common@ 0655d64

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 0655d64 was 63f8966, checked in by Martin Decky <martin@…>, 15 years ago

rename library directories (the common "lib" prefix is already in the upper directory)

  • Property mode set to 100644
File size: 6.0 KB
Line 
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
49ROOT_PATH = $(USPACE_PREFIX)/..
50
51VERSION_DEF = $(ROOT_PATH)/version
52
53COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
54COMMON_HEADER = $(ROOT_PATH)/common.h
55
56CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
57CONFIG_HEADER = $(ROOT_PATH)/config.h
58
59-include $(VERSION_DEF)
60-include $(COMMON_MAKEFILE)
61-include $(CONFIG_MAKEFILE)
62
63ifneq ($(BINARY),)
64 JOB = $(BINARY).job
65 OUTPUT = $(BINARY)
66 EXTRA_OUTPUT += $(BINARY).disasm
67 EXTRA_CLEAN += $(BINARY).map
68endif
69
70ifneq ($(LIBRARY),)
71 JOB = $(LIBRARY).job
72 OUTPUT = $(LIBRARY).a
73endif
74
75DEPEND = Makefile.depend
76DEPEND_PREV = $(DEPEND).prev
77
78LIBC_PREFIX = $(USPACE_PREFIX)/lib/c
79LIBBLOCK_PREFIX = $(USPACE_PREFIX)/lib/block
80LIBFS_PREFIX = $(USPACE_PREFIX)/lib/fs
81LIBPCI_PREFIX = $(USPACE_PREFIX)/lib/pci
82SOFTFLOAT_PREFIX = $(USPACE_PREFIX)/lib/softfloat
83SOFTINT_PREFIX = $(USPACE_PREFIX)/lib/softint
84
85BASE_LIBS = $(LIBC_PREFIX)/libc.a $(SOFTINT_PREFIX)/libsoftint.a
86
87LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
88
89.PHONY: all clean
90
91all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(EXTRA_OUTPUT)
92 -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV)
93
94clean:
95 rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN)
96 find . -name '*.o' -follow -exec rm \{\} \;
97
98OPTIMIZATION = 3
99
100GCC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
101 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
102 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
103 -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
104 -Werror-implicit-function-declaration -Wwrite-strings \
105 -Werror -pipe -g -D__$(ENDIANESS)__
106
107ICC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
108 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
109 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
110 -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \
111 -Werror-implicit-function-declaration -Wwrite-strings \
112 -Werror -pipe -g -D__$(ENDIANESS)__
113
114CLANG_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
115 -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
116 -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
117 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
118 -Werror-implicit-function-declaration -Wwrite-strings \
119 -pipe -g -arch $(CLANG_ARCH) -D__$(ENDIANESS)__
120
121## Setup platform configuration
122#
123
124-include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common
125
126## Compilation options
127#
128
129JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py
130
131ifeq ($(COMPILER),gcc_cross)
132 CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS)
133 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
134endif
135
136ifeq ($(COMPILER),gcc_native)
137 CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS)
138 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
139endif
140
141ifeq ($(COMPILER),icc)
142 CFLAGS = $(ICC_CFLAGS) $(EXTRA_CFLAGS)
143 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
144endif
145
146ifeq ($(COMPILER),clang)
147 CFLAGS = $(CLANG_CFLAGS) $(EXTRA_CFLAGS)
148 DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
149endif
150
151-include $(DEPEND)
152
153OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
154
155ifneq ($(BINARY),)
156%.disasm: $(BINARY)
157 $(OBJDUMP) -d $< > $@
158
159$(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS)
160 $(LD) -N $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS)
161endif
162
163ifneq ($(LIBRARY),)
164%.a: $(OBJECTS)
165 $(AR) rc $@ $(OBJECTS)
166endif
167
168%.o: %.S $(DEPEND)
169 $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
170ifeq ($(PRECHECK),y)
171 $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
172endif
173
174%.o: %.s $(DEPEND)
175 $(AS) $(AFLAGS) -o $@ $<
176ifeq ($(PRECHECK),y)
177 $(JOBFILE) $(JOB) $< $@ as asm
178endif
179
180%.o: %.c $(DEPEND)
181 $(CC) $(DEFS) $(CFLAGS) -c $< -o $@
182ifeq ($(PRECHECK),y)
183 $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS)
184endif
185
186$(DEPEND): $(PRE_DEPEND)
187 makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(SOURCES) > $@ 2> /dev/null
188 -[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@
Note: See TracBrowser for help on using the repository browser.