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 ################################################################################
7 COMPATIBILITY_VERSION=1
21 HDRSRC=$(SRCROOT)/libkern/libkern
22 OBJSRC=$(SRCROOT)/libkern/kxld
25 HDRSRC=$(SRCROOT)/../libkern
30 ARCHS=$(addprefix -arch , $(RC_ARCHS))
32 ARCHS=-arch i386 -arch x86_64 -arch ppc
33 RC_CFLAGS=$(ARCHS) -pipe
38 HDRDST=$(DSTROOT)/usr/local/include
39 DYLIBDST=$(DSTROOT)/usr/lib/system
40 ARCHIVEDST=$(DSTROOT)/usr/local/lib
41 LIBKXLD_DYLIB=libkxld.dylib
42 LIBKXLD_ARCHIVE=libkxld.a
43 LIBKXLD_INSTALLNAME=/usr/lib/system/$(LIBKXLD_DYLIB)
44 LIBKXLDOBJ_DYLIB=$(OBJROOT)/$(LIBKXLD_DYLIB)
45 LIBKXLDOBJ_ARCHIVE=$(OBJROOT)/$(LIBKXLD_ARCHIVE)
46 LIBKXLDSYM_DYLIB=$(SYMROOT)/$(LIBKXLD_DYLIB)
47 LIBKXLDSYM_ARCHIVE=$(SYMROOT)/$(LIBKXLD_ARCHIVE)
48 LIBKXLDDST_DYLIB=$(DYLIBDST)/$(LIBKXLD_DYLIB)
49 LIBKXLDDST_ARCHIVE=$(ARCHIVEDST)/$(LIBKXLD_ARCHIVE)
50 TESTSRC=$(SRCROOT)/tests
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 \
59 -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -g
60 LDFLAGS=$(ARCHS) -dynamiclib -install_name $(LIBKXLD_INSTALLNAME) \
61 -compatibility_version $(COMPATIBILITY_VERSION) \
62 -current_version $(CURRENT_VERSION) -lstdc++
66 CFLAGS += -isysroot $(SDKROOT)
67 LDFLAGS += -isysroot $(SDKROOT)
71 CC = xcrun -sdk $(SDKROOT) cc
72 CLANG_ANALYZER = clang --analyze
73 LIBTOOL = xcrun -sdk $(SDKROOT) libtool
74 STRIP = xcrun -sdk $(SDKROOT) strip
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
82 HDR_NAMES=kxld.h kxld_types.h WKdm.h
83 OBJ_NAMES=kxld.o kxld_array.o kxld_copyright.o kxld_demangle.o kxld_dict.o \
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
87 HDRS=$(addprefix $(HDRSRC)/, $(HDR_NAMES))
88 OBJS=$(addprefix $(OBJROOT)/, $(OBJ_NAMES))
90 $(shell [ -d $(OBJROOT) ] || mkdir -p $(OBJROOT))
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 $@
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
105 $(CC) $(INCLUDES) -MM $< | $(SEDOBJS) | $(SEDSRCS) > $@;
108 release: OPTIM=-Os -dynamic
111 debug: OPTIM=-O0 -DDEBUG -dynamic
114 profile: OPTIM=-Os -pg -dynamic
117 tests: OPTIM=-O0 -DDEBUG
118 tests: kxld_array_test kxld_dict_test copyrighttest
120 build: $(LIBKXLDSYM_$(PRODUCT_TYPE))
122 $(LIBKXLDSYM_DYLIB): $(LIBKXLDOBJ_DYLIB)
124 install -c -m 644 $< $@
126 $(LIBKXLDSYM_ARCHIVE): $(LIBKXLDOBJ_ARCHIVE)
128 install -c -m 644 $< $@
130 $(LIBKXLDOBJ_DYLIB): $(OBJS)
131 $(CC) $(LDFLAGS) -o $@ $^
133 $(LIBKXLDOBJ_ARCHIVE): $(OBJS)
134 $(LIBTOOL) -static -o $@ $^
138 install -o 0 -g 0 -c -m 444 $(HDRS) $(HDRDST)
140 install: release installhdrs $(LIBKXLDDST_$(PRODUCT_TYPE))
142 $(LIBKXLDDST_DYLIB): $(LIBKXLDSYM_DYLIB)
143 @mkdir -p $(DYLIBDST)
144 install -o 0 -g 0 -c -m 555 $< $@
147 $(LIBKXLDDST_ARCHIVE): $(LIBKXLDSYM_ARCHIVE)
148 @mkdir -p $(ARCHIVEDST)
149 install -o 0 -g 0 -c -m 555 $< $@
152 KEXTCOPYOBJS=$(OBJROOT)/kextcopyright.o $(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o
153 kextcopyright: $(TESTDST)/kextcopyright
154 $(TESTDST)/kextcopyright: $(KEXTCOPYOBJS)
156 $(CC) $(ARCHS) $(KEXTCOPYOBJS) -framework CoreFoundation -o $(OBJROOT)/kextcopyright
157 install -c -m 755 $(OBJROOT)/kextcopyright $@
159 TESTOBJS=$(OBJROOT)/kxld_test.o $(OBJROOT)/kxld_util.o
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)
165 $(CC) $(ARCHS) $(ARRAYOBJS) -o $(OBJROOT)/kxld_array_test
166 install -c -m 755 $(OBJROOT)/kxld_array_test $@
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)
172 $(CC) $(ARCHS) $(DICTOBJS) -o $(OBJROOT)/kxld_dict_test
173 install -c -m 755 $(OBJROOT)/kxld_dict_test $@
175 COPYTESTOBJS=$(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o
176 copyrighttest: OPTIM+=-DTEST
177 copyrighttest: $(TESTDST)/copyrighttest
178 $(TESTDST)/copyrighttest: $(COPYTESTOBJS)
180 $(CC) $(ARCHS) $(COPYTESTOBJS) -framework CoreFoundation -framework IOKit -o $(OBJROOT)/copyrighttest
181 install -c -m 755 $(OBJROOT)/copyrighttest $@
184 @$(CLANG_ANALYZER) *.c
185 @$(CLANG_ANALYZER) -I. tests/*.c
195 @rm -rf $(OBJROOT) $(DSTROOT) $(SYMROOT)
198 # Automatically build dependency information when .c or .h files change based
199 # on implicit rule for .d:.c
200 -include $(OBJS:.o=.d)