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 LIBDST=$(DSTROOT)/usr/lib/system
40 ARCHIVEDST=$(DSTROOT)/usr/local/lib
41 LIBOBJ=$(OBJROOT)/libkxld.o
42 LIBKXLD_DYLIB=libkxld.dylib
43 LIBKXLD_ARCHIVE=libkxld.a
44 LIBKXLDNAME=/usr/lib/system/$(LIBKXLD_DYLIB)
45 LIBKXLDOBJ_DYLIB=$(OBJROOT)/$(LIBKXLD_DYLIB)
46 LIBKXLDOBJ_ARCHIVE=$(OBJROOT)/$(LIBKXLD_ARCHIVE)
47 LIBKXLDDST_DYLIB=$(LIBDST)/$(LIBKXLD_DYLIB)
48 LIBKXLDDST_ARCHIVE=$(ARCHIVEDST)/$(LIBKXLD_ARCHIVE)
49 TESTSRC=$(SRCROOT)/tests
54 CFLAGS=-std=c99 -Wall -Wextra -Werror -pedantic -Wformat=2 -Wcast-align \
55 -Wwrite-strings -Wshorten-64-to-32 -Wshadow -Winit-self -Wpointer-arith \
56 -Wno-format-y2k -W -Wstrict-prototypes -Wmissing-prototypes -Wreturn-type \
57 -Wcast-qual -Wwrite-strings -Wswitch -Wcast-align -Wbad-function-cast \
58 -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -g \
60 LDFLAGS=$(ARCHS) -dynamiclib -install_name $(LIBKXLDNAME) \
61 -compatibility_version $(COMPATIBILITY_VERSION) \
62 -current_version $(CURRENT_VERSION) -isysroot $(SDKROOT)
63 INCLUDES=-I$(HDRSRC) $(INCFLAGS_EXTERN)
66 CC = xcrun -sdk $(SDKROOT) cc
67 LIBTOOL = xcrun -sdk $(SDKROOT) libtool
68 STRIP = xcrun -sdk $(SDKROOT) strip
70 # Turn on -Wno-cast-align for arm since it won't build without it
71 ifeq ($(findstring arm, $(ARCHS)),arm)
72 CFLAGS+=-Wno-cast-align
76 HDR_NAMES=kxld.h kxld_types.h
77 OBJ_NAMES=kxld.o kxld_array.o kxld_copyright.o kxld_dict.o kxld_kext.o kxld_reloc.o \
78 kxld_sect.o kxld_seg.o kxld_sym.o kxld_state.o kxld_symtab.o kxld_util.o \
79 kxld_uuid.o kxld_vtable.o
80 HDRS=$(addprefix $(HDRSRC)/, $(HDR_NAMES))
81 OBJS=$(addprefix $(OBJROOT)/, $(OBJ_NAMES))
83 $(shell [ -d $(OBJROOT) ] || mkdir -p $(OBJROOT))
87 $(OBJROOT)/%.o : $(OBJSRC)/%.c
88 $(CC) $(RC_CFLAGS) $(CFLAGS) $(OPTIM) $(INCLUDES) -c $< -o $@
89 $(OBJROOT)/%.o : $(TESTSRC)/%.c
90 $(CC) $(RC_CFLAGS) $(CFLAGS) -O0 -DDEBUG $(INCLUDES) -I $(SRCROOT) -c $< -o $@
92 SRCROOTESC=$(subst /,\/,$(SRCROOT))
93 OBJROOTESC=$(subst /,\/,$(OBJROOT))
94 SEDOBJS=sed -E 's/(^[a-z_]+)\.o/$(OBJROOTESC)\/\1\.o $(OBJROOTESC)\/\1\.d/'
95 SEDSRCS=sed -E 's/([a-z_]+\.[ch])/$(SRCROOTESC)\/\1/g'
96 $(OBJROOT)/%.d: $(OBJSRC)/%.c
98 $(CC) $(INCLUDES) -MM $< | $(SEDOBJS) | $(SEDSRCS) > $@;
101 release: OPTIM=-Os -dynamic
104 debug: OPTIM=-O0 -DDEBUG -dynamic
107 profile: OPTIM=-Os -pg -dynamic
110 tests: OPTIM=-O0 -DDEBUG
111 tests: kxld_dict_test copyrighttest
113 build: $(LIBKXLDOBJ_$(PRODUCT_TYPE))
114 @[ -d $(SYMROOT) ] || mkdir -p $(SYMROOT)
115 install -c -m 644 $< $(SYMROOT)
117 $(LIBKXLDOBJ_DYLIB): $(OBJS)
118 $(CC) $(LDFLAGS) -o $@ $^
120 $(LIBKXLDOBJ_ARCHIVE): $(OBJS)
121 $(LIBTOOL) -static -o $@ $^
124 @[ -d $(HDRDST) ] || mkdir -p $(HDRDST)
125 install -o 0 -g 0 -c -m 444 $(HDRS) $(HDRDST)
127 install: release installhdrs $(LIBKXLDDST_$(PRODUCT_TYPE))
130 @[ -d $(LIBDST) ] || mkdir -p $(LIBDST)
131 install -o 0 -g 0 -c -m 555 $(SYMROOT)/$(LIBKXLD_DYLIB) $(LIBDST)
134 $(LIBKXLDDST_ARCHIVE):
135 @[ -d $(ARCHIVEDST) ] || mkdir -p $(ARCHIVEDST)
136 install -o 0 -g 0 -c -m 555 $(SYMROOT)/$(LIBKXLD_ARCHIVE) $(ARCHIVEDST)
139 KEXTCOPYOBJS=$(OBJROOT)/kextcopyright.o $(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o
140 kextcopyright: $(KEXTCOPYOBJS) $(TESTDST)
141 $(CC) $(ARCHS) $(KEXTCOPYOBJS) -framework CoreFoundation -o $(OBJROOT)/kextcopyright
142 install -c -m 755 $(OBJROOT)/kextcopyright $(TESTDST)
144 DICTOBJS=$(OBJROOT)/kxld_dict_test.o $(OBJROOT)/kxld_dict.o $(OBJROOT)/kxld_array.o $(OBJROOT)/kxld_util.o
145 kxld_dict_test: $(DICTOBJS) $(TESTDST)
146 $(CC) $(ARCHS) $(DICTOBJS) -o $(OBJROOT)/kxld_dict_test
147 install -c -m 755 $(OBJROOT)/kxld_dict_test $(TESTDST)
149 COPYTESTOBJS=$(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o
150 copyrighttest: OPTIM+=-DTEST
151 copyrighttest: $(KEXTCOPYOBJS) $(TESTDST)
152 $(CC) $(ARCHS) $(COPYTESTOBJS) -framework CoreFoundation -framework IOKit -o $(OBJROOT)/copyrighttest
153 install -c -m 755 $(OBJROOT)/copyrighttest $(TESTDST)
156 @[ -d $(TESTDST) ] || mkdir -p $(TESTDST)
165 @rm -rf $(OBJROOT) $(DSTROOT) $(SYMROOT)
168 # Automatically build dependency information when .c or .h files change based
169 # on implicit rule for .d:.c
170 -include $(OBJS:.o=.d)