# -*-Makefile-*- # # This is the main Makefile # Target tools CC=$(CROSS)gcc$(POSTFIX) LD=$(CROSS)ld$(POSTFIX) AS=$(CROSS)as AR=$(CROSS)ar NM=$(CROSS)nm OBJCOPY=$(CROSS)objcopy OBJDUMP=$(CROSS)objdump SIZE=$(CROSS)size LD_TEXT=0x0 NM += --synthetic try = $(shell set -e; if ($(1)) >/dev/null 2>&1; \ then echo "$(2)"; \ else echo "$(3)"; fi ) try-cflag = $(call try,$(1) $(2) -x c -c /dev/null -o /dev/null,$(2)) # Base warnings CWARNS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ -Werror-implicit-function-declaration -Wdeclaration-after-statement \ -Wno-pointer-sign -Wextra -Wno-sign-compare \ -Wmissing-prototypes -Wmissing-declarations \ -Wwrite-strings -Wcast-align \ -Winit-self \ -Wframe-larger-than=1024 \ -Werror # Host tools and options HOSTCC=gcc HOSTEND=$(shell uname -m | sed -e 's/^i.*86$$/LITTLE/' -e 's/^x86.*/LITTLE/' -e 's/^ppc64le/LITTLE/' -e 's/^ppc.*/BIG/') HOSTCFLAGS=-O1 $(CWARNS) -DHAVE_$(HOSTEND)_ENDIAN -MMD HOSTCFLAGS += $(call try-cflag,$(HOSTCC),-std=gnu11) HOSTCFLAGS += $(call try-cflag,$(HOSTCC),-m64) HOSTCFLAGS += $(call try-cflag,$(HOSTCC),-Wjump-misses-init) \ $(call try-cflag,$(HOSTCC),-Wsuggest-attribute=const) \ $(call try-cflag,$(HOSTCC),-Wsuggest-attribute=noreturn) \ $(call try-cflag,$(HOSTCC),-Wstack-usage=1024) HOSTCFLAGS += -DDEBUG -DCCAN_LIST_DEBUG HOSTGCOVCFLAGS = -fprofile-arcs -ftest-coverage -lgcov -O0 -g -pg VALGRIND=valgrind -q --show-reachable=yes --error-exitcode=99 # Target options OPTS=-Os -ffunction-sections DBG=-g CPPFLAGS := -I$(SRC)/include -Iinclude -MMD -include $(SRC)/include/config.h CPPFLAGS += -I$(SRC)/libfdt -I$(SRC)/libflash -I$(SRC)/libc/include -I$(SRC) ifeq ($(PORE),1) CPPFLAGS += -I$(SRC)/libpore -D__HAVE_LIBPORE__ endif CPPFLAGS += -D__SKIBOOT__ -nostdinc CPPFLAGS += -isystem $(shell $(CC) -print-file-name=include) CPPFLAGS += -DBITS_PER_LONG=64 -DHAVE_BIG_ENDIAN # We might want to remove our copy of stdint.h # but that means uint64_t becomes an ulong instead of an ullong # causing all our printf's to warn CPPFLAGS += -ffreestanding ifeq ($(DEBUG),1) CPPFLAGS += -DDEBUG -DCCAN_LIST_DEBUG endif CFLAGS := -fno-strict-aliasing -pie -mbig-endian -m64 CFLAGS += -Wl,--oformat,elf64-powerpc CFLAGS += $(call try-cflag,$(CC),-mabi=elfv1) CFLAGS += $(call try-cflag,$(CC),-std=gnu11) ifeq ($(SKIBOOT_GCOV),1) CFLAGS += -fprofile-arcs -ftest-coverage -DSKIBOOT_GCOV=1 endif ifeq ($(STACK_CHECK),1) CFLAGS += -fstack-protector-all -pg CPPFLAGS += -DSTACK_CHECK_ENABLED else CFLAGS += -fstack-protector CFLAGS += $(call try-cflag,$(CC),-fstack-protector-strong) endif CFLAGS += $(call try-cflag,$(CC),-Wjump-misses-init) \ $(call try-cflag,$(CC),-Wsuggest-attribute=const) \ $(call try-cflag,$(CC),-Wsuggest-attribute=noreturn) \ $(call try-cflag,$(CC),-Wstack-usage=1024) CFLAGS += $(CWARNS) $(OPTS) $(DBG) LDFLAGS := -m64 -static -nostdlib -pie LDFLAGS += -Wl,-Ttext-segment,$(LD_TEXT) -Wl,-N -Wl,--build-id=none LDFLAGS += -Wl,--no-multi-toc LDFLAGS += -mbig-endian -Wl,--oformat,elf64-powerpc LDRFLAGS=-melf64ppc # Debug stuff #LDFLAGS += -Wl,-v -Wl,-Map,foomap AFLAGS := -D__ASSEMBLY__ -mbig-endian -m64 # Special tool flags: # Do not use the floating point unit CFLAGS += -msoft-float # Do not use string instructions CFLAGS += -mno-string # do not use load/store multiple word instrcutions CFLAGS += -mno-multiple # do not use any automatic vector foo # While it would be safe during boot, we don't save/restore across OPAL calls CFLAGS += $(call try-cflag,$(CC),-mno-vsx) \ $(call try-cflag,$(CC),-mno-direct-move) \ $(call try-cflag,$(CC),-mno-altivec) # Do not use load/store update. You REALLY do not want to use this! # The async safety of the ABI stack depends on the atomicity # of update on store. #CFLAGS += -mno-update ifneq ($(KERNEL),) CPPFLAGS += -DBUILTIN_KERNEL="\"$(KERNEL)\"" endif CHECK = sparse CHECKFLAGS := $(CF) CHECK_CFLAGS_SKIP = -std=gnu11 .SECONDARY: vpath %.c $(SRC) vpath %.C $(SRC) vpath %.S $(SRC) default: all include/asm-offsets.h: asm/asm-offsets.s @mkdir -p include $(call Q,GN, $(SRC)/make_offsets.sh $< >$@, $@) TARGET = skiboot include $(SRC)/asm/Makefile.inc include $(SRC)/core/Makefile.inc include $(SRC)/hw/Makefile.inc include $(SRC)/platforms/Makefile.inc include $(SRC)/libfdt/Makefile.inc include $(SRC)/libflash/Makefile.inc include $(SRC)/libpore/Makefile.inc include $(SRC)/libc/Makefile.inc include $(SRC)/ccan/Makefile.inc include $(SRC)/$(DEVSRC)/Makefile.inc include $(SRC)/libstb/Makefile.inc # hack for travis-ci and coverity gard: (cd external/gard; make) pflash: (cd external/pflash; make) pflash-coverity: (cd external/pflash; ./build-all-arch.sh) all: $(SUBDIRS) $(TARGET).lid $(TARGET).lid.xz $(TARGET).map extract-gcov OBJS := $(ASM) $(CORE) $(HW) $(PLATFORMS) $(LIBFDT) $(LIBFLASH) $(LIBSTB) ifeq ($(PORE),1) OBJS += $(LIBPORE) endif OBJS += $(LIBC) $(CCAN) $(DEVSRC_OBJ) OBJS_NO_VER = $(OBJS) ALL_OBJS = $(OBJS) version.o ALL_OBJS_1 = $(ALL_OBJS) asm/dummy_map.o ALL_OBJS_2 = $(ALL_OBJS) asm/real_map.o $(TARGET).lid.xz: $(TARGET).lid $(call Q,XZ, cat $^ | xz -9 -C crc32 > $@, $@) $(TARGET).lid: $(TARGET).elf $(call Q,OBJCOPY, $(OBJCOPY) -O binary -S $^ $@, $@) $(TARGET).tmp.elf: $(ALL_OBJS_1) $(TARGET).lds $(KERNEL) $(call Q,LD, $(CC) $(LDFLAGS) -T $(TARGET).lds $(ALL_OBJS_1) -o $@, $@) asm/real_map.o : $(TARGET).tmp.map $(TARGET).elf: $(ALL_OBJS_2) $(TARGET).lds $(KERNEL) $(call Q,LD, $(CC) $(LDFLAGS) -T $(TARGET).lds $(ALL_OBJS_2) -o $@, $@) $(SUBDIRS): $(call Q,MKDIR,mkdir $@, $@) -include $(wildcard *.d) -include $(wildcard $(SUBDIRS:%=%/*.d)) # Set V=1 if you want to see everything. include $(SRC)/Makefile.rules VERSION ?= $(shell cd $(SRC); GIT_DIR=$(SRC)/.git $(SRC)/make_version.sh) .PHONY: VERSION-always .version: VERSION-always @echo $(VERSION) > $@.tmp @cmp -s $@ $@.tmp || cp $@.tmp $@ @rm -f $@.tmp version.c: $(SRC)/make_version.sh $(OBJS_NO_VER) .version @(if [ "a$(VERSION)" = "a" ]; then \ echo "#error You need to set SKIBOOT_VERSION environment variable" > $@ ;\ else \ echo "const char version[] = \"$(VERSION)\";" ;\ fi) > $@ .PHONY: coverage include $(shell find $(SRC)/* -name Makefile.check) extract-gcov: extract-gcov.c $(call Q, HOSTCC ,$(HOSTCC) $(HOSTCFLAGS) \ -DTARGET__GNUC__=`echo '__GNUC__'|$(CC) -E -|grep -v '^#'` \ -DTARGET__GNUC_MINOR__=`echo '__GNUC_MINOR__'|$(CC) -E -|grep -v '^#'` \ -Wpadded -O0 -g -I$(SRC) -o $@ $<,$<) coverage-report: skiboot.info genhtml --branch-coverage -q -o $@ $< skiboot.info: coverage lcov -q -c -d . $(LCOV_DIRS) -o $@ --rc lcov_branch_coverage=1 lcov -q -r $@ $(LCOV_EXCLUDE) -o $@ --rc lcov_branch_coverage=1 tags: find . -name '*.[chS]' | xargs ctags TAGS: find . -name '*.[chS]' | xargs etags .PHONY: tags TAGS check coverage cscope: find . -name '*.[chS]' | xargs cscope clean: $(RM) *.[odsa] $(SUBDIRS:%=%/*.[odsa]) $(RM) *.elf $(TARGET).lid *.map $(TARGET).lds $(TARGET).lid.xz $(RM) include/asm-offsets.h version.c .version $(RM) extract-gcov distclean: clean $(RM) *~ $(SUBDIRS:%=%/*~) include/*~