]> git.saurik.com Git - apple/xnu.git/blame - libkern/kxld/Makefile
xnu-1504.7.4.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
39LIBDST=$(DSTROOT)/usr/lib/system
40ARCHIVEDST=$(DSTROOT)/usr/local/lib
41LIBOBJ=$(OBJROOT)/libkxld.o
42LIBKXLD_DYLIB=libkxld.dylib
43LIBKXLD_ARCHIVE=libkxld.a
44LIBKXLDNAME=/usr/lib/system/$(LIBKXLD_DYLIB)
45LIBKXLDOBJ_DYLIB=$(OBJROOT)/$(LIBKXLD_DYLIB)
46LIBKXLDOBJ_ARCHIVE=$(OBJROOT)/$(LIBKXLD_ARCHIVE)
47LIBKXLDDST_DYLIB=$(LIBDST)/$(LIBKXLD_DYLIB)
48LIBKXLDDST_ARCHIVE=$(ARCHIVEDST)/$(LIBKXLD_ARCHIVE)
49TESTSRC=$(SRCROOT)/tests
50TESTDST=./BUILD/tests
51
52# Flags
53SDKROOT ?= /
54CFLAGS=-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 \
59 -isysroot $(SDKROOT)
60LDFLAGS=$(ARCHS) -dynamiclib -install_name $(LIBKXLDNAME) \
61 -compatibility_version $(COMPATIBILITY_VERSION) \
b7266188 62 -current_version $(CURRENT_VERSION) -isysroot $(SDKROOT) -lstdc++
b0d623f7
A
63INCLUDES=-I$(HDRSRC) $(INCFLAGS_EXTERN)
64
65# Tools
66CC = xcrun -sdk $(SDKROOT) cc
67LIBTOOL = xcrun -sdk $(SDKROOT) libtool
68STRIP = xcrun -sdk $(SDKROOT) strip
69
70# Turn on -Wno-cast-align for arm since it won't build without it
71ifeq ($(findstring arm, $(ARCHS)),arm)
72CFLAGS+=-Wno-cast-align
73endif
74
75# Files
76HDR_NAMES=kxld.h kxld_types.h
b7266188
A
77OBJ_NAMES=kxld.o kxld_array.o kxld_copyright.o kxld_demangle.o kxld_dict.o \
78 kxld_kext.o kxld_reloc.o kxld_sect.o kxld_seg.o kxld_sym.o kxld_state.o \
79 kxld_symtab.o kxld_util.o kxld_uuid.o kxld_vtable.o
b0d623f7
A
80HDRS=$(addprefix $(HDRSRC)/, $(HDR_NAMES))
81OBJS=$(addprefix $(OBJROOT)/, $(OBJ_NAMES))
82
83$(shell [ -d $(OBJROOT) ] || mkdir -p $(OBJROOT))
84
85# Implicit rules
86%.o : %.c
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 $@
91
92SRCROOTESC=$(subst /,\/,$(SRCROOT))
93OBJROOTESC=$(subst /,\/,$(OBJROOT))
94SEDOBJS=sed -E 's/(^[a-z_]+)\.o/$(OBJROOTESC)\/\1\.o $(OBJROOTESC)\/\1\.d/'
95SEDSRCS=sed -E 's/([a-z_]+\.[ch])/$(SRCROOTESC)\/\1/g'
96$(OBJROOT)/%.d: $(OBJSRC)/%.c
97 @set -e; rm -f $@; \
98 $(CC) $(INCLUDES) -MM $< | $(SEDOBJS) | $(SEDSRCS) > $@;
99
100# Rules
101release: OPTIM=-Os -dynamic
102release: build
103
104debug: OPTIM=-O0 -DDEBUG -dynamic
105debug: build
106
107profile: OPTIM=-Os -pg -dynamic
108profile: build
109
110tests: OPTIM=-O0 -DDEBUG
111tests: kxld_dict_test copyrighttest
112
113build: $(LIBKXLDOBJ_$(PRODUCT_TYPE))
114 @[ -d $(SYMROOT) ] || mkdir -p $(SYMROOT)
115 install -c -m 644 $< $(SYMROOT)
116
117$(LIBKXLDOBJ_DYLIB): $(OBJS)
118 $(CC) $(LDFLAGS) -o $@ $^
119
120$(LIBKXLDOBJ_ARCHIVE): $(OBJS)
121 $(LIBTOOL) -static -o $@ $^
122
123installhdrs:
124 @[ -d $(HDRDST) ] || mkdir -p $(HDRDST)
125 install -o 0 -g 0 -c -m 444 $(HDRS) $(HDRDST)
126
127install: release installhdrs $(LIBKXLDDST_$(PRODUCT_TYPE))
128
129$(LIBKXLDDST_DYLIB):
130 @[ -d $(LIBDST) ] || mkdir -p $(LIBDST)
131 install -o 0 -g 0 -c -m 555 $(SYMROOT)/$(LIBKXLD_DYLIB) $(LIBDST)
132 $(STRIP) -S -x $@
133
134$(LIBKXLDDST_ARCHIVE):
135 @[ -d $(ARCHIVEDST) ] || mkdir -p $(ARCHIVEDST)
136 install -o 0 -g 0 -c -m 555 $(SYMROOT)/$(LIBKXLD_ARCHIVE) $(ARCHIVEDST)
137
138
139KEXTCOPYOBJS=$(OBJROOT)/kextcopyright.o $(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o
140kextcopyright: $(KEXTCOPYOBJS) $(TESTDST)
141 $(CC) $(ARCHS) $(KEXTCOPYOBJS) -framework CoreFoundation -o $(OBJROOT)/kextcopyright
142 install -c -m 755 $(OBJROOT)/kextcopyright $(TESTDST)
143
144DICTOBJS=$(OBJROOT)/kxld_dict_test.o $(OBJROOT)/kxld_dict.o $(OBJROOT)/kxld_array.o $(OBJROOT)/kxld_util.o
145kxld_dict_test: $(DICTOBJS) $(TESTDST)
146 $(CC) $(ARCHS) $(DICTOBJS) -o $(OBJROOT)/kxld_dict_test
147 install -c -m 755 $(OBJROOT)/kxld_dict_test $(TESTDST)
148
149COPYTESTOBJS=$(OBJROOT)/kxld_copyright.o $(OBJROOT)/kxld_util.o
150copyrighttest: OPTIM+=-DTEST
151copyrighttest: $(KEXTCOPYOBJS) $(TESTDST)
152 $(CC) $(ARCHS) $(COPYTESTOBJS) -framework CoreFoundation -framework IOKit -o $(OBJROOT)/copyrighttest
153 install -c -m 755 $(OBJROOT)/copyrighttest $(TESTDST)
154
155$(TESTDST):
156 @[ -d $(TESTDST) ] || mkdir -p $(TESTDST)
157
158clean:
159 @rm -rf $(OBJROOT)/*
160
161fullclean:
162ifdef ROOT
163 @rm -rf $(ROOT)
164else
165 @rm -rf $(OBJROOT) $(DSTROOT) $(SYMROOT)
166endif
167
168# Automatically build dependency information when .c or .h files change based
169# on implicit rule for .d:.c
170-include $(OBJS:.o=.d)
171