]> git.saurik.com Git - apple/xnu.git/blob - libsyscall/BSDmakefile
xnu-1456.1.26.tar.gz
[apple/xnu.git] / libsyscall / BSDmakefile
1 .ifndef DSTROOT
2 DSTROOT != x=`pwd`/DSTROOT && mkdir -p $$x && echo $$x
3 .endif
4 .ifndef OBJROOT
5 OBJROOT != x=`pwd`/OBJROOT && mkdir -p $$x && echo $$x
6 .endif
7 .ifndef SRCROOT
8 SRCROOT != dirname `pwd`
9 .endif
10 .ifndef SYMROOT
11 SYMROOT != x=`pwd`/SYMROOT && mkdir -p $$x && echo $$x
12 .endif
13 ARCH != arch
14 .ifndef RC_ARCHS
15 RC_ARCHS = $(ARCH)
16 RC_$(RC_ARCHS) = 1
17 .endif
18 SDKROOT ?= /
19 NARCHS != echo $(RC_ARCHS) | wc -w
20 LIBSYS = $(SDKROOT)/usr/local/lib/system
21 NJOBS != perl -e '$$n = `/usr/sbin/sysctl -n hw.ncpu`; printf "%d\n", $$n < 2 ? 2 : ($$n * 1.5)'
22 BSDMAKE = bsdmake -f Makefile
23 BSDMAKEJ = $(BSDMAKE) -j $(NJOBS)
24
25 # This variables are to guarantee that the left-hand side of an expression is
26 # always a variable
27 dynamic = dynamic
28 static = static
29
30 # Remove the arch stuff, since we know better here.
31 LOCAL_CFLAGS != echo $(RC_CFLAGS) | sed 's/ *-arch [^ ][^ ]*//g'
32
33 FORMS := debug dynamic profile static
34
35 all: setup build
36
37 build: build-debug build-dynamic build-profile build-static
38
39 # These are the non B&I defaults
40 .ifndef RC_ProjectName
41 install: installhdrs install-all
42
43 .else # RC_ProjectName
44
45 install: setup
46 .for F in $(FORMS)
47 install: BI-install-$(F)
48 .endfor # FORMS
49 install:
50 install -c -m 444 $(OBJROOT)/sys/libsyscall.list $(DSTROOT)/usr/local/lib/system
51 .endif # RC_ProjectName
52
53 .for F in $(FORMS)
54 .if $(dynamic) == $(F)
55 SUFFIX$(F) =
56 .else
57 SUFFIX$(F) = _$(F)
58 .endif
59 LIPOARGS$(F) != perl -e 'printf "%s\n", join(" ", map(qq(-arch $$_ \"$(OBJROOT)/obj.$$_/libsyscall$(SUFFIX$(F)).a\"), qw($(RC_ARCHS))))'
60
61 .for A in $(RC_ARCHS)
62 build-$(F): build-$(A)-$(F)
63 .endfor # RC_ARCHS
64 build-$(F):
65 mkdir -p $(SYMROOT)
66 .if $(NARCHS) == 1
67 cp -p "$(OBJROOT)/obj.$(RC_ARCHS)/libsyscall$(SUFFIX$(F)).a" "$(SYMROOT)"
68 .else
69 xcrun -sdk $(SDKROOT) lipo -create $(LIPOARGS$(F)) -output $(SYMROOT)/libsyscall$(SUFFIX$(F)).a
70 .endif
71
72 .for A in $(RC_ARCHS)
73 build-$(A)-$(F):
74 mkdir -p $(OBJROOT)/obj.$(A) && \
75 MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH="$(A)" \
76 DSTROOT='$(DSTROOT)' OBJROOT='$(OBJROOT)' SYMROOT='$(SYMROOT)' \
77 MAKEFLAGS="" MIGDEFINES="" CFLAGS="-arch $(A) $(LOCAL_CFLAGS)" $(BSDMAKEJ) libsyscall$(SUFFIX$(F)).a
78 .endfor # RC_ARCHS
79 .endfor # FORMS
80
81 installhdrs:
82 MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" MAKEFLAGS="" \
83 DSTROOT='$(DSTROOT)' OBJROOT='$(OBJROOT)' SYMROOT='$(SYMROOT)' \
84 MIGDEFINES="-DLIBSYSCALL_INTERFACE=1" \
85 $(BSDMAKE) installhdrs
86 .for A in $(RC_ARCHS)
87 mkdir -p "$(OBJROOT)/obj.$(A)" && \
88 MAKEOBJDIR="$(OBJROOT)/obj.$(A)" MACHINE_ARCH="$(A)" \
89 DSTROOT='$(DSTROOT)' OBJROOT='$(OBJROOT)' SYMROOT='$(SYMROOT)' \
90 MAKEFLAGS="" MIGDEFINES="" $(BSDMAKE) installhdrs-md
91 .endfor # RC_ARCHS
92
93 .for F in $(FORMS)
94 BI-install-$(F): build-$(F)
95 mkdir -p $(DSTROOT)/usr/local/lib/system
96 if [ -f "$(SYMROOT)/libsyscall$(SUFFIX$(F)).a" ]; then \
97 echo "Installing libsyscall$(SUFFIX$(F)).a" && \
98 install -c -m 644 "$(SYMROOT)/libsyscall$(SUFFIX$(F)).a" \
99 $(DSTROOT)/usr/local/lib/system && \
100 ranlib "$(DSTROOT)/usr/local/lib/system/libsyscall$(SUFFIX$(F)).a"; \
101 chmod 444 "$(DSTROOT)/usr/local/lib/system/libsyscall$(SUFFIX$(F)).a"; \
102 fi
103 .endfor # FORMS
104
105 install-man:
106 mkdir -p $(DSTROOT)/usr/share/man/man2
107 MAKEOBJDIR="$(OBJROOT)" DESTDIR="$(DSTROOT)" \
108 DSTROOT='$(DSTROOT)' OBJROOT='$(OBJROOT)' SYMROOT='$(SYMROOT)' \
109 MACHINE_ARCH="$(ARCH)" MAKEFLAGS="" $(BSDMAKE) all-man maninstall
110
111 install-all: setup build install-man
112 .for F in $(FORMS)
113 install-all: BI-install-$(F)
114 .endfor # FORMS
115
116 clean:
117 .for F in $(FORMS)
118 rm -f $(OBJROOT)/libsyscall$(SUFFIX$(F)).a
119 .endfor # FORMS
120 .for A in $(RC_ARCHS)
121 rm -rf $(OBJROOT)/obj.$(A)
122 .endfor # RC_ARCHS
123
124 INCLUDEDIR = $(OBJROOT)/include
125 SYSDIR = $(OBJROOT)/sys
126
127 setup: $(INCLUDEDIR) $(SYSDIR)
128
129 USR-INCLUDE = /usr/include
130 MOD-HEADERS = architecture/ppc/mode_independent_asm.h architecture/i386/asm_help.h
131
132 $(INCLUDEDIR):
133 mkdir -p $(INCLUDEDIR)
134 .for h in $(MOD-HEADERS)
135 mkdir -p $(INCLUDEDIR)/$(h:H)
136 sed 's/\.globl/.private_extern/g' $(USR-INCLUDE)/$(h) > $(INCLUDEDIR)/$(h)
137 .endfor # MOD-HEADERS
138
139 $(SYSDIR):
140 mkdir -p $(SYSDIR)
141 $(SRCROOT)/libsyscall/create-syscalls.pl $(SRCROOT)/bsd/kern/syscalls.master $(SRCROOT)/libsyscall/custom $(SYSDIR)