Fix plugin to be compatible with the new loader

This commit is contained in:
Maschell 2018-06-28 23:34:05 +02:00
parent aba1adcbb1
commit 0df6c595f0
2 changed files with 55 additions and 83 deletions

View File

@ -33,7 +33,7 @@ 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 := $(notdir $(CURDIR)).mod TARGET := $(notdir $(CURDIR))
BUILD := build BUILD := build
ifeq ($(notdir $(CURDIR)),$(BUILD)) ifeq ($(notdir $(CURDIR)),$(BUILD))
@ -44,6 +44,7 @@ endif
include $(WUPSDIR)/plugin_makefile.mk include $(WUPSDIR)/plugin_makefile.mk
#MAP ?= $(TARGET:.mod=.map) #MAP ?= $(TARGET:.mod=.map)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
@ -52,58 +53,69 @@ include $(WUPSDIR)/plugin_makefile.mk
# -Os: optimise size # -Os: optimise size
# -Wall: generate lots of warnings # -Wall: generate lots of warnings
# -DGEKKO_U: define the symbol GEKKO (used in some headers)
# -D__wiiu__: define the symbol __wiiu__ (used in some headers) # -D__wiiu__: define the symbol __wiiu__ (used in some headers)
# -mcpu=750: enable processor specific compilation # -mcpu=750: enable processor specific compilation
# -meabi: enable eabi specific compilation # -meabi: enable eabi specific compilation
# -mhard-float: enable hardware floating point instructions # -mhard-float: enable hardware floating point instructions
# -fno-common: stop common variables which the loader can't understand # -nostartfiles: Do not use the standard system startup files when linking
# -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 # -ffunction-sections: split up functions so linker can garbage collect
# -fdata-sections: split up data so linker can garbage collect # -fdata-sections: split up data so linker can garbage collect
COMMON_CFLAGS += -Os -Wall -DGEKKO_U -D__wiiu__ -D__WIIU__ -mrvl -mcpu=750 -meabi -mhard-float -fno-common -msdata=none -memb -ffunction-sections -fdata-sections COMMON_CFLAGS := -Os -Wall -mcpu=750 -meabi -mhard-float -D__WIIU__ -nostartfiles -ffunction-sections -fdata-sections -Wl,-q $(COMMON_CFLAGS)
# -x c: compile as c code # -x c: compile as c code
# -std=c11: use the c11 standard # -std=c11: use the c11 standard
CFLAGS += $(COMMON_CFLAGS) -x c -std=gnu11 CFLAGS := $(COMMON_CFLAGS) -x c -std=gnu11 $(CFLAGS)
# -x c: compile as c++ code # -x c: compile as c++ code
# -std=gnu++11: use the c++11 standard # -std=gnu++11: use the c++11 standard
CXXFLAGS += $(COMMON_CFLAGS) -x c++ -std=gnu++11 CXXFLAGS := $(COMMON_CFLAGS) -x c++ -std=gnu++11 $(CXXFLAGS)
ifeq ($(DO_LOGGING), 1) ifeq ($(DO_LOGGING), 1)
CFLAGS += -D__LOGGING__ CFLAGS += -D__LOGGING__
CXXFLAGS += -D__LOGGING__ CXXFLAGS += -D__LOGGING__
endif endif
ADD_NO_WHOLE_ARCHIVE := 0 #---------------------------------------------------------------------------------
# any extra ld flags
#--------------------------------------------------------------------------------
# --gc-sections: remove unneeded symbols
# -Map: generate a map file
LDFLAGS += -Wl,-Map,$(notdir $@).map,--gc-sections
#---------------------------------------------------------------------------------
Q := @
MAKEFLAGS += --no-print-directory
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS +=
#
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS +=
NEEDS_WUT := 0
ifeq ($(WUT_ENABLE_CPP), 1) ifeq ($(WUT_ENABLE_CPP), 1)
WUT_ENABLE_NEWLIB := 1 WUT_ENABLE_NEWLIB := 1
LD_FLAGS_ELF += -whole-archive -lwutstdc++ LDFLAGS += -Wl,-whole-archive,-lwutstdc++,-no-whole-archive
ADD_NO_WHOLE_ARCHIVE := 1
NEEDS_WUT := 1 NEEDS_WUT := 1
endif endif
ifeq ($(WUT_ENABLE_NEWLIB), 1) ifeq ($(WUT_ENABLE_NEWLIB), 1)
LD_FLAGS_ELF += -whole-archive -lwutnewlib LDFLAGS += -Wl,-whole-archive,-lwutnewlib,-no-whole-archive
ADD_NO_WHOLE_ARCHIVE := 1
NEEDS_WUT := 1 NEEDS_WUT := 1
endif endif
ifeq ($(WUT_DEFAULT_MALLOC), 1) ifeq ($(WUT_DEFAULT_MALLOC), 1)
LD_FLAGS_ELF += -whole-archive -lwutmalloc LDFLAGS += -Wl,-whole-archive,-lwutmalloc,-no-whole-archive
ADD_NO_WHOLE_ARCHIVE := 1
NEEDS_WUT := 1 NEEDS_WUT := 1
endif endif
ifeq ($(ADD_NO_WHOLE_ARCHIVE), 1)
LD_FLAGS_ELF += -no-whole-archive
endif
ifeq ($(NEEDS_WUT), 1) ifeq ($(NEEDS_WUT), 1)
ifeq ($(strip $(WUT_ROOT)),) ifeq ($(strip $(WUT_ROOT)),)
$(error "Please set WUT_ROOT in your environment. export WUT_ROOT=<path to>wut) $(error "Please set WUT_ROOT in your environment. export WUT_ROOT=<path to>wut)
@ -112,32 +124,6 @@ ifeq ($(NEEDS_WUT), 1)
CXXFLAGS += -D__WUT__ CXXFLAGS += -D__WUT__
endif endif
ASFLAGS +=
LDFLAG_COMMON +=
ifeq ($(WRAP_MALLOC), 1)
LDFLAG_COMMON += -Wl,-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
endif
LDFLAGS_MOD += $(LD_FLAGS_MOD)
LDFLAGS_ELF += $(LD_FLAGS_ELF)
#---------------------------------------------------------------------------------
Q := @
MAKEFLAGS += --no-print-directory
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
ALL_LIBS := $(LIBS)
#
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS +=
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional # no real need to edit anything past this point unless you need to add additional
# rules for different file extensions # rules for different file extensions
@ -165,9 +151,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_MOD := $(CC) export REAL_LD := $(CC)
else else
export LD_MOD := $(CXX) export REAL_LD := $(CXX)
endif endif
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
@ -199,7 +185,7 @@ $(BUILD):
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
clean: clean:
@echo clean ... @echo clean ...
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin $(BUILD_DBG).elf $(OUTPUT) @rm -fr $(BUILD) $(OUTPUT).mod $(OUTPUT)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
else else
@ -216,17 +202,11 @@ all : $(OUTPUT)
############################################################################### ###############################################################################
# Special build rules # Special build rules
# Rule to make the module file.
$(OUTPUT) : output.elf
@echo "checking for missing symbols ..."
@$(LD_MOD) ../$(BUILD)/output.elf $(LDFLAG_COMMON) $(LD_FLAGS_MOD) $(ALL_LIBS) $(LIBPATHS_FULL) -o check_linking.elf
@echo "linking ..." $@
@$(LD_MOD) ../$(BUILD)/output.elf $(LDFLAG_COMMON) $(LDFLAGS_MOD) $(ALL_LIBS) $(LIBPATHS_FULL) -o $@
# Rule to make the module file. # Rule to make the module file.
output.elf : $(OFILES) $(OUTPUT) : $(OFILES)
@echo "linking ... output.elf" @echo "linking ... " $@
@$(LD) $(OFILES) $(LDFLAGS_ELF) $(ALL_LIBS) $(LIBPATHS_FULL) -o $@ @$(REAL_LD) $(OFILES) $(LDFLAGS) $(LIBS) $(LIBPATHS_FULL) -o $@
############################################################################### ###############################################################################
# Standard build rules # Standard build rules
@ -250,7 +230,7 @@ output.elf : $(OFILES)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
%.o: %.S %.o: %.S
@echo $(notdir $<) @echo $(notdir $<)
@$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(INCLUDE_FULL) -c $< -o $@ $(ERROR_FILTER) $(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(INCLUDE_FULL) -c $< -o $@ $(ERROR_FILTER)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
%.png.o : %.png %.png.o : %.png

View File

@ -1,12 +1,6 @@
# Compiling the projects with libutils logging code? # Compiling the projects with libutils logging code?
DO_LOGGING := 1 DO_LOGGING := 1
# Non WUT plugins need to wrap the malloc functions.
WRAP_MALLOC := 0
# Sets the "-D__WUT__" compiling flag
USE_WUT := 1
# Links against the wut implementation of newlib, this is useful for using any function # Links against the wut implementation of newlib, this is useful for using any function
# from the C standard library # from the C standard library
WUT_ENABLE_NEWLIB := 0 WUT_ENABLE_NEWLIB := 0
@ -36,16 +30,14 @@ INCLUDES := src
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation and linking # options for code generation and linking
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# Extra C AND C++ compiler flags
COMMON_CFLAGS :=
# Extra C compiler flags # Extra C compiler flags
CFLAGS := CFLAGS :=
# Extra C++ compiler flags # Extra C++ compiler flags
CXXFLAGS := CXXFLAGS :=
# Extra linking flags for all linking steps # Extra linking flags for all linking steps
LD_FLAGS := LDFLAGS :=
# extra linking flags for linking the temporarily elf file (using ld)
LD_FLAGS_ELF :=
# extra linking flags for linking the final mod file (using gcc/g++)
LD_FLAGS_MOD :=
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing # list of directories containing libraries, this must be the top level containing
@ -56,7 +48,7 @@ LIBDIRS := $(WUPSDIR) $(WUT_ROOT)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project # any extra libraries we wish to link with the project
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
LIBS := -lwups -lutilswut -lcontrollerpatcherwut -lcoreinit -lnsysnet -lnsyshid -lvpadbase LIBS := -lwups -lcontrollerpatcherwut -lutilswut -lcoreinit -lnsysnet -lnsyshid -lvpadbase
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# Will be added to the final lib paths # Will be added to the final lib paths