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