]> git.saurik.com Git - apple/xnu.git/blob - libkern/kmod/Makefile.kmod
xnu-1456.1.26.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 CFLAGS_KMOD = $(filter-out -O0 -O1 -O2 -O3 -O4 -Os -Oz,$(CFLAGS)) \
22 -Os -mkernel -Wall
23
24 ifneq ($(MACHINE_CONFIG), DEFAULT)
25 COMPOBJROOT = $(OBJROOT)/$(KERNEL_CONFIG)_$(ARCH_CONFIG)_$(MACHINE_CONFIG)/$(COMPONENT)/kmod
26 INSTOBJROOT = $(OBJROOT)/$(INSTALL_TYPE)_$(ARCH_CONFIG)_$(MACHINE_CONFIG)/$(COMPONENT)/kmod
27 else
28 COMPOBJROOT = $(OBJROOT)/$(KERNEL_CONFIG)_$(ARCH_CONFIG)/$(COMPONENT)/kmod
29 INSTOBJROOT = $(OBJROOT)/$(INSTALL_TYPE)_$(ARCH_CONFIG)/$(COMPONENT)/kmod
30 endif
31
32
33 KMOD_CFILES = c_start.c c_stop.c
34 KMODCPP_CFILES = cplus_start.c cplus_stop.c
35
36 KMOD_OFILES = $(KMOD_CFILES:.c=.o)
37 KMODCPP_OFILES = $(KMODCPP_CFILES:.c=.o)
38
39 ALL_OFILES = $(KMOD_OFILES) $(KMODCPP_OFILES)
40
41 $(ALL_OFILES): %.o : %.c
42 @echo CC $@
43 $(_v)${KCC} -c ${CFLAGS_KMOD} ${${join $@,_CFLAGS}} ${INCFLAGS} ${${join $@,_INCFLAGS}} -o $(COMPOBJROOT)/$(*F).o $<
44
45 $(COMPOBJROOT)/$(KMOD_NAME).a: $(KMOD_OFILES)
46 @echo LIBTOOL $(notdir $@)
47 $(_v)$(LIBTOOL) -static -o $@ $^ $(_vstdout) 2>&1
48
49 $(COMPOBJROOT)/$(KMODCPP_NAME).a: $(KMODCPP_OFILES)
50 @echo LIBTOOL $(notdir $@)
51 $(_v)$(LIBTOOL) -static -o $@ $^ $(_vstdout) 2>&1
52
53 do_build_all: $(COMPOBJROOT)/$(KMOD_NAME).a $(COMPOBJROOT)/$(KMODCPP_NAME).a
54
55 $(INSTALL_DIR)/%.a: $(INSTOBJROOT)/%.a
56 @echo Installing $< in $@;
57 $(_v)$(RM) $@ || true; \
58 ${MKDIR} $(INSTALL_DIR) $(SYMROOT); \
59 if [ $(MACHINE_CONFIG) = DEFAULT ]; then \
60 allarchs=""; \
61 for onearch in $(INSTALL_ARCHS); do \
62 archdir=$(OBJROOT)/$(KERNEL_CONFIG)_$${onearch}/$(COMPONENT); \
63 if [ -e $${archdir}/kmod/$(*F).a ]; then \
64 allarchs="$${allarchs} $${archdir}/kmod/$(*F).a"; \
65 fi; \
66 done; \
67 cmd="$(LIPO) $${allarchs} -create -output $(SYMROOT)/$(*F).a"; \
68 echo $$cmd; eval $$cmd; \
69 else \
70 my_counter=1; \
71 my_innercounter=1; \
72 outputfile=$(SYMROOT)/$(*F).a; \
73 for my_config in $(TARGET_CONFIGS_UC); do \
74 if [ $${my_counter} -eq 1 ]; then \
75 my_counter=2; \
76 my_kconfig=$${my_config}; \
77 elif [ $${my_counter} -eq 2 ]; then \
78 my_counter=3; \
79 my_aconfig=$${my_config}; \
80 else \
81 my_counter=1; \
82 inputfile=$(OBJROOT)/$${my_kconfig}_$${my_aconfig}_$${my_config}/$(COMPONENT)/kmod/$(*F).a; \
83 if [ -e $${inputfile} ]; then \
84 if [ $${my_innercounter} -eq 1 ]; then \
85 my_innercounter=2; \
86 cmd="$(LIPO) -create $${inputfile} -o $${outputfile}"; \
87 else \
88 cmd="$(LIPO) -create $${outputfile} $${inputfile} -o $${outputfile} || true"; \
89 fi; \
90 echo $$cmd; eval $$cmd; \
91 fi; \
92 fi; \
93 done; \
94 fi; \
95 cmd="$(INSTALL) $(LIB_INSTALL_FLAGS) $(SYMROOT)/$(*F).a $@"; \
96 echo $$cmd; eval $$cmd
97
98 do_build_install: $(INSTALL_DIR)/$(KMOD_NAME).a $(INSTALL_DIR)/$(KMODCPP_NAME).a
99
100 # include $(MakeInc_rule)
101 include $(MakeInc_dir)