diff options
Diffstat (limited to 'Makerules')
| -rw-r--r-- | Makerules | 231 |
1 files changed, 176 insertions, 55 deletions
@@ -4,6 +4,13 @@ .SUFFIXES: .c .S .o .os .oS .so .a .s .i +PHONY := FORCE + +.PHONY: dummy $(PHONY) \ + all check clean realclean distclean test \ + config dist menuconfig oldconfig release \ + subdirs utils + # order is important, the stripping uses STRIP_FLAGS for lib-so, but not for lib-a ifeq ($(HAVE_SHARED),y) .LIBPATTERNS: "lib%.so" @@ -18,14 +25,22 @@ libs: $(lib-a-y) endif objs: all_objs -shared_objs = $(ldso-y) $(libc-y:.o=.os) $(libc-shared-y) $(libc-nonshared-y) $(libdl-so-y) -shared_objs += $(libcrypt-so-y) $(libintl-so-y) $(libm-so-y) $(libnsl-so-y) $(libpthread-so-y) $(libpthread-nonshared-y) -shared_objs += $(libthread_db-so-y) $(libresolv-so-y) $(librt-so-y) $(libutil-so-y) -ar_objs = $(libc-y) $(libc-static-y) $(libdl-a-y) $(libcrypt-a-y) $(libintl-a-y) $(libm-a-y) $(libnsl-a-y) -ar_objs += $(libpthread-a-y) $(libthread_db-a-y) $(libresolv-a-y) $(librt-a-y) $(libutil-a-y) +shared_objs = $(libc-y:.o=.os) $(libc-shared-y) $(libc-nonshared-y) \ + $(libcrypt-so-y) $(libdl-so-y) \ + $(libintl-so-y) $(libm-so-y) $(libnsl-so-y) \ + $(libpthread-so-y) $(libpthread-nonshared-y) $(libthread_db-so-y) \ + $(libresolv-so-y) $(librt-so-y) \ + $(ldso-y) \ + $(libutil-so-y) + +ar_objs = $(libc-y) $(libc-static-y) $(libcrypt-a-y) \ + $(libdl-a-y) $(libintl-a-y) $(libm-a-y) $(libnsl-a-y) \ + $(libpthread-a-y) $(libthread_db-a-y) \ + $(libresolv-a-y) $(librt-a-y) $(libutil-a-y) ifeq ($(DOPIC),y) ar_objs := $(ar_objs:.o=.os) endif +flat_objs = $(lib-gdb-y) ifeq ($(HAVE_SHARED),y) all_objs: $(sort $(shared_objs) $(ar_objs)) @@ -50,7 +65,7 @@ SECHO := @echo ifneq ($(V)$(VERBOSE),) SHELL_SET_X := set -x DISP := ver -Q := +Q := else DISP := pur Q := @ @@ -60,6 +75,9 @@ endif show_objs = $(subst ../,,$@) pur_disp_compile.c = echo " "CC $(show_objs) +pur_disp_compile.i = echo " "CPP $(show_objs) +pur_disp_compile.s = echo " "CC-S $(show_objs) +pur_disp_compile.u = echo " "CC $(show_objs) pur_disp_compile.S = echo " "AS $(show_objs) pur_disp_compile.m = $(pur_disp_compile.c) pur_disp_compile-m = echo " "CC-m $(show_objs) @@ -67,8 +85,15 @@ pur_disp_strip = echo " "STRIP $(STRIP_FLAGS) $@ pur_disp_t_strip = echo " "STRIP $(STRIP_FLAGS) $@ pur_disp_ar = echo " "AR $(ARFLAGS) $@ pur_disp_ld = echo " "LD $(1) +pur_disp_ln = echo " "LN $@ +pur_disp_mkdir = echo " "MKDIR $@ +pur_disp_gen = echo " "GEN $@ +pur_disp_unifdef = echo " "UNIFDEF $@ sil_disp_compile.c = true +sil_disp_compile.i = true +sil_disp_compile.s = true +sil_disp_compile.u = true sil_disp_compile.S = true sil_disp_compile.m = true sil_disp_compile-m = true @@ -76,17 +101,31 @@ sil_disp_strip = true sil_disp_t_strip = true sil_disp_ar = true sil_disp_ld = true +sil_disp_ln = true +sil_disp_mkdir = true +sil_disp_gen = true +sil_disp_unifdef = true ver_disp_compile.c = echo $(cmd_compile.c) +ver_disp_compile.i = echo $(cmd_compile.i) +ver_disp_compile.s = echo $(cmd_compile.s) +ver_disp_compile.u = echo $(cmd_compile.u) ver_disp_compile.S = echo $(cmd_compile.S) ver_disp_compile.m = echo $(cmd_compile.m) ver_disp_compile-m = echo $(cmd_compile-m) ver_disp_strip = echo $(cmd_strip) ver_disp_t_strip = echo $(cmd_t_strip) ver_disp_ar = echo $(cmd_ar) -ver_disp_ld = +ver_disp_ld = +ver_disp_ln = +ver_disp_mkdir = +ver_disp_gen = +ver_disp_unifdef = echo $(cmd_unifdef) disp_compile.c = $($(DISP)_disp_compile.c) +disp_compile.i = $($(DISP)_disp_compile.i) +disp_compile.s = $($(DISP)_disp_compile.s) +disp_compile.u = $($(DISP)_disp_compile.u) disp_compile.S = $($(DISP)_disp_compile.S) disp_compile.m = $($(DISP)_disp_compile.m) disp_compile-m = $($(DISP)_disp_compile-m) @@ -94,30 +133,83 @@ disp_strip = $($(DISP)_disp_strip) disp_t_strip = $($(DISP)_disp_t_strip) disp_ar = $($(DISP)_disp_ar) disp_ld = $($(DISP)_disp_ld) - -cmd_compile.c = $(CC) -c $< -o $@ $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(filter-out $(CFLAGS-OMIT-$(notdir $<)),$(CFLAGS-$(notdir $(^D)))) $(CFLAGS-$(subst $(top_srcdir),,$(dir $<))) $(CFLAGS-$(notdir $<)) $(CFLAGS-$(notdir $@)) -cmd_compile.S = $(cmd_compile.c) -D__ASSEMBLER__ $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $<)) $(ASFLAGS-$(notdir $@)) +disp_ln = $($(DISP)_disp_ln) +disp_mkdir = $($(DISP)_disp_mkdir) +disp_gen = $($(DISP)_disp_gen) +disp_unifdef = $($(DISP)_disp_unifdef) + +any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) + +# ../foo/bar/baz.ext -> foo_bar_baz.ext +variablify = $(subst /,_,$(subst $(top_builddir),,$(1))) +# strip the top_builddir off everything to make the *string* idempotent for -C +dirify = $(subst $(top_builddir),,$(patsubst -L$(top_builddir)%,-L%,$(patsubst -I$(top_builddir)%,-I%,$(1)))) + +# True if not identical. Neither order nor whitespace nor identical flags +# matter. +compare_flags = \ + $(strip $(filter-out $(call dirify,$(cmd_$(call variablify,$(1)))), \ + $(call dirify,$(cmd_$(call variablify,$(@))))) \ + $(filter-out $(call dirify,$(cmd_$(call variablify,$(@)))), \ + $(call dirify,$(cmd_$(call variablify,$(1)))))) + +# Rebuild if any prerequisite, the used CC or flags changed. +# Previously used flags are stored in the corresponding .%.dep files +maybe_exec = \ + $(if $(strip $(compare_flags) $(any-prereq)), \ + @set -e; \ + $(disp_$(1)); \ + $(cmd_$(1)); \ + echo 'cmd_$(call variablify,$@) := $(call dirify,$(cmd_$(call variablify,$1)))' >> $(dir $@).$(notdir $@).dep) + + +CFLAGS_gen.dep = -MT $@ -MD -MP -MF $(dir $@).$(notdir $@).dep + +cmd_compile.c = $(CC) -c $< -o $@ $(CFLAGS) $(ARCH_CFLAGS) \ + $(CFLAGS-$(suffix $@)) \ + $(filter-out $(CFLAGS-OMIT-$(notdir $<)),$(CFLAGS-$(notdir $(<D)))) \ + $(CFLAGS-$(subst $(top_srcdir),,$(dir $<))) \ + $(CFLAGS-$(notdir $<)) \ + $(CFLAGS-$(notdir $@)) \ + $(CFLAGS_gen.dep) +cmd_compile.i = $(cmd_compile.c:-c=-E -dD) +cmd_compile.s = $(cmd_compile.c:-c=-S) +cmd_compile.u = $(CC) $^ $(DEPS-$(notdir $@)) -o $@ $(CFLAGS) $(CFLAGS-$(notdir $(^D))) $(CFLAGS-$(notdir $@)) $(CFLAGS_gen.dep) +cmd_compile.S = $(filter-out -std=gnu99, $(cmd_compile.c)) -D__ASSEMBLER__ $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $<)) $(ASFLAGS-$(notdir $@)) cmd_compile.m = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@)) + cmd_compile-m = $(CC) $^ -c -o $@ $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $(@D))) $(CFLAGS-$(notdir $@)) cmd_strip = $(STRIPTOOL) $(STRIP_FLAGS) $^ cmd_t_strip = $(STRIPTOOL) $(STRIP_FLAGS) $@ cmd_ar = $(AR) $(ARFLAGS) $@ $^ -compile.c = @$(disp_compile.c) ; $(cmd_compile.c) -compile.i = $(cmd_compile.c:-c=-E -dD) -compile.s = $(cmd_compile.c:-c=-S) -compile.S = @$(disp_compile.S) ; $(cmd_compile.S) -compile.m = @$(disp_compile.m) ; $(cmd_compile.m) -compile-m = @$(disp_compile-m) ; $(cmd_compile-m) +define do_ln + @$(disp_ln) + $(Q)$(LN) -fs +endef + +define do_awk + @$(disp_gen) + $(Q)$(AWK) -f +endef + +compile.c = @$(call maybe_exec,compile.c) +compile.i = $(call maybe_exec,compile.i) +compile.s = $(call maybe_exec,compile.s) +compile.S = @$(call maybe_exec,compile.S) +compile.m = @$(call maybe_exec,compile.m) +compile-m = @$(disp_compile-m) ; $(cmd_compile-m) ; $(do_t_strip) do_strip = @$(disp_strip) ; $(cmd_strip) do_t_strip= @$(disp_t_strip) ; $(cmd_t_strip) -do_ar = @$(disp_ar) ; $(cmd_ar) +do_unifdef= @$(disp_unifdef) ; $(cmd_unifdef) +define do_ar + $(do_strip) + @$(disp_ar) ; $(cmd_ar) +endef define compile.u - @$(disp_compile.c) - $(Q)$(CC) $^ $(DEPS-$(notdir $@)) -o $@ $(CFLAGS) $(CFLAGS-$(notdir $(^D))) $(CFLAGS-$(notdir $@)) - @$(disp_strip) - $(Q)$(STRIPTOOL) $(STRIP_FLAGS) $@ + @$(disp_compile.u) ; $(cmd_compile.u) + @$(disp_t_strip) endef hcompile.u = $(HOSTCC) $^ $(DEPS-$(notdir $@)) -o $@ $(BUILD_LDFLAGS) $(BUILD_LDFLAGS-$(notdir $(^D))) $(BUILD_LDFLAGS-$(notdir $@)) $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@)) hcompile.o = $(HOSTCC) $^ $(DEPS-$(notdir $@)) -c -o $@ $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@)) @@ -127,7 +219,7 @@ define link.so $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1) @$(disp_ld) $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -Wl,-soname=$(notdir $@).$(2) \ - -nostdlib -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \ + $(NOSTDLIB_CFLAGS) -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \ -Wl,--whole-archive $(firstword $^) -Wl,--no-whole-archive \ $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@)) $(Q)$(LN) -sf $(1) $@.$(2) @@ -146,23 +238,28 @@ LINK_FLAT_CRTS := $(top_builddir)lib/Scrt1.o $(top_builddir)lib/crti.o \ # Argument 1 is the shared library file -- i.e. $(@:.gdb=) -- and argument 2 # is the shared library identifier. If it wasn't for $(disp_ld), we could # avoid passing $(@:.gdb=) as an argument and use $(@:.gdb=) instead of $(1). +# +# This is so far only used for libc, for which we want to link the entire +# libgcc into the shared object. define link-flat.so $(Q)$(INSTALL) -d $(dir $@) $(Q)$(RM) $(1) $@ @$(disp_ld) - $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -nostdlib -o $(1) \ - -Wl,-elf2flt -Wl,-shared-lib-id $(2) $(top_builddir)lib/Scrt1.o \ + $(Q)$(CC) $(LDFLAGS-$(notdir $@)) $(NOSTDLIB_CFLAGS) -o $(1) \ + -Wl,-elf2flt -Wl,-shared-lib-id,$(2) $(top_builddir)lib/Scrt1.o \ $(top_builddir)/lib/crti.o -Wl,--whole-archive $(firstword $^) \ - -Wl,--no-whole-archive $(LIBS-$(notdir $@)) $(LIBGCC) \ + $(LIBGCC) -Wl,--no-whole-archive $(LIBS-$(notdir $@)) $(LIBGCC) \ $(top_builddir)/lib/crtn.o endef define linkm.so $(Q)$(INSTALL) -d $(dir $@) $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1) + $(do_strip) @$(disp_ld) $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -Wl,-soname=$(notdir $@).$(2) \ - -nostdlib -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) $^ \ + $(NOSTDLIB_CFLAGS) -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \ + $^ \ $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@)) $(Q)$(LN) -sf $(1) $@.$(2) $(Q)$(LN) -sf $(1) $@ @@ -171,19 +268,19 @@ endef CFLAGS-.os+=$(PICFLAG) CFLAGS-.oS+=$(PICFLAG) -DSHARED -%.o: %.c ; $(compile.c) -%.os: %.c ; $(compile.c) -%.oS: %.c ; $(compile.c) -%.o: %.S ; $(compile.S) -%.os: %.S ; $(compile.S) -%.oS: %.S ; $(compile.S) -%.o: %.s ; $(compile.S) -%.os: %.s ; $(compile.S) -%.oS: %.s ; $(compile.S) -%.i: %.c ; $(compile.i) -%.i: %.S ; $(compile.i) -%.s: %.c ; $(compile.s) -%.s: %.S ; $(compile.s) +%.o: %.c FORCE ; $(compile.c) +%.os: %.c FORCE ; $(compile.c) +%.oS: %.c FORCE ; $(compile.c) +%.o: %.S FORCE ; $(compile.S) +%.os: %.S FORCE ; $(compile.S) +%.oS: %.S FORCE ; $(compile.S) +%.o: %.s FORCE ; $(compile.S) +%.os: %.s FORCE ; $(compile.S) +%.oS: %.s FORCE ; $(compile.S) +%.i: %.c FORCE ; $(compile.i) +%.i: %.S FORCE ; $(compile.i) +%.s: %.c FORCE ; $(compile.s) +%.s: %.S FORCE ; $(compile.s) $(top_builddir)lib/interp.c: | $(sub_headers) $(Q)$(INSTALL) -d $(dir $@) @@ -202,9 +299,6 @@ $(ldso): $(libc): @cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(MAJOR_VERSION),%,$(notdir $@)) -$(headers_dep): - $(Q)cd $(top_builddir); $(MAKE) headers - CRT := crt1 ifeq ($(HAVE_SHARED)$(UCLIBC_FORMAT_SHARED_FLAT),y) @@ -226,6 +320,13 @@ else CTOR_TARGETS:= endif +ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y) +CRTRELOC=$(top_builddir)lib/crtreloc.o +$(CRTRELOC): $(top_builddir)lib/%.o : $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/%.c + $(Q)$(INSTALL) -d $(dir $@) + $(compile.c) +endif + ifneq ($(wildcard $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c),) CFLAGS-initfini.s := -S -g0 $(PICFLAG) -fno-inline-functions -finhibit-size-directive $(top_builddir)lib/initfini.s: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c @@ -238,13 +339,13 @@ $(top_builddir)lib/defs.h: $(top_builddir)lib/initfini.s $(top_builddir)lib/crti.S: $(top_builddir)lib/initfini.s $(top_builddir)lib/defs.h $(Q)sed -n -e '1,/@HEADER_ENDS/p' \ - -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \ - -e '/@TRAILER_BEGINS/,$$p' $< > $@ + -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \ + -e '/@TRAILER_BEGINS/,$$p' $< > $@ $(top_builddir)lib/crtn.S: $(top_builddir)lib/initfini.s $(Q)sed -n -e '1,/@HEADER_ENDS/p' \ - -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \ - -e '/@TRAILER_BEGINS/,$$p' $< > $@ + -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \ + -e '/@TRAILER_BEGINS/,$$p' $< > $@ $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_builddir)lib/%.S $(Q)$(INSTALL) -d $(dir $@) @@ -263,28 +364,48 @@ endif CRTS_COMPAT := #endif -$(crt-y): $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) -$(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT): | headers +$(crt-y): $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) $(CRTRELOC) +$(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) $(CRTRELOC): | $(headers-y) $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y) $(Q)$(INSTALL) -d $(dir $@) $(Q)$(RM) $@ - $(do_strip) $(do_ar) $(top_builddir)lib/libpthread_nonshared.a: $(libpthread-nonshared-y) $(Q)$(INSTALL) -d $(dir $@) $(Q)$(RM) $@ - $(do_strip) $(do_ar) -.PHONY: dummy create +files.dep := $(libc-a-y) $(libc-so-y) $(libc-nonshared-y) \ + $(libm-a-y) $(libm-so-y) \ + $(libpthread-a-y) $(libpthread-so-y) $(libpthread-nonshared-y) \ + $(libthread_db-a-y) $(libthread_db-so-y) \ + $(librt-a-y) $(librt-so-y) $(libresolv-a-y) $(libresolv-so-y) \ + $(libcrypt-a-y) $(libcrypt-so-y) $(libutil-a-y) $(libutil-so-y) \ + $(libnsl-a-y) $(libnsl-so-y) $(ldso-y) $(libdl-a-y) $(libdl-so-y) +.depends.dep := \ + $(patsubst %.o,%.o.dep,$(filter %.o,$(files.dep))) \ + $(patsubst %.os,%.os.dep,$(filter %.os,$(files.dep))) \ + $(patsubst %.oS,%.oS.dep,$(filter %.oS,$(files.dep))) +# Oh, and prepend a dot to the basename so i don't have to change my habit of +# calling 'size thefile.o*' +.depends.dep := $(foreach f,$(.depends.dep),$(dir $(f)).$(notdir $(f))) +.depends.dep := $(wildcard $(.depends.dep)) + +FORCE: + clean: objclean-y headers_clean-y +realclean: clean + $(Q)$(RM) $(.depends.dep) objclean-y: $(objclean-y) headers_clean-y: $(headers_clean-y) -.PHONY: \ - all check clean distclean test \ - config dist menuconfig oldconfig release \ - subdirs utils +ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),) +ifneq ($(strip $(.depends.dep)),) +.NOEXPORT: +-include $(.depends.dep) +endif +endif + |
