Changeset a0a273e in mainline for kernel/Makefile


Ignore:
Timestamp:
2017-10-03T18:12:17Z (7 years ago)
Author:
jzr <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a41cda7
Parents:
0f28387
Message:

Unify compiler handling a bit.

Most compiler flags have been changed from GCC-specific to "common",
since code might build but not work properly without them.
Clang still rejects some of the flags, but at least we can see
the incompatibilities now.

Explicit —target flag was removed from clang, in favor of using clang
through a target-specific symlink. This allows clang to automatically
find correct assembler and linker, if it needs to.

Additionally, assembly language files are now compiled using $(CC)
whether or not they need the preprocessor. This allows clang to build
.s files using its integrated assembler.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/Makefile

    r0f28387 ra0a273e  
    8484DEFS = -DKERNEL -DRELEASE=$(RELEASE) "-DCOPYRIGHT=$(COPYRIGHT)" "-DNAME=$(NAME)" -D__$(BITS)_BITS__ -D__$(ENDIANESS)__
    8585
    86 GCC_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
    87         -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
    88         -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
    89         -std=gnu99 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes \
    90         -Werror-implicit-function-declaration -Wwrite-strings \
    91         -pipe
    92 
    93 ICC_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
    94         -ffreestanding -fno-builtin -nostdlib -nostdinc -Wall -Wmissing-prototypes \
     86COMMON_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
     87        -ffreestanding -fno-builtin -nostdlib -nostdinc \
     88        -fexec-charset=UTF-8 -finput-charset=UTF-8
     89
     90GCC_CFLAGS = -std=gnu99 -Wall -Wextra -Wno-unused-parameter \
     91        -Wmissing-prototypes -Werror-implicit-function-declaration \
     92        -Wwrite-strings -pipe
     93
     94ICC_CFLAGS = -Wall -Wmissing-prototypes \
    9595        -Werror-implicit-function-declaration -wd170
    9696
    97 # clang does not support following options but I am not sure whether
    98 # something won't break because of that:
    99 # -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) -finput-charset=UTF-8
    100 CLANG_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
    101         -ffreestanding -fno-builtin -nostdlib -nostdinc \
    102         -std=gnu99 -Wall -Werror -Wextra -Wno-unused-parameter -Wmissing-prototypes \
    103         -Werror-implicit-function-declaration -Wwrite-strings \
    104         -integrated-as -pipe -target $(CLANG_TARGET)
     97CLANG_CFLAGS = -std=gnu99 -Wall -Wextra -Wno-unused-parameter \
     98        -Wmissing-prototypes -Werror-implicit-function-declaration \
     99        -Wwrite-strings -pipe -fno-stack-protector -fno-PIC
    105100
    106101ifeq ($(CONFIG_DEBUG),y)
    107         GCC_CFLAGS += -Werror
    108         ICC_CFLAGS += -Werror
     102        COMMON_CFLAGS += -Werror
    109103endif
    110104
    111105ifeq ($(CONFIG_LTO),y)
    112         GCC_CFLAGS += -flto
     106        COMMON_CFLAGS += -flto
    113107endif
    114108
    115109ifeq ($(CONFIG_LINE_DEBUG),y)
    116         GCC_CFLAGS += -g
    117         ICC_CFLAGS += -g
    118         CLANG_CFLAGS += -g
     110        COMMON_CFLAGS += -g
    119111endif
    120112
     
    123115# AFLAGS and LFLAGS must be initialized before the inclusion.
    124116#
    125 AFLAGS = --fatal-warnings
     117AFLAGS =
    126118LFLAGS = -n -T $(LINK) -M --fatal-warnings
     119
     120# FIXME: This condition is a workaround for issues #693 and #694.
     121ifneq ($(KARCH),sparc64)
     122ifneq ($(KARCH),mips32)
     123        AFLAGS += --fatal-warnings
     124endif
     125endif
    127126
    128127#
     
    156155
    157156ifeq ($(COMPILER),gcc_native)
    158         CFLAGS = $(GCC_CFLAGS)
     157        CFLAGS = $(COMMON_CFLAGS) $(GCC_CFLAGS)
    159158        DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
    160159        INSTRUMENTATION = -finstrument-functions
     
    162161
    163162ifeq ($(COMPILER),gcc_cross)
    164         CFLAGS = $(GCC_CFLAGS)
     163        CFLAGS = $(COMMON_CFLAGS) $(GCC_CFLAGS)
    165164        DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
    166165        INSTRUMENTATION = -finstrument-functions
     
    168167
    169168ifeq ($(COMPILER),gcc_helenos)
    170         CFLAGS = $(GCC_CFLAGS)
     169        CFLAGS = $(COMMON_CFLAGS) $(GCC_CFLAGS)
    171170        DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
    172171        INSTRUMENTATION = -finstrument-functions
     
    174173
    175174ifeq ($(COMPILER),icc)
    176         CFLAGS = $(ICC_CFLAGS)
     175        CFLAGS = $(COMMON_CFLAGS) $(ICC_CFLAGS)
    177176        DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
    178177        INSTRUMENTATION =
     
    180179
    181180ifeq ($(COMPILER),clang)
    182         CFLAGS = $(CLANG_CFLAGS)
     181        CFLAGS = $(COMMON_CFLAGS) $(CLANG_CFLAGS)
    183182        DEPEND_DEFS = $(DEFS) $(CONFIG_DEFS)
    184         INSTRUMENTATION =
     183        INSTRUMENTATION = -finstrument-functions
    185184endif
    186185
     
    384383AUTOGENS_AG := $(ARCH_AUTOGENS_AG) $(GENARCH_AUTOGENS_AG)
    385384
    386 LFLAGS_LTO := $(addprefix -Xlinker ,$(LFLAGS))
     385AS_CFLAGS := $(addprefix -Xassembler ,$(AFLAGS))
     386LD_CFLAGS := $(addprefix -Xlinker ,$(LFLAGS))
     387
     388ifeq ($(COMPILER),clang)
     389        AS_CFLAGS += -mllvm -asm-macro-max-nesting-depth=1000
     390endif
    387391
    388392ifeq ($(CONFIG_SYMTAB),y)
     
    404408$(RAW): $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(SYMTAB_OBJECTS)
    405409ifeq ($(CONFIG_LTO),y)
    406         $(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
     410        $(CC) $(DEFS) $(CFLAGS) $(LD_CFLAGS) -Xlinker -Map -Xlinker $(MAP) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
    407411else
    408412        $(LD) $(LFLAGS) -Map $(MAP) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SYMTAB_OBJECTS)
     
    417421%.h: %.ag
    418422        $(AUTOGEN) probe $< >$<.probe.c
    419         $(CC) $(DEFS) $(CFLAGS) -S -o $<.probe.s $<.probe.c
     423        $(CC_AUTOGEN) $(DEFS) $(CFLAGS) -S -o $<.probe.s $<.probe.c
    420424        $(AUTOGEN) generate $< <$<.probe.s >$@   
    421425
    422426%.o: %.S $(DEPEND)
    423         $(GCC) $(DEFS) $(GCC_CFLAGS) -D__ASM__ -c -o $@ $<
     427        $(CC) $(DEFS) $(CFLAGS) $(AS_CFLAGS) -D__ASM__ -c -o $@ $<
    424428ifeq ($(PRECHECK),y)
    425         $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(GCC_CFLAGS) -D__ASM__
     429        $(JOBFILE) $(JOB) $< $@ as asm/preproc $(DEFS) $(CFLAGS) -D__ASM__
    426430endif
    427431
    428432%.o: %.s $(DEPEND)
    429         $(AS) $(AFLAGS) -o $@ $<
     433        $(CC) $(DEFS) $(CFLAGS) $(AS_CFLAGS) -D__ASM__ -c -o $@ $<
    430434ifeq ($(PRECHECK),y)
    431435        $(JOBFILE) $(JOB) $< $@ as asm $(DEFS) $(CFLAGS) $(EXTRA_FLAGS)
     
    439443
    440444$(REAL_MAP).o: $(REAL_MAP).bin
    441         echo "$(AS_PROLOG)""$(SYMTAB_SECTION)"" .incbin \"$<\"" | $(AS) $(AFLAGS) -o $@
     445        echo "$(AS_PROLOG)""$(SYMTAB_SECTION)"" .incbin \"$<\"" | $(CC) $(CFLAGS) $(AS_CFLAGS) -x assembler -c -o $@ -
    442446
    443447$(REAL_MAP).bin: $(LINK) $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS)
    444         echo "$(AS_PROLOG)""$(SYMTAB_SECTION)" | $(AS) $(AFLAGS) -o $(EMPTY_MAP)
     448        echo "$(AS_PROLOG)""$(SYMTAB_SECTION)" | $(CC) $(CFLAGS) $(AS_CFLAGS) -x assembler -c -o $(EMPTY_MAP) -
    445449ifeq ($(CONFIG_LTO),y)
    446         $(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP_PREV) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
     450        $(CC) $(DEFS) $(CFLAGS) $(LD_CFLAGS) -Xlinker -Map -Xlinker $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
    447451else
    448452        $(LD) $(LFLAGS) -Map $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(EMPTY_MAP)
     
    454458        # on architectures that have bss after symtab
    455459       
    456         echo "$(AS_PROLOG)""$(SYMTAB_SECTION)"" .incbin \"$@\"" | $(AS) $(AFLAGS) -o $(SIZEOK_MAP)
     460        echo "$(AS_PROLOG)""$(SYMTAB_SECTION)"" .incbin \"$@\"" | $(CC) $(CFLAGS) $(AS_CFLAGS) -x assembler -c -o $(SIZEOK_MAP) -
    457461ifeq ($(CONFIG_LTO),y)
    458         $(GCC) $(LFLAGS_LTO) -Xlinker -Map -Xlinker $(MAP_PREV) $(DEFS) $(GCC_CFLAGS) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
     462        $(CC) $(DEFS) $(CFLAGS) $(LD_CFLAGS) -Xlinker -Map -Xlinker $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
    459463else
    460464        $(LD) $(LFLAGS) -Map $(MAP_PREV) -o $@ $(ARCH_OBJECTS) $(GENARCH_OBJECTS) $(GENERIC_OBJECTS) $(EXTRA_OBJECTS) $(SIZEOK_MAP)
Note: See TracChangeset for help on using the changeset viewer.