]> git.saurik.com Git - apple/xnu.git/blame - libkern/kxld/Makefile
xnu-1699.22.73.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
21HDRSRC=$(SRCROOT)/libkern/libkern
22OBJSRC=$(SRCROOT)/libkern/kxld
23else
24SRCROOT=.
25HDRSRC=$(SRCROOT)/../libkern
26OBJSRC=$(SRCROOT)
27ROOT=BUILD
28endif
29ifdef RC_CFLAGS
30ARCHS=$(addprefix -arch , $(RC_ARCHS))
31else
32ARCHS=-arch i386 -arch x86_64 -arch ppc
33RC_CFLAGS=$(ARCHS) -pipe
34endif
35
36PRODUCT_TYPE ?= DYLIB
37
38HDRDST=$(DSTROOT)/usr/local/include
6d2010ae 39DYLIBDST=$(DSTROOT)/usr/lib/system
b0d623f7 40ARCHIVEDST=$(DSTROOT)/usr/local/lib
b0d623f7
A
41LIBKXLD_DYLIB=libkxld.dylib
42LIBKXLD_ARCHIVE=libkxld.a
6d2010ae 43LIBKXLD_INSTALLNAME=/usr/lib/system/$(LIBKXLD_DYLIB)
b0d623f7
A
44LIBKXLDOBJ_DYLIB=$(OBJROOT)/$(LIBKXLD_DYLIB)
45LIBKXLDOBJ_ARCHIVE=$(OBJROOT)/$(LIBKXLD_ARCHIVE)
6d2010ae
A
46LIBKXLDSYM_DYLIB=$(SYMROOT)/$(LIBKXLD_DYLIB)
47LIBKXLDSYM_ARCHIVE=$(SYMROOT)/$(LIBKXLD_ARCHIVE)
48LIBKXLDDST_DYLIB=$(DYLIBDST)/$(LIBKXLD_DYLIB)
b0d623f7
A
49LIBKXLDDST_ARCHIVE=$(ARCHIVEDST)/$(LIBKXLD_ARCHIVE)
50TESTSRC=$(SRCROOT)/tests
51TESTDST=./BUILD/tests
52
53# Flags
54SDKROOT ?= /
55CFLAGS=-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
60LDFLAGS=$(ARCHS) -dynamiclib -install_name $(LIBKXLD_INSTALLNAME) \
b0d623f7 61 -compatibility_version $(COMPATIBILITY_VERSION) \
6d2010ae
A
62 -current_version $(CURRENT_VERSION) -lstdc++
63INCLUDES=-I$(HDRSRC)
64
65ifneq ($(SDKROOT),/)
66 CFLAGS += -isysroot $(SDKROOT)
67 LDFLAGS += -isysroot $(SDKROOT)
68endif
b0d623f7
A
69
70# Tools
71CC = xcrun -sdk $(SDKROOT) cc
6d2010ae 72CLANG_ANALYZER = clang --analyze
b0d623f7
A
73LIBTOOL = xcrun -sdk $(SDKROOT) libtool
74STRIP = xcrun -sdk $(SDKROOT) strip
75
76# Turn on -Wno-cast-align for arm since it won't build without it
77ifeq ($(findstring arm, $(ARCHS)),arm)
78CFLAGS+=-Wno-cast-align
79endif
80
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 \
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
87HDRS=$(addprefix $(HDRSRC)/, $(HDR_NAMES))
88OBJS=$(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
99SRCROOTESC=$(subst /,\/,$(SRCROOT))
100OBJROOTESC=$(subst /,\/,$(OBJROOT))
101SEDOBJS=sed -E 's/(^[a-z_]+)\.o/$(OBJROOTESC)\/\1\.o $(OBJROOTESC)\/\1\.d/'
102SEDSRCS=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
108release: OPTIM=-Os -dynamic
109release: build
110
111debug: OPTIM=-O0 -DDEBUG -dynamic
112debug: build
113
114profile: OPTIM=-Os -pg -dynamic
115profile: build
116
117tests: OPTIM=-O0 -DDEBUG
6d2010ae
A
118tests: kxld_array_test kxld_dict_test copyrighttest
119
120build: $(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
136installhdrs:
6d2010ae 137 @mkdir -p $(HDRDST)
b0d623f7
A
138 install -o 0 -g 0 -c -m 444 $(HDRS) $(HDRDST)
139
140install: 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
152KEXTCOPYOBJS=$(OBJROOT)/kextcopyright.o $(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o
6d2010ae
A
153kextcopyright: $(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
159TESTOBJS=$(OBJROOT)/kxld_test.o $(OBJROOT)/kxld_util.o
160
161ARRAYOBJS=$(OBJROOT)/kxld_array_test.o $(OBJROOT)/kxld_array.o $(TESTOBJS)
162kxld_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
168DICTOBJS=$(OBJROOT)/kxld_dict_test.o $(OBJROOT)/kxld_dict.o $(OBJROOT)/kxld_array.o $(TESTOBJS)
169kxld_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
175COPYTESTOBJS=$(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o
176copyrighttest: OPTIM+=-DTEST
6d2010ae
A
177copyrighttest: $(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
183analyze:
184 @$(CLANG_ANALYZER) *.c
185 @$(CLANG_ANALYZER) -I. tests/*.c
186 @rm -f *.plist
b0d623f7
A
187
188clean:
189 @rm -rf $(OBJROOT)/*
190
191fullclean:
192ifdef ROOT
193 @rm -rf $(ROOT)
194else
195 @rm -rf $(OBJROOT) $(DSTROOT) $(SYMROOT)
196endif
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