From 418a36e6775d0b8e2209571e59d57e831342d146 Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 7 Jan 2019 06:02:19 -0500 Subject: project: added object-generation rules for shared/static/crt/ldso-objs. --- project/common.mk | 123 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 109 insertions(+), 14 deletions(-) (limited to 'project') diff --git a/project/common.mk b/project/common.mk index d5de244..e414247 100644 --- a/project/common.mk +++ b/project/common.mk @@ -15,27 +15,23 @@ libc_src_merged = $(subst $(SOURCE_DIR)/,./, \ $(subst $(PROJECT_DIR)/,./, \ $(libc_src_sorted))) -libc_arch_dirs = $(wildcard $(addsuffix $(ARCH)/, $(libc_src_dirs))) +libc_arch_dirs = $(sort $(wildcard $(addsuffix $(ARCH)/, $(libc_src_dirs)))) -libc_arch_files_c = $(wildcard $(addsuffix *.c,$(libc_arch_dirs))) -libc_arch_files_s = $(wildcard $(addsuffix *.s,$(libc_arch_dirs))) -libc_arch_files_S = $(wildcard $(addsuffix *.S,$(libc_arch_dirs))) +libc_arch_files_c = $(subst $(PORT_DIR)/,./,$(wildcard $(addsuffix *.c,$(libc_arch_dirs)))) +libc_arch_files_s = $(subst $(PORT_DIR)/,./,$(wildcard $(addsuffix *.s,$(libc_arch_dirs)))) +libc_arch_files_S = $(subst $(PORT_DIR)/,./,$(wildcard $(addsuffix *.S,$(libc_arch_dirs)))) -libc_arch_files = $(subst $(SOURCE_DIR)/,./, \ - $(subst $(PROJECT_DIR)/,./, \ - $(libc_arch_files_c) \ - $(libc_arch_files_s) \ - $(libc_arch_files_S))) +libc_arch_files = $(libc_arch_files_c) \ + $(libc_arch_files_s) \ + $(libc_arch_files_S) libc_arch_substs_c = $(subst /$(ARCH)/,/,$(libc_arch_files_c)) libc_arch_substs_s = $(subst /$(ARCH)/,/,$(libc_arch_files_s)) libc_arch_substs_S = $(subst /$(ARCH)/,/,$(libc_arch_files_S)) -libc_arch_substs = $(subst $(SOURCE_DIR)/,./, \ - $(subst $(PROJECT_DIR)/,./, \ - $(libc_arch_substs_c) \ - $(libc_arch_substs_s:%.s=%.c) \ - $(libc_arch_substs_S:%.S=%.c))) +libc_arch_substs = $(libc_arch_substs_c) \ + $(libc_arch_substs_s:%.s=%.c) \ + $(libc_arch_substs_S:%.S=%.c) libc_pure_files = $(filter-out $(libc_arch_substs), $(libc_src_merged)) libc_all_files = $(libc_pure_files) $(libc_arch_files) @@ -68,3 +64,102 @@ libc_tree_dirs = $(subst $(SOURCE_DIR)/,./, \ libc_tree_dirs += ./crt/ ./crt/$(ARCH)/ libc_tree_dirs += ./ldso/ ./ldso/$(ARCH)/ + + +# core objects +STATIC_OBJS += $(libc_core_files_c:%.c=%.o) +STATIC_OBJS += $(libc_core_files_s:%.s=%.o) +STATIC_OBJS += $(libc_core_files_S:%.S=%.o) + +SHARED_OBJS += $(libc_core_files_c:%.c=%.lo) +SHARED_OBJS += $(libc_core_files_s:%.s=%.lo) +SHARED_OBJS += $(libc_core_files_S:%.S=%.lo) + +$(STATIC_OBJS): headers.tag host.tag tree.tag +$(SHARED_OBJS): headers.tag host.tag tree.tag + +$(SHARED_OBJS): CFLAGS_SHARED += -DSHARED= + +src/%.o:$(PORT_DIR)/src/%.c + $(CC) -c -o $@ $< $(CFLAGS_STATIC) + +src/%.o:$(PORT_DIR)/src/%.s + $(AS) -o $@ $< + +src/%.o:$(PORT_DIR)/src/%.S + $(CC) -c -o $@ $< $(CFLAGS_STATIC) + +src/%.lo:$(PORT_DIR)/src/%.c + $(CC) -c -o $@ $< $(CFLAGS_SHARED) + +src/%.lo:$(PORT_DIR)/src/%.s + $(AS) -o $@ $< + +src/%.lo:$(PORT_DIR)/src/%.S + $(CC) -c -o $@ $< $(CFLAGS_SHARED) + + +# crt objects +CRT_OBJS += $(libc_crt_files_c:%.c=%.o) +CRT_OBJS += $(libc_crt_files_s:%.s=%.o) +CRT_OBJS += $(libc_crt_files_S:%.S=%.o) + +$(CRT_OBJS): headers.tag host.tag tree.tag +$(CRT_OBJS): CFLAGS_CONFIG += -DCRT + +./crt/Scrt1.o: CFLAGS_CONFIG += -fPIC +./crt/rcrt1.o: CFLAGS_CONFIG += -fPIC + +crt/%.o:$(PORT_DIR)/crt/%.c + $(CC) -c -o $@ $< $(CFLAGS_STATIC) + +crt/%.o:$(PORT_DIR)/crt/%.s + $(AS) -o $@ $< + +crt/%.o:$(PORT_DIR)/crt/%.S + $(CC) -c -o $@ $< $(CFLAGS_STATIC) + +crt/%.o:$(SOURCE_DIR)/crt/%.c + $(CC) -c -o $@ $< $(CFLAGS_STATIC) + +crt-objs: $(CRT_OBJS) +shared-lib:$(CRT_OBJS) +static-lib:$(CRT_OBJS) + +clean-crt-objs: + rm -f $(CRT_OBJS) + +clean: clean-crt-objs + +.PHONY: crt-objs clean-crt-objs + + +# ldso objects +LDSO_OBJS += $(libc_ldso_files_c:%.c=%.lo) +LDSO_OBJS += $(libc_ldso_files_s:%.s=%.lo) +LDSO_OBJS += $(libc_ldso_files_S:%.S=%.lo) + +$(LDSO_OBJS): headers.tag host.tag tree.tag + +$(LDSO_OBJS): CFLAGS_SHARED += -DSHARED= + +ldso/%.lo:$(PORT_DIR)/ldso/%.c + $(CC) -c -o $@ $< $(CFLAGS_SHARED) + +ldso/%.lo:$(PORT_DIR)/ldso/%.s + $(AS) -o $@ $< + +ldso/%.lo:$(PORT_DIR)/ldso/%.S + $(CC) -c -o $@ $< $(CFLAGS_SHARED) + +ldso/%.lo:$(SOURCE_DIR)/ldso/%.c + $(CC) -c -o $@ $< $(CFLAGS_SHARED) + +ldso-objs:$(LDSO_OBJS) + +clean-ldso-objs: + rm -f $(LDSO_OBJS) + +clean: clean-ldso-objs + +.PHONY: ldso-objs clean-ldso-objs -- cgit v1.2.3