]>
Commit | Line | Data |
---|---|---|
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 | |
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 | |
50 | TESTDST=./BUILD/tests | |
51 | ||
52 | # Flags | |
53 | SDKROOT ?= / | |
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 \ | |
59 | -isysroot $(SDKROOT) | |
60 | LDFLAGS=$(ARCHS) -dynamiclib -install_name $(LIBKXLDNAME) \ | |
61 | -compatibility_version $(COMPATIBILITY_VERSION) \ | |
62 | -current_version $(CURRENT_VERSION) -isysroot $(SDKROOT) -lstdc++ | |
63 | INCLUDES=-I$(HDRSRC) $(INCFLAGS_EXTERN) | |
64 | ||
65 | # Tools | |
66 | CC = xcrun -sdk $(SDKROOT) cc | |
67 | LIBTOOL = xcrun -sdk $(SDKROOT) libtool | |
68 | STRIP = xcrun -sdk $(SDKROOT) strip | |
69 | ||
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 | |
73 | endif | |
74 | ||
75 | # Files | |
76 | HDR_NAMES=kxld.h kxld_types.h | |
77 | OBJ_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 | |
80 | HDRS=$(addprefix $(HDRSRC)/, $(HDR_NAMES)) | |
81 | OBJS=$(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 | ||
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 | |
97 | @set -e; rm -f $@; \ | |
98 | $(CC) $(INCLUDES) -MM $< | $(SEDOBJS) | $(SEDSRCS) > $@; | |
99 | ||
100 | # Rules | |
101 | release: OPTIM=-Os -dynamic | |
102 | release: build | |
103 | ||
104 | debug: OPTIM=-O0 -DDEBUG -dynamic | |
105 | debug: build | |
106 | ||
107 | profile: OPTIM=-Os -pg -dynamic | |
108 | profile: build | |
109 | ||
110 | tests: OPTIM=-O0 -DDEBUG | |
111 | tests: kxld_dict_test copyrighttest | |
112 | ||
113 | build: $(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 | ||
123 | installhdrs: | |
124 | @[ -d $(HDRDST) ] || mkdir -p $(HDRDST) | |
125 | install -o 0 -g 0 -c -m 444 $(HDRS) $(HDRDST) | |
126 | ||
127 | install: 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 | ||
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) | |
143 | ||
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) | |
148 | ||
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) | |
154 | ||
155 | $(TESTDST): | |
156 | @[ -d $(TESTDST) ] || mkdir -p $(TESTDST) | |
157 | ||
158 | clean: | |
159 | @rm -rf $(OBJROOT)/* | |
160 | ||
161 | fullclean: | |
162 | ifdef ROOT | |
163 | @rm -rf $(ROOT) | |
164 | else | |
165 | @rm -rf $(OBJROOT) $(DSTROOT) $(SYMROOT) | |
166 | endif | |
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 |