1# Copyright 2017 The Fuchsia Authors 2# 3# Use of this source code is governed by a MIT-style 4# license that can be found in the LICENSE file or at 5# https://opensource.org/licenses/MIT 6 7# rules for generating the sysroot/ dir and contents in the builddir 8 9# identify global headers to copy to the sysroot 10GLOBAL_HEADERS := $(shell find system/public -name \*\.h -o -name \*\.inc -o -name \*\.modulemap) 11SYSROOT_HEADERS := $(patsubst system/public/%,$(BUILDSYSROOT)/include/%,$(GLOBAL_HEADERS)) 12 13# generate rule to copy them 14$(call copy-dst-src,$(BUILDSYSROOT)/include/%.h,system/public/%.h) 15$(call copy-dst-src,$(BUILDSYSROOT)/include/%.inc,system/public/%.inc) 16$(call copy-dst-src,$(BUILDSYSROOT)/include/%.modulemap,system/public/%.modulemap) 17 18SYSROOT_DEPS += $(SYSROOT_HEADERS) 19 20# copy crt*.o files to the sysroot 21SYSROOT_SCRT1 := $(BUILDSYSROOT)/lib/Scrt1.o 22$(call copy-dst-src,$(SYSROOT_SCRT1),$(USER_SCRT1_OBJ)) 23SYSROOT_DEPS += $(SYSROOT_SCRT1) 24 25# generate empty compatibility libs 26$(BUILDSYSROOT)/lib/libm.so: third_party/ulib/musl/lib.ld 27 @$(MKDIR) 28 $(NOECHO)cp $< $@ 29$(BUILDSYSROOT)/lib/libdl.so: third_party/ulib/musl/lib.ld 30 @$(MKDIR) 31 $(NOECHO)cp $< $@ 32$(BUILDSYSROOT)/lib/libpthread.so: third_party/ulib/musl/lib.ld 33 @$(MKDIR) 34 $(NOECHO)cp $< $@ 35$(BUILDSYSROOT)/lib/librt.so: third_party/ulib/musl/lib.ld 36 @$(MKDIR) 37 $(NOECHO)cp $< $@ 38 39SYSROOT_DEPS += $(BUILDSYSROOT)/lib/libm.so $(BUILDSYSROOT)/lib/libdl.so $(BUILDSYSROOT)/lib/libpthread.so 40 41# GDB specifically looks for ld.so.1, so we create that as a symlink. 42$(BUILDSYSROOT)/debug/$(USER_SHARED_INTERP): FORCE 43 @$(MKDIR) 44 $(NOECHO)rm -f $@ 45 $(NOECHO)ln -s libc.so $@ 46 47SYSROOT_DEPS += $(BUILDSYSROOT)/debug/$(USER_SHARED_INTERP) 48 49# Stable (i.e. sorted) list of the actual build inputs in the sysroot. 50# (The debug files don't really belong in the sysroot.) 51SYSROOT_LIST := \ 52 $(sort $(filter-out debug/%,$(SYSROOT_DEPS:$(BUILDSYSROOT)/%=%))) 53 54# Generate a file containing $(SYSROOT_LIST) (but newline-separated), for 55# other scripts and whatnot to consume. Touch that file only when its 56# contents change, so the whatnot can lazily trigger on changes. 57$(BUILDDIR)/sysroot.list: $(BUILDDIR)/sysroot.list.stamp ; 58$(BUILDDIR)/sysroot.list.stamp: FORCE 59 $(NOECHO)for f in $(SYSROOT_LIST); do echo $$f; done > $(@:.stamp=.new) 60 $(NOECHO)\ 61 if cmp -s $(@:.stamp=.new) $(@:.stamp=); then \ 62 rm $(@:.stamp=.new); \ 63 else \ 64 $(if $(filter false,$(call TOBOOL,$(QUIET))), \ 65 echo generating $(@:.stamp=);) \ 66 mv $(@:.stamp=.new) $(@:.stamp=); \ 67 fi 68 $(NOECHO)touch $@ 69 70GENERATED += $(BUILDDIR)/sysroot.list $(BUILDDIR)/sysroot.list.stamp 71GENERATED += $(SYSROOT_DEPS) 72 73# add phony top level rule 74.PHONY: sysroot 75sysroot: $(SYSROOT_DEPS) $(BUILDDIR)/sysroot.list.stamp 76 77# conditionally run the sysroot rule if set in the environment 78ifeq ($(call TOBOOL,$(ENABLE_BUILD_SYSROOT)),true) 79EXTRA_BUILDDEPS += sysroot 80endif 81