X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/c957a83bde4df2e2d3d1ed0963656856b48ef0a0..224c70764cab4e0e39a26aaf3ad3016552f62f55:/BSDmakefile diff --git a/BSDmakefile b/BSDmakefile index 45d508d..de14ee9 100644 --- a/BSDmakefile +++ b/BSDmakefile @@ -1,15 +1,28 @@ +PWD != pwd +.ifdef DSTROOT +DESTDIR = $(DSTROOT) +.else +.ifdef DESTDIR +DSTROOT = $(DESTDIR) +.else +DSTROOT = / +DESTDIR = / +.endif +.endif .ifndef OBJROOT -OBJROOT != pwd +OBJROOT = $(PWD)/OBJROOT +.endif +.ifndef SRCROOT +SRCROOT = $(PWD) .endif .ifndef SYMROOT -SYMROOT != pwd +SYMROOT = $(PWD)/SYMROOT .endif ARCH != arch .ifndef RC_ARCHS RC_ARCHS = $(ARCH) RC_$(RC_ARCHS) = 1 .endif -NARCHS != echo $(RC_ARCHS) | wc -w .ifdef ALTUSRLOCALLIBSYSTEM LIBSYS = $(ALTUSRLOCALLIBSYSTEM) .else @@ -17,10 +30,13 @@ LIBSYS = $(NEXT_ROOT)/usr/local/lib/system .endif NJOBS != perl -e '$$n = `/usr/sbin/sysctl -n hw.ncpu`; printf "%d\n", $$n < 2 ? 2 : ($$n * 1.5)' BSDMAKE = bsdmake -f Makefile -#BSDMAKEJ = $(BSDMAKE) -j $(NJOBS) -BSDMAKEJ = $(BSDMAKE) -j $(NJOBS) -P +#BSDMAKEJ = $(BSDMAKE) -j $(NJOBS) -P +BSDMAKEJ = $(BSDMAKE) -j $(NJOBS) + +# Set the DONT-BUILD-arch-form variable to non-empty to turn off building +#DONT-BUILD-x86_64-static = 1 -# This variables are to guarantee that the left-hand side of an expression is +# These variables are to guarantee that the left-hand side of an expression is # always a variable dynamic = dynamic static = static @@ -32,11 +48,19 @@ FORMS := dynamic debug profile static all: build +ROOTS := DSTROOT OBJROOT SYMROOT +.for R in $(ROOTS) # { +roots: $($(R)) +$($(R)): + mkdir -p '$($(R))' +.endfor # ROOTS } + # These are the non B&I defaults .ifndef RC_ProjectName -installhdrs: installhdrs-real -build: build-static build-profile build-debug build-dynamic -install: installhdrs install-all + +installhdrs: roots installhdrs-real +build: roots build-static build-profile build-debug build-dynamic +install: roots installhdrs install-all .else # RC_ProjectName @@ -44,127 +68,163 @@ install: installhdrs install-all # based on RC_ProjectName. .if $(RC_ProjectName) == Libc installhdrs: -build: build-dynamic -install: BI-install-dynamic +build: roots build-dynamic +install: roots BI-install-dynamic .endif .if $(RC_ProjectName) == Libc_headers -installhdrs: installhdrs-real +installhdrs: roots installhdrs-real build: -install: installhdrs-real +install: roots installhdrs-real .endif .if $(RC_ProjectName) == Libc_man installhdrs: build: -install: install-man +install: roots install-man .endif .if $(RC_ProjectName) == Libc_static installhdrs: -build: build-static -install: BI-install-static +build: roots build-static +install: roots BI-install-static .endif .if $(RC_ProjectName) == Libc_debug installhdrs: -build: build-debug -install: BI-install-debug +build: roots build-debug +install: roots BI-install-debug .endif .if $(RC_ProjectName) == Libc_profile installhdrs: -build: build-profile -install: BI-install-profile +build: roots build-profile +install: roots BI-install-profile .endif .endif # RC_ProjectName -# Because of 3780028, there are random failures on HFS because the -# CC_PRINT_OPTIONS_FILE can't be created. So we touch it first. -.if !empty $(CC_PRINT_OPTIONS_FILE) -$(CC_PRINT_OPTIONS_FILE): - touch $(CC_PRINT_OPTIONS_FILE) -.endif # CC_PRINT_OPTIONS_FILE - -.for F in $(FORMS) -.if $(dynamic) == $(F) -SUFFIX$(F) = +# Make a copy of System.framework/Versions/B/PrivateHeaders, with headers +# patched so that we can build variant symbols independently +SYSTEMFRAMEWORK = System.framework +VERSIONSB = Versions/B +PRIVATEHEADERPATH = $(SYSTEMFRAMEWORK)/$(VERSIONSB)/PrivateHeaders +FRAMEWORKS = $(OBJROOT)/Frameworks +.ifdef ALTFRAMEWORKSPATH +FRAMEWORKPATH = ${ALTFRAMEWORKSPATH} .else -SUFFIX$(F) = _$(F) +FRAMEWORKPATH = ${NEXT_ROOT}/System/Library/Frameworks .endif -LIPOARGS$(F) != perl -e 'printf "%s\n", join(" ", map(qq(-arch $$_ \"$(OBJROOT)/obj.$$_/libc$(SUFFIX$(F)).a\"), qw($(RC_ARCHS))))' - -build-$(F): autopatch $(CC_PRINT_OPTIONS_FILE) -.for A in $(RC_ARCHS) -build-$(F): build-$(A)-$(F) -.endfor # RC_ARCHS -build-$(F): -.if $(NARCHS) == 1 - cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc$(SUFFIX$(F)).a" "$(SYMROOT)" -.else - lipo -create $(LIPOARGS$(F)) -output $(SYMROOT)/libc$(SUFFIX$(F)).a -.endif - -.for A in $(RC_ARCHS) +$(FRAMEWORKS): + $(SRCROOT)/patchHeaders $(FRAMEWORKPATH)/$(PRIVATEHEADERPATH) $(FRAMEWORKS)/$(PRIVATEHEADERPATH:H) + ln -fs $(VERSIONSB)/PrivateHeaders $(FRAMEWORKS)/$(SYSTEMFRAMEWORK)/PrivateHeaders + +AUTOPATCHED = $(SRCROOT)/.autopatched +PARTIAL = -partial +.for F in $(FORMS) # { +.if $(dynamic) == $(F) # { +SUFFIX-$(F) = +.else # } { +SUFFIX-$(F) = _$(F) +.endif # } +PSUFFIX-$(F) = $(PARTIAL)$(SUFFIX-$(F)) + +.for A in $(RC_ARCHS) # { +.if empty(DONT-BUILD-$(A)-$(F)) # { +ARCHS-$(F) += $(A) build-$(A)-$(F): mkdir -p $(OBJROOT)/obj.$(A) && \ MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH="$(A)" \ - MAKEFLAGS="" CFLAGS="-arch $(A) $(LOCAL_CFLAGS)" $(BSDMAKEJ) libc$(SUFFIX$(F)).a -.endfor # RC_ARCHS -.endfor # FORMS - -# We have to separately call bsdmake to patch the FreeBSD files, because of -# the way its cache works, it would otherwise pick A file in ${SYMROOT}, even -# over A .s file. -autopatch: -.for A in $(RC_ARCHS) - MACHINE_ARCH="$(A)" $(BSDMAKEJ) autopatch -.endfor # RC_ARCHS - -installsrc: - pax -rw . "$(SRCROOT)" - -installhdrs-real: $(CC_PRINT_OPTIONS_FILE) + DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \ + MAKEFLAGS="" CFLAGS="-arch $(A) $(LOCAL_CFLAGS)" $(BSDMAKEJ) libc$(SUFFIX-$(F)).a +.else # } { +build-$(A)-$(F): + @echo Not building libc$(PSUFFIX-$(F)).a for $(A) +.endif # } +.endfor # RC_ARCHS } + +NARCHS-$(F) != echo $(ARCHS-$(F)) | wc -w + +build-$(F): $(FRAMEWORKS) $(AUTOPATCHED) +.for A in $(RC_ARCHS) # { +build-$(F): build-$(A)-$(F) +.endfor # RC_ARCHS } +.if $(NARCHS-$(F)) == 0 # { +build-$(F): + @echo No libc$(PSUFFIX-$(F)).a built +.else # } { +LIPOARGS-$(F) != perl -e 'printf "%s\n", join(" ", map(qq(-arch $$_ \"$(OBJROOT)/obj.$$_/libc$(SUFFIX-$(F)).a\"), qw($(ARCHS-$(F)))))' +build-$(F): +.if $(NARCHS-$(F)) == 1 # { + cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libc$(SUFFIX-$(F)).a" "$(SYMROOT)/libc$(PSUFFIX-$(F)).a" +.else # } { + lipo -create $(LIPOARGS-$(F)) -output "$(SYMROOT)/libc$(PSUFFIX-$(F)).a" +.endif # } +.endif # } +.endfor # FORMS } + +# We autopatch the files into the directory containing the Makefile.inc. This +# will happen at installsrc. +$(AUTOPATCHED): + @set -x && \ + for m in `find $(SRCROOT) -name Makefile.inc`; do \ + cd `dirname $$m` && \ + bsdmake -I $(SRCROOT) -f $(SRCROOT)/Makefile.inc -f Makefile.inc -f $(SRCROOT)/Makefile.autopatch autopatch LIB=c SRCROOT=$(SRCROOT) || \ + exit 1; \ + done + touch $(AUTOPATCHED) + +copysrc: + pax -rw -p p . "$(SRCROOT)" + +installsrc: copysrc $(AUTOPATCHED) + +installhdrs-real: MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" MAKEFLAGS="" \ - $(BSDMAKEJ) installhdrs -.for A in $(RC_ARCHS) + DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \ + $(BSDMAKEJ) installhdrs +.for A in $(RC_ARCHS) # { mkdir -p "$(OBJROOT)/obj.$(A)" && \ MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH="$(A)" \ - MAKEFLAGS="" $(BSDMAKEJ) installhdrs-md -.endfor # RC_ARCHS + DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \ + MAKEFLAGS="" $(BSDMAKEJ) installhdrs-md +.endfor # RC_ARCHS # } -.for F in $(FORMS) +.for F in $(FORMS) # { BI-install-$(F): build-$(F) mkdir -p $(DSTROOT)/usr/local/lib/system - if [ -f "$(SYMROOT)/libc$(SUFFIX$(F)).a" ]; then \ - echo "Installing libc$(SUFFIX$(F)).a" && \ - install -c -m 444 "$(SYMROOT)/libc$(SUFFIX$(F)).a" \ + if [ -f "$(SYMROOT)/libc$(PSUFFIX-$(F)).a" ]; then \ + echo "Installing libc$(PSUFFIX-$(F)).a" && \ + install -c -m 444 "$(SYMROOT)/libc$(PSUFFIX-$(F)).a" \ $(DSTROOT)/usr/local/lib/system && \ - ranlib "$(DSTROOT)/usr/local/lib/system/libc$(SUFFIX$(F)).a"; \ + ranlib "$(DSTROOT)/usr/local/lib/system/libc$(PSUFFIX-$(F)).a" || exit 1; \ fi -.if !empty $(RC_ppc) && ($(static) != $(F)) - if [ -f "$(OBJROOT)/obj.ppc/libc-ldbl128$(SUFFIX$(F)).a" ]; then \ - echo "Installing libldbl128$(SUFFIX$(F)).a" ; \ - $(SRCROOT)/make_libldbl128 "$(OBJROOT)/obj.ppc/libc-ldbl128$(SUFFIX$(F)).a" \ - "$(SUFFIX$(F))" "$(DSTROOT)/usr/local/lib/system" $(LIBSYS) ; \ - fi -.endif # RC_ppc && !static -.endfor # FORMS +.if $(dynamic) == $(F) # { +.for A in $(RC_ARCHS) # { + MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH="$(A)" \ + DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \ + DSTROOT=$(DSTROOT) OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) \ + MAKEFLAGS="" $(BSDMAKE) copyfiles +.endfor # RC_ARCHS # } +.endif # } +.endfor # FORMS } # Don't use -j here; it may try to make links before the files are copied +MANARGS != test `id -u` -eq 0 || echo MINSTALL=/usr/bin/install install-man: mkdir -p $(DSTROOT)/usr/share/man/man2 mkdir -p $(DSTROOT)/usr/share/man/man3 mkdir -p $(DSTROOT)/usr/share/man/man4 mkdir -p $(DSTROOT)/usr/share/man/man5 mkdir -p $(DSTROOT)/usr/share/man/man7 - MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" NOMANCOMPRESS=1 \ - MACHINE_ARCH="$(ARCH)" MAKEFLAGS="" $(BSDMAKE) autopatchman maninstall + MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" \ + DSTROOT='$(DSTROOT)' OBJROOT='$(OBJROOT)' SYMROOT='$(SYMROOT)' \ + MACHINE_ARCH="$(ARCH)" MAKEFLAGS="" \ + $(BSDMAKE) autopatchman all-man maninstall $(MANARGS) install-all: build install-man -.for F in $(FORMS) +.for F in $(FORMS) # { install-all: BI-install-$(F) -.endfor # FORMS +.endfor # FORMS } clean: -.for F in $(FORMS) - rm -f $(OBJROOT)/libc$(SUFFIX$(F)).a -.endfor # FORMS -.for A in $(RC_ARCHS) +.for F in $(FORMS) # { + rm -f $(SYMROOT)/libc$(PSUFFIX-$(F)).a +.endfor # FORMS } +.for A in $(RC_ARCHS) # { rm -rf $(OBJROOT)/obj.$(A) -.endfor # RC_ARCHS +.endfor # RC_ARCHS # }