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