]> git.saurik.com Git - apple/xnu.git/blame - libkern/kxld/Makefile
xnu-7195.50.7.100.1.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 40
f427ee49 41PRODUCT_TYPE ?= ALL
b0d623f7
A
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
f427ee49
A
60# Build both the dylib and archive
61LIBKXLDDST_ALL=$(LIBKXLDDST_DYLIB) $(LIBKXLDDST_ARCHIVE)
62
b0d623f7 63# Flags
fe8ab488
A
64ifdef SDKROOT
65 SDK_DIR := $(shell xcodebuild -version -sdk $(SDKROOT) Path)
66endif
67
68ifeq ($(strip $(SDK_DIR)),)
69 SDK_DIR := /
70endif
71
d9a64523 72
39236c6e 73DEFINES = -DPRIVATE
b0d623f7
A
74CFLAGS=-std=c99 -Wall -Wextra -Werror -pedantic -Wformat=2 -Wcast-align \
75 -Wwrite-strings -Wshorten-64-to-32 -Wshadow -Winit-self -Wpointer-arith \
76 -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes -Wreturn-type \
77 -Wcast-qual -Wwrite-strings -Wswitch -Wcast-align -Wbad-function-cast \
6d2010ae
A
78 -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -g
79LDFLAGS=$(ARCHS) -dynamiclib -install_name $(LIBKXLD_INSTALLNAME) \
b0d623f7 80 -compatibility_version $(COMPATIBILITY_VERSION) \
6d2010ae 81 -current_version $(CURRENT_VERSION) -lstdc++
39236c6e 82INCLUDES=-I$(HDRSRC) -isystem $(EXTHDRSRC)
6d2010ae 83
fe8ab488
A
84ifneq ($(SDK_DIR),/)
85 CFLAGS += -isysroot $(SDK_DIR)
86 LDFLAGS += -isysroot $(SDK_DIR)
6d2010ae 87endif
b0d623f7
A
88
89# Tools
fe8ab488 90CC = xcrun -sdk $(SDK_DIR) clang
fe8ab488
A
91LIBTOOL = xcrun -sdk $(SDK_DIR) libtool
92STRIP = xcrun -sdk $(SDK_DIR) strip
93DSYMUTIL = xcrun -sdk $(SDK_DIR) dsymutil
b0d623f7 94
b0d623f7 95# Files
39037602 96HDR_NAMES=kxld.h kxld_types.h prelink.h
b7266188 97OBJ_NAMES=kxld.o kxld_array.o kxld_copyright.o kxld_demangle.o kxld_dict.o \
316670eb 98 kxld_kext.o kxld_object.o kxld_reloc.o kxld_sect.o kxld_seg.o \
39037602 99 kxld_srcversion.o kxld_splitinfolc.o kxld_sym.o kxld_symtab.o kxld_util.o kxld_uuid.o \
39236c6e 100 kxld_vtable.o kxld_versionmin.o
316670eb 101
b0d623f7
A
102HDRS=$(addprefix $(HDRSRC)/, $(HDR_NAMES))
103OBJS=$(addprefix $(OBJROOT)/, $(OBJ_NAMES))
104
105$(shell [ -d $(OBJROOT) ] || mkdir -p $(OBJROOT))
106
107# Implicit rules
108%.o : %.c
109$(OBJROOT)/%.o : $(OBJSRC)/%.c
39236c6e 110 $(CC) $(RC_CFLAGS) $(CFLAGS) $(DEFINES) $(OPTIM) $(INCLUDES) -c $< -o $@
b0d623f7 111$(OBJROOT)/%.o : $(TESTSRC)/%.c
3e170ce0 112 $(CC) $(RC_CFLAGS) $(CFLAGS) $(DEFINES) -O0 -DDEBUG $(INCLUDES) -I$(SRCROOT) -c $< -o $@
b0d623f7
A
113
114SRCROOTESC=$(subst /,\/,$(SRCROOT))
115OBJROOTESC=$(subst /,\/,$(OBJROOT))
116SEDOBJS=sed -E 's/(^[a-z_]+)\.o/$(OBJROOTESC)\/\1\.o $(OBJROOTESC)\/\1\.d/'
316670eb 117SEDSRCS=sed -E 's/ ([a-z_]+\.[ch])/ $(SRCROOTESC)\/\1/g'
b0d623f7
A
118$(OBJROOT)/%.d: $(OBJSRC)/%.c
119 @set -e; rm -f $@; \
3e170ce0 120 $(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -MM $< | $(SEDOBJS) | $(SEDSRCS) > $@;
b0d623f7
A
121
122# Rules
123release: OPTIM=-Os -dynamic
124release: build
125
126debug: OPTIM=-O0 -DDEBUG -dynamic
127debug: build
128
129profile: OPTIM=-Os -pg -dynamic
130profile: build
131
132tests: OPTIM=-O0 -DDEBUG
6d2010ae
A
133tests: kxld_array_test kxld_dict_test copyrighttest
134
135build: $(LIBKXLDSYM_$(PRODUCT_TYPE))
b0d623f7 136
6d2010ae
A
137$(LIBKXLDSYM_DYLIB): $(LIBKXLDOBJ_DYLIB)
138 @mkdir -p $(SYMROOT)
139 install -c -m 644 $< $@
fe8ab488 140 $(DSYMUTIL) $@ -o $(LIBKXLDSYM_DYLIB_DSYM)
6d2010ae
A
141
142$(LIBKXLDSYM_ARCHIVE): $(LIBKXLDOBJ_ARCHIVE)
143 @mkdir -p $(SYMROOT)
144 install -c -m 644 $< $@
b0d623f7 145
d9a64523 146
b0d623f7
A
147$(LIBKXLDOBJ_DYLIB): $(OBJS)
148 $(CC) $(LDFLAGS) -o $@ $^
149
150$(LIBKXLDOBJ_ARCHIVE): $(OBJS)
151 $(LIBTOOL) -static -o $@ $^
152
153installhdrs:
6d2010ae 154 @mkdir -p $(HDRDST)
b0d623f7
A
155 install -o 0 -g 0 -c -m 444 $(HDRS) $(HDRDST)
156
157install: release installhdrs $(LIBKXLDDST_$(PRODUCT_TYPE))
158
6d2010ae
A
159$(LIBKXLDDST_DYLIB): $(LIBKXLDSYM_DYLIB)
160 @mkdir -p $(DYLIBDST)
161 install -o 0 -g 0 -c -m 555 $< $@
b0d623f7
A
162 $(STRIP) -S -x $@
163
6d2010ae
A
164$(LIBKXLDDST_ARCHIVE): $(LIBKXLDSYM_ARCHIVE)
165 @mkdir -p $(ARCHIVEDST)
166 install -o 0 -g 0 -c -m 555 $< $@
b0d623f7 167
39037602 168KEXTCOPYOBJS=$(OBJROOT)/kextcopyright.o $(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o
6d2010ae
A
169kextcopyright: $(TESTDST)/kextcopyright
170$(TESTDST)/kextcopyright: $(KEXTCOPYOBJS)
171 @mkdir -p $(TESTDST)
b0d623f7 172 $(CC) $(ARCHS) $(KEXTCOPYOBJS) -framework CoreFoundation -o $(OBJROOT)/kextcopyright
6d2010ae
A
173 install -c -m 755 $(OBJROOT)/kextcopyright $@
174
175TESTOBJS=$(OBJROOT)/kxld_test.o $(OBJROOT)/kxld_util.o
176
177ARRAYOBJS=$(OBJROOT)/kxld_array_test.o $(OBJROOT)/kxld_array.o $(TESTOBJS)
178kxld_array_test: $(TESTDST)/kxld_array_test
179$(TESTDST)/kxld_array_test: $(ARRAYOBJS)
180 @mkdir -p $(TESTDST)
181 $(CC) $(ARCHS) $(ARRAYOBJS) -o $(OBJROOT)/kxld_array_test
182 install -c -m 755 $(OBJROOT)/kxld_array_test $@
b0d623f7 183
6d2010ae
A
184DICTOBJS=$(OBJROOT)/kxld_dict_test.o $(OBJROOT)/kxld_dict.o $(OBJROOT)/kxld_array.o $(TESTOBJS)
185kxld_dict_test: $(TESTDST)/kxld_dict_test
186$(TESTDST)/kxld_dict_test: $(DICTOBJS)
187 @mkdir -p $(TESTDST)
b0d623f7 188 $(CC) $(ARCHS) $(DICTOBJS) -o $(OBJROOT)/kxld_dict_test
6d2010ae 189 install -c -m 755 $(OBJROOT)/kxld_dict_test $@
b0d623f7
A
190
191COPYTESTOBJS=$(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o
192copyrighttest: OPTIM+=-DTEST
6d2010ae
A
193copyrighttest: $(TESTDST)/copyrighttest
194$(TESTDST)/copyrighttest: $(COPYTESTOBJS)
195 @mkdir -p $(TESTDST)
b0d623f7 196 $(CC) $(ARCHS) $(COPYTESTOBJS) -framework CoreFoundation -framework IOKit -o $(OBJROOT)/copyrighttest
6d2010ae 197 install -c -m 755 $(OBJROOT)/copyrighttest $@
b0d623f7 198
39037602 199clean:
b0d623f7
A
200 @rm -rf $(OBJROOT)/*
201
202fullclean:
203ifdef ROOT
204 @rm -rf $(ROOT)
205else
206 @rm -rf $(OBJROOT) $(DSTROOT) $(SYMROOT)
207endif
208
209# Automatically build dependency information when .c or .h files change based
210# on implicit rule for .d:.c
211-include $(OBJS:.o=.d)