From: John Hodge Date: Sat, 31 May 2014 05:38:30 +0000 (+0800) Subject: BuildConf - Switch to OS specific cross-compiler (instead of bare) X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=2bf08f0eb3461218cc493ef458fe100ae9158f28;p=tpg%2Facess2.git BuildConf - Switch to OS specific cross-compiler (instead of bare) --- diff --git a/BuildConf/x86/Makefile.cfg b/BuildConf/x86/Makefile.cfg index 3989363a..271059c8 100644 --- a/BuildConf/x86/Makefile.cfg +++ b/BuildConf/x86/Makefile.cfg @@ -2,15 +2,8 @@ # Acess2 Build Configuration # -CC = i686-elf-gcc -CXX = i686-elf-g++ -#CC = clang -m32 -LD = i686-elf-ld -#CC = gcc -#LD = ld +TRIPLET = i686-pc-acess2 AS = nasm -#OBJDUMP = i686-elf-objdump -OBJDUMP = objdump RM = @rm -f STRIP = strip diff --git a/Usermode/Applications/Makefile.cfg b/Usermode/Applications/Makefile.cfg index e1703297..72611452 100644 --- a/Usermode/Applications/Makefile.cfg +++ b/Usermode/Applications/Makefile.cfg @@ -7,26 +7,24 @@ include $(_appsdir)../Makefile.cfg ifeq ($(ARCHDIR),native) ASFLAGS = -felf - CPPFLAGS = -Wall - CFLAGS = $(CPPFLAGS) - LDFLAGS = -L $(OUTPUTDIR)Libs -lacess-native -lc_acess + LDFLAGS = -L $(OUTPUTDIR)Libs + LIBS := -lacess-native -lc_acess #LIBGCC_PATH = $(ACESSDIR)/AcessNative/symbol_renames.ld else ASFLAGS = -felf - CPPFLAGS = -ffreestanding - CFLAGS = -fno-stack-protector -fno-builtin $(CPPFLAGS) -Wall - LDFLAGS = -T $(OUTPUTDIR)Libs/acess.ld -L $(OUTPUTDIR)Libs -I /Acess/Libs/ld-acess.so -lld-acess -lc $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crtend.o -lposix - LIBGCC_PATH = $(shell $(CC) -print-libgcc-file-name) +# LDFLAGS = -T $(OUTPUTDIR)Libs/acess.ld + LDFLAGS = -L $(OUTPUTDIR)Libs + LIBS = -lld-acess endif --include $(_appsdir)../common_settings.mk LDFLAGS += -rpath-link $(OUTPUTDIR)Libs CXXFLAGS += -std=gnu++11 +CPPFLAGS += +CFLAGS += -Wall + +-include $(_appsdir)../common_settings.mk # Extra-verbose errors! #CFLAGS += -Wall -Wextra -Wwrite-strings -Wshadow -Wswitch-default -Wswitch-enum -Wstrict-overflow=5 -Wfloat-equal -Wundef -Wmissing-declarations -Wlogical-op -Wformat=2 -Winit-self -Wmissing-include-dirs -Wswitch-default -Wswitch-enum -Wsync-nand -Wunused -Wstrict-overflow=5 -Wfloat-equal -Wundef -Wno-endif-labels -Wshadow -Wunsafe-loop-optimizations -Wbad-function-cast -Wc++-compat -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-declarations -Wnormalized=nfc -Wpacked -Wpadded -Wredundant-decls -Wnested-externs -Winline -Winvalid-pch -Wdisabled-optimization -Woverlength-strings -CRTBEGIN = $(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o) -CRTEND = $(shell $(CC) $(CFLAGS) -print-file-name=crtend.o) - DIR = Bin diff --git a/Usermode/Applications/Makefile.tpl b/Usermode/Applications/Makefile.tpl index 2b645af6..9cc0753b 100644 --- a/Usermode/Applications/Makefile.tpl +++ b/Usermode/Applications/Makefile.tpl @@ -3,21 +3,20 @@ # - Application Template Makefile # -CFLAGS += -g -LDFLAGS += -g - -LDFLAGS += -Map $(_OBJPREFIX)Map.txt - -ifneq ($(lastword $(subst -, ,$(basename $(LD)))),ld) - comma=, - LDFLAGS := $(subst -rpath-link ,-Wl$(comma)-rpath-link$(comma),$(LDFLAGS)) - LDFLAGS := $(subst -Map ,-Wl$(comma)-Map$(comma),$(LDFLAGS)) -endif +CFLAGS += -g +CXXFLAGS += -g +LDFLAGS += -g _BIN := $(OUTPUTDIR)$(DIR)/$(BIN) _OBJPREFIX := obj-$(ARCH)/ -_LIBS := $(filter -l%,$(LDFLAGS)) +LDFLAGS += -Map $(_OBJPREFIX)Map.txt + +comma=, +LDFLAGS := $(subst -rpath-link ,-Wl$(comma)-rpath-link$(comma),$(LDFLAGS)) +LDFLAGS := $(subst -Map ,-Wl$(comma)-Map$(comma),$(LDFLAGS)) + +_LIBS := $(filter -l%,$(LIBS)) _LIBS := $(patsubst -l%,$(OUTPUTDIR)Libs/lib%.so,$(_LIBS)) ifeq ($(VERBOSE),) @@ -28,6 +27,9 @@ endif OBJ := $(addprefix $(_OBJPREFIX),$(OBJ)) +#LINK_OBJS := $(CRTI) $(CRTBEGIN) $(CRT0) $(OBJ) $(LIBGCC_PATH) $(CRTEND) $(CRTN) +LINK_OBJS := $(OBJ) + DEPFILES := $(OBJ:%.o=%.dep) .PHONY : all clean install @@ -45,10 +47,14 @@ install: $(_BIN) @$(xCP) $(_BIN)_ $(DISTROOT)/$(DIR)/$(BIN) @$(RM) $(_BIN)_ -$(_BIN): $(OUTPUTDIR)Libs/acess.ld $(OUTPUTDIR)Libs/crt0.o $(_LIBS) $(OBJ) +$(_BIN): $(OUTPUTDIR)Libs/acess.ld $(_LIBS) $(LINK_OBJS) @mkdir -p $(dir $(_BIN)) @echo [LD] -o $@ - $V$(LD) -g $(LDFLAGS) -o $@ $(CRTBEGIN) $(OBJ) $(LIBGCC_PATH) $(CRTEND) +ifneq ($(USE_CXX_LINK),) + $V$(CXX) -g $(LDFLAGS) -o $(_BIN) $(LINK_OBJS) $(LIBS) +else + $V$(CC) -g $(LDFLAGS) -o $(_BIN) $(LINK_OBJS) $(LIBS) +endif $V$(DISASM) $(_BIN) > $(_OBJPREFIX)$(BIN).dsm $(_OBJPREFIX)%.o: %.c diff --git a/Usermode/Libraries/Makefile.cfg b/Usermode/Libraries/Makefile.cfg index 113e65c8..b10117e4 100644 --- a/Usermode/Libraries/Makefile.cfg +++ b/Usermode/Libraries/Makefile.cfg @@ -4,11 +4,14 @@ _libsdir := $(dir $(lastword $(MAKEFILE_LIST))) -include $(_libsdir)../Makefile.cfg +USE_CXX_LINK := +PRELINK := MAKEDEP = $(CC) -M ifeq ($(ARCHDIR),native) ASFLAGS += -D ARCHDIR=$(ARCHDIR) -D __ASSEMBLER__=1 - LDFLAGS := -lacess-native + LDFLAGS := + LIBS := -lacess-native #CPPFLAGS := -D SoMain="__attribute__ ((constructor(101))) libacessnative_init" ifeq ($(PLATFORM),windows) else @@ -26,14 +29,16 @@ else ifneq ($(HOST_ARCH),) CFLAGS += -fPIC CXXFLAGS += -fPIC endif + LIBS := -lld-acess else - CPPFLAGS := -ffreestanding CFLAGS := -fno-stack-protector -fPIC - CXXFLAGS := -fno-stack-protector -fPIC - LDFLAGS := -I/Acess/Libs/ld-acess.so -lld-acess `$(CC) -print-libgcc-file-name` + CXXFLAGS := -fno-stack-protector -fPIC + LDFLAGS := + LIBS := -lld-acess endif -LDFLAGS += -g -nostdlib -shared -eSoMain -x --no-undefined -L$(OUTPUTDIR)Libs/ --defsym __dso_handle=SoMain +LDFLAGS += -g -shared -eSoStart -L$(OUTPUTDIR)Libs/ --no-undefined CXXFLAGS += -std=gnu++11 +#CPPFLAGS += -D 'SoMain(...)=SoMain(__VA_ARGS__) __attribute__ ((visibility ("hidden"))); int SoMain(__VA_ARGS__)' -include $(_libsdir)../common_settings.mk diff --git a/Usermode/Libraries/Makefile.tpl b/Usermode/Libraries/Makefile.tpl index 27de5f67..530b585f 100644 --- a/Usermode/Libraries/Makefile.tpl +++ b/Usermode/Libraries/Makefile.tpl @@ -10,17 +10,16 @@ ifeq ($(ARCH),native) LDFLAGS := $(LDFLAGS:-lc=-lc_acess) endif -_LD_CMD := $(lastword $(subst -, ,$(firstword $(LD)))) -ifneq ($(_LD_CMD),ld) - LDFLAGS := $(subst -soname ,-Wl$(comma)-soname$(comma),$(LDFLAGS)) - LDFLAGS := $(subst -Map ,-Wl$(comma)-Map$(comma),$(LDFLAGS)) - LDFLAGS := $(LDFLAGS:-x=-Wl,-x) - LDFLAGS := $(LDFLAGS:--%=-Wl,--%) -endif - _BIN := $(addprefix $(OUTPUTDIR)Libs/,$(BIN)) _XBIN := $(addprefix $(OUTPUTDIR)Libs/,$(EXTRABIN)) _OBJPREFIX := obj-$(ARCH)/ +LDFLAGS += -Map $(_OBJPREFIX)Map.txt + +_LD_CMD := $(lastword $(subst -, ,$(firstword $(LD)))) +LDFLAGS := $(subst -soname ,-Wl$(comma)-soname$(comma),$(LDFLAGS)) +LDFLAGS := $(subst -Map ,-Wl$(comma)-Map$(comma),$(LDFLAGS)) +LDFLAGS := $(LDFLAGS:-x=-Wl,-x) +LDFLAGS := $(LDFLAGS:--%=-Wl,--%) _LIBS := $(filter -l%,$(LDFLAGS)) _LIBS := $(patsubst -l%,$(OUTPUTDIR)Libs/lib%.so,$(_LIBS)) @@ -84,28 +83,33 @@ endif # for f in $(INCFILES); do ln -s $f $(ACESSDIR)/include/$f; done #endif -$(_BIN): $(OBJ) +LINK_OBJS = $(PRELINK) $(OBJ) +$(_BIN): $(LINK_OBJS) @mkdir -p $(dir $(_BIN)) @echo [LD] -o $(BIN) $(OBJ) - $V$(LD) $(LDFLAGS) -o $(_BIN) $(OBJ) $(shell $(CC) -print-libgcc-file-name) - $V$(DISASM) -D -S $(_BIN) > $(_OBJPREFIX)$(BIN).dsm +ifneq ($(USE_CXX_LINK),) + $V$(CXX) $(LDFLAGS) -o $(_BIN) $(LINK_OBJS) $(LIBS) +else + $V$(CC) $(LDFLAGS) -o $(_BIN) $(LINK_OBJS) $(LIBS) +endif + $V$(DISASM) -C $(_BIN) > $(_OBJPREFIX)$(BIN).dsm -$(_OBJPREFIX)%.o: %.c +$(_OBJPREFIX)%.o: %.c Makefile @echo [CC] -o $@ @mkdir -p $(dir $@) $V$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $< -MMD -MP -MT $@ -MF $@.dep -$(_OBJPREFIX)%.o: %.cc +$(_OBJPREFIX)%.o: %.cc Makefile @echo [CXX] -o $@ @mkdir -p $(dir $@) $V$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ -c $< -MMD -MP -MT $@ -MF $@.dep -$(_OBJPREFIX)%.o: %.cpp +$(_OBJPREFIX)%.o: %.cpp Makefile @echo [CXX] -o $@ @mkdir -p $(dir $@) $V$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ -c $< -MMD -MP -MT $@ -MF $@.dep -$(_OBJPREFIX)%.ao: %.$(ASSUFFIX) +$(_OBJPREFIX)%.ao: %.$(ASSUFFIX) Makefile @echo [AS] -o $@ @mkdir -p $(dir $@) $V$(AS) $(ASFLAGS) -o $@ $< diff --git a/Usermode/common_settings.mk b/Usermode/common_settings.mk index 519b0fd3..639cab17 100644 --- a/Usermode/common_settings.mk +++ b/Usermode/common_settings.mk @@ -5,3 +5,11 @@ CPPFLAGS += -I$(ACESSUSERDIR)/include/ -DARCHDIR_is_$(ARCHDIR) CPPFLAGS += -I $(ACESSDIR)/Externals/Output/$(ARCHDIR)/include CFLAGS += -std=gnu99 -g LDFLAGS += -L $(ACESSDIR)/Externals/Output/$(ARCHDIR)/lib + +CRTI := $(OUTPUTDIR)Libs/crti.o +CRTBEGIN := $(shell $(CC) $(CFLAGS) -print-file-name=crtbegin.o) +CRT0 := $(OUTPUTDIR)Libs/crt0.o +CRT0S := $(OUTPUTDIR)Libs/crt0S.o +CRTEND := $(shell $(CC) $(CFLAGS) -print-file-name=crtend.o) +CRTN := $(OUTPUTDIR)Libs/crtn.o +LIBGCC_PATH = $(shell $(CC) -print-libgcc-file-name)