[Plugins] Updated the Makefile

- Added some comments
- Linking without --relocatable to check if all symbols can be found
- cleanup
This commit is contained in:
Maschell 2018-02-11 14:45:20 +01:00
parent 2d685cf41f
commit 3cc18c2557
3 changed files with 114 additions and 72 deletions

View File

@ -18,11 +18,11 @@ export GCC_VER := $(shell $(DEVKITPPC)/bin/powerpc-eabi-gcc -dumpversion)
PREFIX := powerpc-eabi- PREFIX := powerpc-eabi-
export AS := $(PREFIX)as export AS := $(PREFIX)as
export CC := $(PREFIX)gcc export CC := $(PREFIX)gcc
export CXX := $(PREFIX)g++ export CXX := $(PREFIX)g++
export REAL_LD := $(PREFIX)ld export LD := $(PREFIX)ld
export AR := $(PREFIX)ar export AR := $(PREFIX)ar
export OBJCOPY := $(PREFIX)objcopy export OBJCOPY := $(PREFIX)objcopy
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
@ -31,26 +31,45 @@ export OBJCOPY := $(PREFIX)objcopy
# SOURCES is a list of directories containing source code # SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files # INCLUDES is a list of directories containing extra header files
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
TARGET := $(BIN)/$(notdir $(CURDIR)).mod TARGET := $(notdir $(CURDIR)).mod
BUILD := build BUILD := build
BUILD_DBG := $(TARGET)_dbg
SOURCES := src SOURCES := src
DATA := DATA :=
INCLUDES := src INCLUDES := src
# The name of the assembler listing file to generate.
LIST ?= $(TARGET:.mod=.list)
# The name of the map file to generate.
MAP ?= $(TARGET:.mod=.map) MAP ?= $(TARGET:.mod=.map)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
CFLAGS += -shared -fPIC -Os -Wall -x c -std=c11 -DGEKKO_U -D__wiiu__ -mrvl -mcpu=750 -meabi -mhard-float -fshort-wchar -fno-common -msdata=none -memb -ffunction-sections -fdata-sections
CXXFLAGS += -shared -fPIC -Os -Wall -x c -std=gnu++11 -DGEKKO_U -D__wiiu__ -mrvl -mcpu=750 -meabi -mhard-float -fshort-wchar -fno-common -msdata=none -memb -ffunction-sections -fdata-sections # -fPIC: create position independed code
# -Os: optimise size
# -Wall: generate lots of warnings
# -DGEKKO_U: define the symbol GEKKO (used in some headers)
# -D__wiiu__: define the symbol __wii__ (used in some headers)
# -mrvl: enable wii/gamecube compilation
# -mcpu=750: enable processor specific compilation
# -meabi: enable eabi specific compilation
# -mhard-float: enable hardware floating point instructions
# -fshort-wchar: use 16 bit whcar_t type in keeping with Wii executables
# -fno-common: stop common variables which the loader can't understand
# -msdata-none: do not use r2 or r13 as small data areas
# -memb: enable embedded application specific compilation
# -ffunction-sections: split up functions so linker can garbage collect
# -fdata-sections: split up data so linker can garbage collect
COMMON_CFLAGS += -fPIC -Os -Wall -DGEKKO_U -D__wiiu__ -mrvl -mcpu=750 -meabi -mhard-float -fshort-wchar -fno-common -msdata=none -memb -ffunction-sections -fdata-sections
# -x c: compile as c code
# -std=c11: use the c11 standard
CFLAGS += $(COMMON_CFLAGS) -x c -std=c11
# -x c: compile as c++ code
# -std=gnu++11: use the c++11 standard
CXXFLAGS += $(COMMON_CFLAGS) -x c++ -std=gnu++11
ifeq ($(DO_LOGGING), 1) ifeq ($(DO_LOGGING), 1)
CFLAGS += -D__LOGGING__ CFLAGS += -D__LOGGING__
@ -60,12 +79,18 @@ endif
ASFLAGS := -mregnames ASFLAGS := -mregnames
# --relocatable: make sure ld doesn't remove relocations wups will need # --relocatable: make sure ld doesn't remove relocations wups will need
# -s: strip local symbols to speed linking # -s: strip local symbols to speed linking
# -u: keep certain sections
# -wrap: wrap function
# --gc-sections: remove unneeded symbols # --gc-sections: remove unneeded symbols
# -T: use the linker script specified (to force certain wups sections together) # -T: use the linker script specified (to force certain wups sections together)
# -Map: generate a map file # -Map: generate a map file
LDFLAGS += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \
-Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,--relocatable,--gc-sections LDFLAG_COMMON += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \
LD1FLAGS += --relocatable -s -T $(WUPSDIR)/wups_elf.ld -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,--gc-sections
LDFLAGS_MOD += $(LDFLAG_COMMON),--relocatable
LDFLAGS_ELF += --relocatable -s -T $(WUPSDIR)/wups_elf.ld
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
Q := @ Q := @
MAKEFLAGS += --no-print-directory MAKEFLAGS += --no-print-directory
@ -108,9 +133,9 @@ PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png)))
# use CXX for linking C++ projects, CC for standard C # use CXX for linking C++ projects, CC for standard C
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),) ifeq ($(strip $(CPPFILES)),)
export LD := $(CC) export LD_MOD := $(CC)
else else
export LD := $(CXX) export LD_MOD := $(CXX)
endif endif
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
@ -160,22 +185,18 @@ all : $(OUTPUT)
# Special build rules # Special build rules
# Rule to make the module file. # Rule to make the module file.
$(OUTPUT) : output.elf | $(BIN) $(OUTPUT) : output.elf
$(LOG) @echo "checking for missing symbols ..."
$(LD) $(THIS_DIR)/$(BUILD)/output.elf $(LDFLAGS) $(LIBS) $(LIBPATHS) -o $@ @$(LD_MOD) ../$(BUILD)/output.elf $(LDFLAG_COMMON) $(LIBS) $(LIBPATHS) -o check_linking.elf
@echo "linking ..." $@
@$(LD_MOD) ../$(BUILD)/output.elf $(LDFLAGS_MOD) $(LIBS) $(LIBPATHS) -o $@
# Rule to make the module file. # Rule to make the module file.
output.elf : $(OFILES) | $(BIN) $(BUILD) output.elf : $(OFILES)
$(LOG) @echo "linking ... output.elf"
$(REAL_LD) $(OFILES) $(LD1FLAGS) $(LIBS) $(LIBPATHS) -o $@
# Rule to make intermediate directory
$(BUILD) :
$Qmkdir $@
# Rule to make output directory @$(LD) $(OFILES) $(LDFLAGS_ELF) $(LIBS) $(LIBPATHS) -o $@
$(BIN) :
$Qmkdir $@
############################################################################### ###############################################################################
# Standard build rules # Standard build rules
@ -194,12 +215,12 @@ $(BIN) :
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
%.o: %.c %.o: %.c
@echo $(notdir $<) @echo $(notdir $<)
$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) $(INCLUDE) -c $< -o $@ $(ERROR_FILTER) @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) $(INCLUDE) -c $< -o $@ $(ERROR_FILTER)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
%.o: %.S %.o: %.S
@echo $(notdir $<) @echo $(notdir $<)
$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER) @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
%.png.o : %.png %.png.o : %.png

