# # Copyright (c) 2005 Martin Decky # Copyright (c) 2007 Jakub Jermar # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # - Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # - Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # - The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Individual makefiles set: # # USPACE_PREFIX (*) relative path to uspace/ directory # SOURCES (*) list of source files # LIBS libraries to link with # DEFS compiler defines # EXTRA_CFLAGS additional flags to pass to C compiler # LINKER_SCRIPT linker script # PRE_DEPEND targets required for dependency check # # BINARY (/) binary output name (like appname) # LIBRARY (/) library output name (like libname) # EXTRA_OUTPUT additional output targets # EXTRA_CLEAN additional cleanup targets # # (x) required variables # (/) exactly one of the variables must be defined # ROOT_PATH = $(USPACE_PREFIX)/.. VERSION_DEF = $(ROOT_PATH)/version COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common COMMON_HEADER = $(ROOT_PATH)/common.h CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config CONFIG_HEADER = $(ROOT_PATH)/config.h -include $(VERSION_DEF) -include $(COMMON_MAKEFILE) -include $(CONFIG_MAKEFILE) ifneq ($(BINARY),) JOB = $(BINARY).job OUTPUT = $(BINARY) EXTRA_OUTPUT += $(BINARY).disasm EXTRA_CLEAN += $(BINARY).map endif ifneq ($(LIBRARY),) JOB = $(LIBRARY).job OUTPUT = $(LIBRARY).a endif DEPEND = Makefile.depend DEPEND_PREV = $(DEPEND).prev LIB_PREFIX = $(USPACE_PREFIX)/lib LIBC_PREFIX = $(LIB_PREFIX)/c LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint LIBBLOCK_PREFIX = $(LIB_PREFIX)/block LIBFS_PREFIX = $(LIB_PREFIX)/fs LIBCLUI_PREFIX = $(LIB_PREFIX)/clui LIBDRV_PREFIX = $(LIB_PREFIX)/drv LIBPACKET_PREFIX = $(LIB_PREFIX)/packet LIBNET_PREFIX = $(LIB_PREFIX)/net LIBMINIX_PREFIX = $(LIB_PREFIX)/minix BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y) OPTIMIZATION = s else OPTIMIZATION = 3 endif .PHONY: all clean all: $(VERSION_DEF) $(COMMON_MAKEFILE) $(CONFIG_MAKEFILE) $(CONFIG_HEADER) $(LIBS) $(OUTPUT) $(EXTRA_OUTPUT) -[ -f $(DEPEND) ] && cp -a $(DEPEND) $(DEPEND_PREV) clean: rm -f $(DEPEND) $(DEPEND_PREV) $(JOB) $(OUTPUT) $(EXTRA_OUTPUT) $(EXTRA_CLEAN) find . -name '*.o' -follow -exec rm \{\} \; GCC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \ -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \ -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \ -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \ -Werror-implicit-function-declaration -Wwrite-strings \ -pipe -g -D__$(ENDIANESS)__ ICC_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \ -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \ -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \ -Wall -Wextra -Wno-clobbered -Wno-unused-parameter -Wmissing-prototypes \ -Werror-implicit-function-declaration -Wwrite-strings \ -pipe -g -D__$(ENDIANESS)__ CLANG_CFLAGS = -I$(LIBC_PREFIX)/include -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \ -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \ -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \ -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \ -Werror-implicit-function-declaration -Wwrite-strings \ -pipe -g -arch $(CLANG_ARCH) -D__$(ENDIANESS)__ ifeq ($(CONFIG_DEBUG),y) GCC_CFLAGS += -Werror ICC_CFLAGS += -Werror endif ifeq ($(CONFIG_LINE_DEBUG),y) GCC_CFLAGS += -g ICC_CFLAGS += -g SUNCC_CFLAGS += -g CLANG_CFLAGS += -g endif ## Setup platform configuration # -include $(LIBC_PREFIX)/arch/$(UARCH)/Makefile.common ## Compilation options # JOBFILE = $(LIBC_PREFIX)/../../../tools/jobfile.py ifeq ($(COMPILER),gcc_cross) CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS) DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS) endif ifeq ($(COMPILER),gcc_native) CFLAGS = $(GCC_CFLAGS) $(EXTRA_CFLAGS) DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS) endif ifeq ($(COMPILER),icc) CFLAGS = $(ICC_CFLAGS) $(EXTRA_CFLAGS) DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS) endif ifeq ($(COMPILER),clang) CFLAGS = $(CLANG_CFLAGS) $(EXTRA_CFLAGS) DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS) endif -include $(DEPEND) OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) ifneq ($(BINARY),) %.disasm: $(BINARY) ifeq ($(CONFIG_LINE_DEBUG),y) $(OBJDUMP) -d -S $< > $@ else $(OBJDUMP) -d $< > $@ endif $(BINARY): $(LINKER_SCRIPT) $(OBJECTS) $(LIBS) $(BASE_LIBS) $(LD) -N $(LFLAGS) -T $(LINKER_SCRIPT) -M -Map $(BINARY).map -o $(BINARY) $(OBJECTS) $(LIBS) $(BASE_LIBS) ifeq ($(CONFIG_STRIP_BINARIES),y) $(STRIP) $(BINARY) endif endif ifneq ($(LIBRARY),) %.a: $(OBJECTS) $(AR) rc $@ $(OBJECTS) endif %.o: %.S $(DEPEND) $(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@ ifeq ($(PRECHECK),y) $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__ endif %.o: %.s $(DEPEND) $(AS) $(AFLAGS) -o $@ $< ifeq ($(PRECHECK),y) $(JOBFILE) $(JOB) $< $@ as asm endif %.o: %.c $(DEPEND) $(CC) $(DEFS) $(CFLAGS) -c $< -o $@ ifeq ($(PRECHECK),y) $(JOBFILE) $(JOB) $< $@ cc core $(DEFS) $(CFLAGS) endif $(DEPEND): $(PRE_DEPEND) makedepend -f - -- $(DEPEND_DEFS) $(CFLAGS) -- $(SOURCES) > $@ 2> /dev/null -[ -f $(DEPEND_PREV) ] && diff -q $(DEPEND_PREV) $@ && mv -f $(DEPEND_PREV) $@ ## # This explicit dependecy of the output binary on the object files seems to be # necessary to prevent parallel build failures (GNU make bug #26893 ???). $(OUTPUT): $(OBJECTS)