]> git.saurik.com Git - apple/xnu.git/blob - libkern/kmod/Makefile.kmod
xnu-1699.32.7.tar.gz
[apple/xnu.git] / libkern / kmod / Makefile.kmod
1 #
2 # Kernel Module Library code makefile
3 #
4
5 export MakeInc_cmd=${SRCROOT}/makedefs/MakeInc.cmd
6 export MakeInc_def=${SRCROOT}/makedefs/MakeInc.def
7 export MakeInc_rule=${SRCROOT}/makedefs/MakeInc.rule
8 export MakeInc_dir=${SRCROOT}/makedefs/MakeInc.dir
9
10
11 include $(MakeInc_cmd)
12 include $(MakeInc_def)
13
14 INSTALL_DIR = $(DSTROOT)/usr/lib
15 KMOD_NAME = libkmod
16 KMODCPP_NAME = libkmodc++
17 LIB_INSTALL_FLAGS = -p -m 444
18
19 # -mkernel implies -mlong-branch/-mlong-calls/-mno-red-zone as needed for
20 # code linked into kexts
21 # -fno-stack-protector is necessary for the kernel, but not for kexts
22 CFLAGS_KMOD = $(filter-out -O0 -O1 -O2 -O3 -O4 -Os -Oz -freorder-blocks -flto -fno-stack-protector,$(CFLAGS)) \
23 -Os -mkernel -Wall
24
25 ifneq ($(MACHINE_CONFIG), DEFAULT)
26 COMPOBJROOT = $(OBJROOT)/$(KERNEL_CONFIG)_$(ARCH_CONFIG)_$(MACHINE_CONFIG)/$(COMPONENT)/kmod
27 INSTOBJROOT = $(OBJROOT)/$(INSTALL_TYPE)_$(ARCH_CONFIG)_$(MACHINE_CONFIG)/$(COMPONENT)/kmod
28 else
29 COMPOBJROOT = $(OBJROOT)/$(KERNEL_CONFIG)_$(ARCH_CONFIG)/$(COMPONENT)/kmod
30 INSTOBJROOT = $(OBJROOT)/$(INSTALL_TYPE)_$(ARCH_CONFIG)/$(COMPONENT)/kmod
31 endif
32
33
34 KMOD_CFILES = c_start.c c_stop.c
35 KMODCPP_CFILES = cplus_start.c cplus_stop.c
36
37 KMOD_OFILES = $(KMOD_CFILES:.c=.o)
38 KMODCPP_OFILES = $(KMODCPP_CFILES:.c=.o)
39
40 ALL_OFILES = $(KMOD_OFILES) $(KMODCPP_OFILES)
41
42 $(ALL_OFILES): %.o : %.c
43 @echo LIBKMOD_CC $@
44 $(_v)${LIBKMOD_CC} -c ${CFLAGS_KMOD} ${${join $@,_CFLAGS}} ${INCFLAGS} ${${join $@,_INCFLAGS}} -o $(COMPOBJROOT)/$(*F).o $<
45
46 $(COMPOBJROOT)/$(KMOD_NAME).a: $(KMOD_OFILES)
47 @echo LIBTOOL $(notdir $@)
48 $(_v)$(LIBTOOL) -static -o $@ $^ $(_vstdout) 2>&1
49
50 $(COMPOBJROOT)/$(KMODCPP_NAME).a: $(KMODCPP_OFILES)
51 @echo LIBTOOL $(notdir $@)
52 $(_v)$(LIBTOOL) -static -o $@ $^ $(_vstdout) 2>&1
53
54 do_build_all: $(COMPOBJROOT)/$(KMOD_NAME).a $(COMPOBJROOT)/$(KMODCPP_NAME).a
55
56 $(INSTALL_DIR)/%.a: $(INSTOBJROOT)/%.a
57 @echo Installing $< in $@;
58 $(_v)$(RM) $@ || true; \
59 ${MKDIR} $(INSTALL_DIR) $(SYMROOT); \
60 if [ $(MACHINE_CONFIG) = DEFAULT ]; then \
61 allarchs=""; \
62 for onearch in $(INSTALL_ARCHS); do \
63 if [ $${onearch} = ARM ] ; then \
64 archdir=$(OBJROOT)/$(KERNEL_CONFIG)_$${onearch}_$(DEFAULT_ARM_MACHINE_CONFIG)/$(COMPONENT); \
65 else \
66 archdir=$(OBJROOT)/$(KERNEL_CONFIG)_$${onearch}/$(COMPONENT); \
67 fi; \
68 if [ -e $${archdir}/kmod/$(*F).a ]; then \
69 allarchs="$${allarchs} $${archdir}/kmod/$(*F).a"; \
70 fi; \
71 done; \
72 cmd="$(LIPO) $${allarchs} -create -output $(SYMROOT)/$(*F).a"; \
73 echo $$cmd; eval $$cmd; \
74 else \
75 my_counter=1; \
76 my_innercounter=1; \
77 outputfile=$(SYMROOT)/$(*F).a; \
78 for my_config in $(TARGET_CONFIGS_UC); do \
79 if [ $${my_counter} -eq 1 ]; then \
80 my_counter=2; \
81 my_kconfig=$${my_config}; \
82 elif [ $${my_counter} -eq 2 ]; then \
83 my_counter=3; \
84 my_aconfig=$${my_config}; \
85 else \
86 my_counter=1; \
87 if [ $${my_aconfig} = ARM ] ; then \
88 if [ $${my_config} = DEFAULT ] ; then \
89 my_config=$(DEFAULT_ARM_MACHINE_CONFIG); \
90 fi; \
91 fi; \
92 inputfile=$(OBJROOT)/$${my_kconfig}_$${my_aconfig}_$${my_config}/$(COMPONENT)/kmod/$(*F).a; \
93 if [ -e $${inputfile} ]; then \
94 if [ $${my_innercounter} -eq 1 ]; then \
95 my_innercounter=2; \
96 cmd="$(LIPO) -create $${inputfile} -o $${outputfile}"; \
97 else \
98 cmd="$(LIPO) -create $${outputfile} $${inputfile} -o $${outputfile} || true"; \
99 fi; \
100 echo $$cmd; eval $$cmd; \
101 fi; \
102 fi; \
103 done; \
104 fi; \
105 cmd="$(INSTALL) $(LIB_INSTALL_FLAGS) $(SYMROOT)/$(*F).a $@"; \
106 echo $$cmd; eval $$cmd
107
108 do_build_install: $(INSTALL_DIR)/$(KMOD_NAME).a $(INSTALL_DIR)/$(KMODCPP_NAME).a
109
110 # include $(MakeInc_rule)
111 include $(MakeInc_dir)