]> git.saurik.com Git - apple/xnu.git/blame - libkern/kxld/Makefile
xnu-3789.70.16.tar.gz
[apple/xnu.git] / libkern / kxld / Makefile
CommitLineData
b0d623f7
A
1################################################################################
2# Note: this makefile is used only for the libkxld build alias. It is not part
3# of the regular kernel build process.
4################################################################################
5
6# Version
7COMPATIBILITY_VERSION=1
8CURRENT_VERSION=1
9
10# Paths
11ifndef DSTROOT
12DSTROOT=./BUILD/dst
13endif
14ifndef OBJROOT
15OBJROOT=./BUILD/obj
16endif
17ifndef SYMROOT
18SYMROOT=./BUILD/sym
19endif
20ifdef SRCROOT
316670eb 21EXTHDRSRC=$(SRCROOT)/EXTERNAL_HEADERS
b0d623f7
A
22HDRSRC=$(SRCROOT)/libkern/libkern
23OBJSRC=$(SRCROOT)/libkern/kxld
24else
25SRCROOT=.
316670eb 26EXTHDRSRC=$(SRCROOT)/../../EXTERNAL_HEADERS
b0d623f7
A
27HDRSRC=$(SRCROOT)/../libkern
28OBJSRC=$(SRCROOT)
29ROOT=BUILD
30endif
31ifdef RC_CFLAGS
32ARCHS=$(addprefix -arch , $(RC_ARCHS))
33else
39236c6e 34ARCHS=-arch x86_64
b0d623f7
A
35RC_CFLAGS=$(ARCHS) -pipe
36endif
316670eb
A
37ifdef INSTALL_LOCATION
38override DSTROOT := $(DSTROOT)/$(INSTALL_LOCATION)
39endif
b0d623f7
A
40
41PRODUCT_TYPE ?= DYLIB
42
43HDRDST=$(DSTROOT)/usr/local/include
6d2010ae 44DYLIBDST=$(DSTROOT)/usr/lib/system
b0d623f7 45ARCHIVEDST=$(DSTROOT)/usr/local/lib
b0d623f7
A
46LIBKXLD_DYLIB=libkxld.dylib
47LIBKXLD_ARCHIVE=libkxld.a
fe8ab488 48LIBKXLD_DSYM=$(LIBKXLD_DYLIB).dSYM
6d2010ae 49LIBKXLD_INSTALLNAME=/usr/lib/system/$(LIBKXLD_DYLIB)
b0d623f7
A
50LIBKXLDOBJ_DYLIB=$(OBJROOT)/$(LIBKXLD_DYLIB)
51LIBKXLDOBJ_ARCHIVE=$(OBJROOT)/$(LIBKXLD_ARCHIVE)
6d2010ae 52LIBKXLDSYM_DYLIB=$(SYMROOT)/$(LIBKXLD_DYLIB)
fe8ab488 53LIBKXLDSYM_DYLIB_DSYM=$(SYMROOT)/$(LIBKXLD_DSYM)
6d2010ae
A
54LIBKXLDSYM_ARCHIVE=$(SYMROOT)/$(LIBKXLD_ARCHIVE)
55LIBKXLDDST_DYLIB=$(DYLIBDST)/$(LIBKXLD_DYLIB)
b0d623f7
A
56LIBKXLDDST_ARCHIVE=$(ARCHIVEDST)/$(LIBKXLD_ARCHIVE)
57TESTSRC=$(SRCROOT)/tests
58TESTDST=./BUILD/tests
59
60# Flags
fe8ab488
A
61ifdef SDKROOT
62 SDK_DIR := $(shell xcodebuild -version -sdk $(SDKROOT) Path)
63endif
64
65ifeq ($(strip $(SDK_DIR)),)
66 SDK_DIR := /
67endif
68
39236c6e 69DEFINES = -DPRIVATE
b0d623f7
A
70CFLAGS=-std=c99 -Wall -Wextra -Werror -pedantic -Wformat=2 -Wcast-align \
71 -Wwrite-strings -Wshorten-64-to-32 -Wshadow -Winit-self -Wpointer-arith \
72 -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes -Wreturn-type \
73 -Wcast-qual -Wwrite-strings -Wswitch -Wcast-align -Wbad-function-cast \
6d2010ae
A
74 -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -g
75LDFLAGS=$(ARCHS) -dynamiclib -install_name $(LIBKXLD_INSTALLNAME) \
b0d623f7 76 -compatibility_version $(COMPATIBILITY_VERSION) \
6d2010ae 77 -current_version $(CURRENT_VERSION) -lstdc++
39236c6e 78INCLUDES=-I$(HDRSRC) -isystem $(EXTHDRSRC)
6d2010ae 79
fe8ab488
A
80ifneq ($(SDK_DIR),/)
81 CFLAGS += -isysroot $(SDK_DIR)
82 LDFLAGS += -isysroot $(SDK_DIR)
6d2010ae 83endif
b0d623f7
A
84
85# Tools
fe8ab488 86CC = xcrun -sdk $(SDK_DIR) clang
6d2010ae 87CLANG_ANALYZER = clang --analyze
fe8ab488
A
88LIBTOOL = xcrun -sdk $(SDK_DIR) libtool
89STRIP = xcrun -sdk $(SDK_DIR) strip
90DSYMUTIL = xcrun -sdk $(SDK_DIR) dsymutil
b0d623f7 91
b0d623f7 92# Files
39037602 93HDR_NAMES=kxld.h kxld_types.h prelink.h
b7266188 94OBJ_NAMES=kxld.o kxld_array.o kxld_copyright.o kxld_demangle.o kxld_dict.o \
316670eb 95 kxld_kext.o kxld_object.o kxld_reloc.o kxld_sect.o kxld_seg.o \
39037602 96 kxld_srcversion.o kxld_splitinfolc.o kxld_sym.o kxld_symtab.o kxld_util.o kxld_uuid.o \
39236c6e 97 kxld_vtable.o kxld_versionmin.o
316670eb 98
b0d623f7
A
99HDRS=$(addprefix $(HDRSRC)/, $(HDR_NAMES))
100OBJS=$(addprefix $(OBJROOT)/, $(OBJ_NAMES))
101
102$(shell [ -d $(OBJROOT) ] || mkdir -p $(OBJROOT))
103
104# Implicit rules
105%.o : %.c
106$(OBJROOT)/%.o : $(OBJSRC)/%.c
39236c6e 107 $(CC) $(RC_CFLAGS) $(CFLAGS) $(DEFINES) $(OPTIM) $(INCLUDES) -c $< -o $@
b0d623f7 108$(OBJROOT)/%.o : $(TESTSRC)/%.c
3e170ce0 109 $(CC) $(RC_CFLAGS) $(CFLAGS) $(DEFINES) -O0 -DDEBUG $(INCLUDES) -I$(SRCROOT) -c $< -o $@
b0d623f7
A
110
111SRCROOTESC=$(subst /,\/,$(SRCROOT))
112OBJROOTESC=$(subst /,\/,$(OBJROOT))
113SEDOBJS=sed -E 's/(^[a-z_]+)\.o/$(OBJROOTESC)\/\1\.o $(OBJROOTESC)\/\1\.d/'
316670eb 114SEDSRCS=sed -E 's/ ([a-z_]+\.[ch])/ $(SRCROOTESC)\/\1/g'
b0d623f7
A
115$(OBJROOT)/%.d: $(OBJSRC)/%.c
116 @set -e; rm -f $@; \
3e170ce0 117 $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -MM $< | $(SEDOBJS) | $(SEDSRCS) > $@;
b0d623f7
A
118
119# Rules
120release: OPTIM=-Os -dynamic
121release: build
122
123debug: OPTIM=-O0 -DDEBUG -dynamic
124debug: build
125
126profile: OPTIM=-Os -pg -dynamic
127profile: build
128
129tests: OPTIM=-O0 -DDEBUG
6d2010ae
A
130tests: kxld_array_test kxld_dict_test copyrighttest
131
132build: $(LIBKXLDSYM_$(PRODUCT_TYPE))
b0d623f7 133
6d2010ae
A
134$(LIBKXLDSYM_DYLIB): $(LIBKXLDOBJ_DYLIB)
135 @mkdir -p $(SYMROOT)
136 install -c -m 644 $< $@
fe8ab488 137 $(DSYMUTIL) $@ -o $(LIBKXLDSYM_DYLIB_DSYM)
6d2010ae
A
138
139$(LIBKXLDSYM_ARCHIVE): $(LIBKXLDOBJ_ARCHIVE)
140 @mkdir -p $(SYMROOT)
141 install -c -m 644 $< $@
b0d623f7
A
142
143$(LIBKXLDOBJ_DYLIB): $(OBJS)
144 $(CC) $(LDFLAGS) -o $@ $^
145
146$(LIBKXLDOBJ_ARCHIVE): $(OBJS)
147 $(LIBTOOL) -static -o $@ $^
148
149installhdrs:
6d2010ae 150 @mkdir -p $(HDRDST)
b0d623f7
A
151 install -o 0 -g 0 -c -m 444 $(HDRS) $(HDRDST)
152
153install: release installhdrs $(LIBKXLDDST_$(PRODUCT_TYPE))
154
6d2010ae
A
155$(LIBKXLDDST_DYLIB): $(LIBKXLDSYM_DYLIB)
156 @mkdir -p $(DYLIBDST)
157 install -o 0 -g 0 -c -m 555 $< $@
b0d623f7
A
158 $(STRIP) -S -x $@
159
6d2010ae
A
160$(LIBKXLDDST_ARCHIVE): $(LIBKXLDSYM_ARCHIVE)
161 @mkdir -p $(ARCHIVEDST)
162 install -o 0 -g 0 -c -m 555 $< $@
b0d623f7 163
39037602 164KEXTCOPYOBJS=$(OBJROOT)/kextcopyright.o $(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o
6d2010ae
A
165kextcopyright: $(TESTDST)/kextcopyright
166$(TESTDST)/kextcopyright: $(KEXTCOPYOBJS)
167 @mkdir -p $(TESTDST)
b0d623f7 168 $(CC) $(ARCHS) $(KEXTCOPYOBJS) -framework CoreFoundation -o $(OBJROOT)/kextcopyright
6d2010ae
A
169 install -c -m 755 $(OBJROOT)/kextcopyright $@
170
171TESTOBJS=$(OBJROOT)/kxld_test.o $(OBJROOT)/kxld_util.o
172
173ARRAYOBJS=$(OBJROOT)/kxld_array_test.o $(OBJROOT)/kxld_array.o $(TESTOBJS)
174kxld_array_test: $(TESTDST)/kxld_array_test
175$(TESTDST)/kxld_array_test: $(ARRAYOBJS)
176 @mkdir -p $(TESTDST)
177 $(CC) $(ARCHS) $(ARRAYOBJS) -o $(OBJROOT)/kxld_array_test
178 install -c -m 755 $(OBJROOT)/kxld_array_test $@
b0d623f7 179
6d2010ae
A
180DICTOBJS=$(OBJROOT)/kxld_dict_test.o $(OBJROOT)/kxld_dict.o $(OBJROOT)/kxld_array.o $(TESTOBJS)
181kxld_dict_test: $(TESTDST)/kxld_dict_test
182$(TESTDST)/kxld_dict_test: $(DICTOBJS)
183 @mkdir -p $(TESTDST)
b0d623f7 184 $(CC) $(ARCHS) $(DICTOBJS) -o $(OBJROOT)/kxld_dict_test
6d2010ae 185 install -c -m 755 $(OBJROOT)/kxld_dict_test $@
b0d623f7
A
186
187COPYTESTOBJS=$(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o
188copyrighttest: OPTIM+=-DTEST
6d2010ae
A
189copyrighttest: $(TESTDST)/copyrighttest
190$(TESTDST)/copyrighttest: $(COPYTESTOBJS)
191 @mkdir -p $(TESTDST)
b0d623f7 192 $(CC) $(ARCHS) $(COPYTESTOBJS) -framework CoreFoundation -framework IOKit -o $(OBJROOT)/copyrighttest
6d2010ae 193 install -c -m 755 $(OBJROOT)/copyrighttest $@
b0d623f7 194
6d2010ae 195analyze:
3e170ce0
A
196 @$(CLANG_ANALYZER) $(CFLAGS) $(INCLUDES) $(filter-out WKdm%.c,$(wildcard *.c))
197 @$(CLANG_ANALYZER) $(CFLAGS) $(INCLUDES) -I$(SRCROOT) tests/*.c
6d2010ae 198 @rm -f *.plist
b0d623f7 199
39037602 200clean:
b0d623f7
A
201 @rm -rf $(OBJROOT)/*
202
203fullclean:
204ifdef ROOT
205 @rm -rf $(ROOT)
206else
207 @rm -rf $(OBJROOT) $(DSTROOT) $(SYMROOT)
208endif
209
210# Automatically build dependency information when .c or .h files change based
211# on implicit rule for .d:.c
212-include $(OBJS:.o=.d)