]>
Commit | Line | Data |
---|---|---|
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 | |
7 | COMPATIBILITY_VERSION=1 | |
8 | CURRENT_VERSION=1 | |
9 | ||
10 | # Paths | |
11 | ifndef DSTROOT | |
12 | DSTROOT=./BUILD/dst | |
13 | endif | |
14 | ifndef OBJROOT | |
15 | OBJROOT=./BUILD/obj | |
16 | endif | |
17 | ifndef SYMROOT | |
18 | SYMROOT=./BUILD/sym | |
19 | endif | |
20 | ifdef SRCROOT | |
316670eb | 21 | EXTHDRSRC=$(SRCROOT)/EXTERNAL_HEADERS |
b0d623f7 A |
22 | HDRSRC=$(SRCROOT)/libkern/libkern |
23 | OBJSRC=$(SRCROOT)/libkern/kxld | |
24 | else | |
25 | SRCROOT=. | |
316670eb | 26 | EXTHDRSRC=$(SRCROOT)/../../EXTERNAL_HEADERS |
b0d623f7 A |
27 | HDRSRC=$(SRCROOT)/../libkern |
28 | OBJSRC=$(SRCROOT) | |
29 | ROOT=BUILD | |
30 | endif | |
31 | ifdef RC_CFLAGS | |
32 | ARCHS=$(addprefix -arch , $(RC_ARCHS)) | |
33 | else | |
316670eb | 34 | ARCHS=-arch i386 -arch x86_64 |
b0d623f7 A |
35 | RC_CFLAGS=$(ARCHS) -pipe |
36 | endif | |
316670eb A |
37 | ifdef INSTALL_LOCATION |
38 | override DSTROOT := $(DSTROOT)/$(INSTALL_LOCATION) | |
39 | endif | |
b0d623f7 A |
40 | |
41 | PRODUCT_TYPE ?= DYLIB | |
42 | ||
43 | HDRDST=$(DSTROOT)/usr/local/include | |
6d2010ae | 44 | DYLIBDST=$(DSTROOT)/usr/lib/system |
b0d623f7 | 45 | ARCHIVEDST=$(DSTROOT)/usr/local/lib |
b0d623f7 A |
46 | LIBKXLD_DYLIB=libkxld.dylib |
47 | LIBKXLD_ARCHIVE=libkxld.a | |
6d2010ae | 48 | LIBKXLD_INSTALLNAME=/usr/lib/system/$(LIBKXLD_DYLIB) |
b0d623f7 A |
49 | LIBKXLDOBJ_DYLIB=$(OBJROOT)/$(LIBKXLD_DYLIB) |
50 | LIBKXLDOBJ_ARCHIVE=$(OBJROOT)/$(LIBKXLD_ARCHIVE) | |
6d2010ae A |
51 | LIBKXLDSYM_DYLIB=$(SYMROOT)/$(LIBKXLD_DYLIB) |
52 | LIBKXLDSYM_ARCHIVE=$(SYMROOT)/$(LIBKXLD_ARCHIVE) | |
53 | LIBKXLDDST_DYLIB=$(DYLIBDST)/$(LIBKXLD_DYLIB) | |
b0d623f7 A |
54 | LIBKXLDDST_ARCHIVE=$(ARCHIVEDST)/$(LIBKXLD_ARCHIVE) |
55 | TESTSRC=$(SRCROOT)/tests | |
56 | TESTDST=./BUILD/tests | |
57 | ||
58 | # Flags | |
59 | SDKROOT ?= / | |
60 | CFLAGS=-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 |
65 | LDFLAGS=$(ARCHS) -dynamiclib -install_name $(LIBKXLD_INSTALLNAME) \ | |
b0d623f7 | 66 | -compatibility_version $(COMPATIBILITY_VERSION) \ |
6d2010ae | 67 | -current_version $(CURRENT_VERSION) -lstdc++ |
316670eb | 68 | INCLUDES=-I$(HDRSRC) -I$(EXTHDRSRC) |
6d2010ae A |
69 | |
70 | ifneq ($(SDKROOT),/) | |
71 | CFLAGS += -isysroot $(SDKROOT) | |
72 | LDFLAGS += -isysroot $(SDKROOT) | |
73 | endif | |
b0d623f7 A |
74 | |
75 | # Tools | |
316670eb | 76 | CC = xcrun -sdk $(SDKROOT) clang |
6d2010ae | 77 | CLANG_ANALYZER = clang --analyze |
b0d623f7 A |
78 | LIBTOOL = xcrun -sdk $(SDKROOT) libtool |
79 | STRIP = xcrun -sdk $(SDKROOT) strip | |
80 | ||
b0d623f7 | 81 | # Files |
6d2010ae | 82 | HDR_NAMES=kxld.h kxld_types.h WKdm.h |
b7266188 | 83 | OBJ_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 |
88 | HDRS=$(addprefix $(HDRSRC)/, $(HDR_NAMES)) |
89 | OBJS=$(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 | ||
100 | SRCROOTESC=$(subst /,\/,$(SRCROOT)) | |
101 | OBJROOTESC=$(subst /,\/,$(OBJROOT)) | |
102 | SEDOBJS=sed -E 's/(^[a-z_]+)\.o/$(OBJROOTESC)\/\1\.o $(OBJROOTESC)\/\1\.d/' | |
316670eb | 103 | SEDSRCS=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 | |
109 | release: OPTIM=-Os -dynamic | |
110 | release: build | |
111 | ||
112 | debug: OPTIM=-O0 -DDEBUG -dynamic | |
113 | debug: build | |
114 | ||
115 | profile: OPTIM=-Os -pg -dynamic | |
116 | profile: build | |
117 | ||
118 | tests: OPTIM=-O0 -DDEBUG | |
6d2010ae A |
119 | tests: kxld_array_test kxld_dict_test copyrighttest |
120 | ||
121 | build: $(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 | ||
137 | installhdrs: | |
6d2010ae | 138 | @mkdir -p $(HDRDST) |
b0d623f7 A |
139 | install -o 0 -g 0 -c -m 444 $(HDRS) $(HDRDST) |
140 | ||
141 | install: 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 | ||
153 | KEXTCOPYOBJS=$(OBJROOT)/kextcopyright.o $(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o | |
6d2010ae A |
154 | kextcopyright: $(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 | ||
160 | TESTOBJS=$(OBJROOT)/kxld_test.o $(OBJROOT)/kxld_util.o | |
161 | ||
162 | ARRAYOBJS=$(OBJROOT)/kxld_array_test.o $(OBJROOT)/kxld_array.o $(TESTOBJS) | |
163 | kxld_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 |
169 | DICTOBJS=$(OBJROOT)/kxld_dict_test.o $(OBJROOT)/kxld_dict.o $(OBJROOT)/kxld_array.o $(TESTOBJS) |
170 | kxld_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 | |
176 | COPYTESTOBJS=$(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o | |
177 | copyrighttest: OPTIM+=-DTEST | |
6d2010ae A |
178 | copyrighttest: $(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 |
184 | analyze: |
185 | @$(CLANG_ANALYZER) *.c | |
186 | @$(CLANG_ANALYZER) -I. tests/*.c | |
187 | @rm -f *.plist | |
b0d623f7 A |
188 | |
189 | clean: | |
190 | @rm -rf $(OBJROOT)/* | |
191 | ||
192 | fullclean: | |
193 | ifdef ROOT | |
194 | @rm -rf $(ROOT) | |
195 | else | |
196 | @rm -rf $(OBJROOT) $(DSTROOT) $(SYMROOT) | |
197 | endif | |
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 |