View File

@ -18,11 +18,11 @@ export GCC_VER := $(shell $(DEVKITPPC)/bin/powerpc-eabi-gcc -dumpversion)
PREFIX := powerpc-eabi- PREFIX := powerpc-eabi-
export AS := $(PREFIX)as export AS := $(PREFIX)as
export CC := $(PREFIX)gcc export CC := $(PREFIX)gcc
export CXX := $(PREFIX)g++ export CXX := $(PREFIX)g++
export REAL_LD := $(PREFIX)ld export LD := $(PREFIX)ld
export AR := $(PREFIX)ar export AR := $(PREFIX)ar
export OBJCOPY := $(PREFIX)objcopy export OBJCOPY := $(PREFIX)objcopy
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
@ -31,26 +31,45 @@ export OBJCOPY := $(PREFIX)objcopy
# SOURCES is a list of directories containing source code # SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files # INCLUDES is a list of directories containing extra header files
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
TARGET := $(BIN)/$(notdir $(CURDIR)).mod TARGET := $(notdir $(CURDIR)).mod
BUILD := build BUILD := build
BUILD_DBG := $(TARGET)_dbg
SOURCES := src SOURCES := src
DATA := DATA :=
INCLUDES := src INCLUDES := src
# The name of the assembler listing file to generate.
LIST ?= $(TARGET:.mod=.list)
# The name of the map file to generate.
MAP ?= $(TARGET:.mod=.map) MAP ?= $(TARGET:.mod=.map)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
CFLAGS += -shared -fPIC -Os -Wall -x c -std=c11 -DGEKKO_U -D__wiiu__ -mrvl -mcpu=750 -meabi -mhard-float -fshort-wchar -fno-common -msdata=none -memb -ffunction-sections -fdata-sections
CXXFLAGS += -shared -fPIC -Os -Wall -x c -std=gnu++11 -DGEKKO_U -D__wiiu__ -mrvl -mcpu=750 -meabi -mhard-float -fshort-wchar -fno-common -msdata=none -memb -ffunction-sections -fdata-sections # -fPIC: create position independed code
# -Os: optimise size
# -Wall: generate lots of warnings
# -DGEKKO_U: define the symbol GEKKO (used in some headers)
# -D__wiiu__: define the symbol __wii__ (used in some headers)
# -mrvl: enable wii/gamecube compilation
# -mcpu=750: enable processor specific compilation
# -meabi: enable eabi specific compilation
# -mhard-float: enable hardware floating point instructions
# -fshort-wchar: use 16 bit whcar_t type in keeping with Wii executables
# -fno-common: stop common variables which the loader can't understand
# -msdata-none: do not use r2 or r13 as small data areas
# -memb: enable embedded application specific compilation
# -ffunction-sections: split up functions so linker can garbage collect
# -fdata-sections: split up data so linker can garbage collect
COMMON_CFLAGS += -fPIC -Os -Wall -DGEKKO_U -D__wiiu__ -mrvl -mcpu=750 -meabi -mhard-float -fshort-wchar -fno-common -msdata=none -memb -ffunction-sections -fdata-sections
# -x c: compile as c code
# -std=c11: use the c11 standard
CFLAGS += $(COMMON_CFLAGS) -x c -std=c11
# -x c: compile as c++ code
# -std=gnu++11: use the c++11 standard
CXXFLAGS += $(COMMON_CFLAGS) -x c++ -std=gnu++11
ifeq ($(DO_LOGGING), 1) ifeq ($(DO_LOGGING), 1)
CFLAGS += -D__LOGGING__ CFLAGS += -D__LOGGING__
@ -60,12 +79,18 @@ endif
ASFLAGS := -mregnames ASFLAGS := -mregnames
# --relocatable: make sure ld doesn't remove relocations wups will need # --relocatable: make sure ld doesn't remove relocations wups will need
# -s: strip local symbols to speed linking # -s: strip local symbols to speed linking
# -u: keep certain sections
# -wrap: wrap function
# --gc-sections: remove unneeded symbols # --gc-sections: remove unneeded symbols
# -T: use the linker script specified (to force certain wups sections together) # -T: use the linker script specified (to force certain wups sections together)
# -Map: generate a map file # -Map: generate a map file
LDFLAGS += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \
-Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,--relocatable,--gc-sections LDFLAG_COMMON += -u wups_load -u wups_meta -u wups_hooks -T $(WUPSDIR)/wups.ld \
LD1FLAGS += --relocatable -s -T $(WUPSDIR)/wups_elf.ld -Wl,-Map,$(notdir $@).map,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size,-wrap,_malloc_r,-wrap,_free_r,-wrap,_realloc_r,-wrap,_calloc_r,-wrap,_memalign_r,-wrap,_malloc_usable_size_r,--gc-sections
LDFLAGS_MOD += $(LDFLAG_COMMON),--relocatable
LDFLAGS_ELF += --relocatable -s -T $(WUPSDIR)/wups_elf.ld
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
Q := @ Q := @
MAKEFLAGS += --no-print-directory MAKEFLAGS += --no-print-directory
@ -108,9 +133,9 @@ PNGFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.png)))
# use CXX for linking C++ projects, CC for standard C # use CXX for linking C++ projects, CC for standard C
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),) ifeq ($(strip $(CPPFILES)),)
export LD := $(CC) export LD_MOD := $(CC)
else else
export LD := $(CXX) export LD_MOD := $(CXX)
endif endif
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
@ -160,22 +185,18 @@ all : $(OUTPUT)
# Special build rules # Special build rules
# Rule to make the module file. # Rule to make the module file.
$(OUTPUT) : output.elf | $(BIN) $(OUTPUT) : output.elf
$(LOG) @echo "checking for missing symbols ..."
$(LD) $(THIS_DIR)/$(BUILD)/output.elf $(LDFLAGS) $(LIBS) $(LIBPATHS) -o $@ @$(LD_MOD) ../$(BUILD)/output.elf $(LDFLAG_COMMON) $(LIBS) $(LIBPATHS) -o check_linking.elf
@echo "linking ..." $@
@$(LD_MOD) ../$(BUILD)/output.elf $(LDFLAGS_MOD) $(LIBS) $(LIBPATHS) -o $@
# Rule to make the module file. # Rule to make the module file.
output.elf : $(OFILES) | $(BIN) $(BUILD) output.elf : $(OFILES)
$(LOG) @echo "linking ... output.elf"
$(REAL_LD) $(OFILES) $(LD1FLAGS) $(LIBS) $(LIBPATHS) -o $@
# Rule to make intermediate directory
$(BUILD) :
$Qmkdir $@
# Rule to make output directory @$(LD) $(OFILES) $(LDFLAGS_ELF) $(LIBS) $(LIBPATHS) -o $@
$(BIN) :
$Qmkdir $@
############################################################################### ###############################################################################
# Standard build rules # Standard build rules
@ -194,12 +215,12 @@ $(BIN) :
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
%.o: %.c %.o: %.c
@echo $(notdir $<) @echo $(notdir $<)
$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) $(INCLUDE) -c $< -o $@ $(ERROR_FILTER) @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d $(CFLAGS) $(INCLUDE) -c $< -o $@ $(ERROR_FILTER)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
%.o: %.S %.o: %.S
@echo $(notdir $<) @echo $(notdir $<)
$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER) @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
%.png.o : %.png %.png.o : %.png

View File

@ -5,7 +5,7 @@ SECTIONS {
.wups.load : { .wups.load : {
*(.wups.load*) *(.wups.load*)
} }
.wups.hooks : { .wups.hooks : {
*(.wups.hooks*) *(.wups.hooks*)
} }
.text : { .text : {
@ -14,7 +14,7 @@ SECTIONS {
.sdata : { .sdata : {
*(.sdata*) *(.sdata*)
} }
.data : { .data : {
*(.data*) *(.data*)
} }
.rodata : { .rodata : {