2 # Kernel Module Library code makefile
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
11 include $(MakeInc_cmd)
12 include $(MakeInc_def)
14 INSTALL_DIR = $(DSTROOT)/usr/lib
16 KMODCPP_NAME = libkmodc++
17 LIB_INSTALL_FLAGS = -p -m 444
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)) \
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
29 COMPOBJROOT = $(OBJROOT)/$(KERNEL_CONFIG)_$(ARCH_CONFIG)/$(COMPONENT)/kmod
30 INSTOBJROOT = $(OBJROOT)/$(INSTALL_TYPE)_$(ARCH_CONFIG)/$(COMPONENT)/kmod
34 KMOD_CFILES = c_start.c c_stop.c
35 KMODCPP_CFILES = cplus_start.c cplus_stop.c
37 KMOD_OFILES = $(KMOD_CFILES:.c=.o)
38 KMODCPP_OFILES = $(KMODCPP_CFILES:.c=.o)
40 ALL_OFILES = $(KMOD_OFILES) $(KMODCPP_OFILES)
42 $(ALL_OFILES): %.o : %.c
44 $(_v)${LIBKMOD_CC} -c ${CFLAGS_KMOD} ${${join $@,_CFLAGS}} ${INCFLAGS} ${${join $@,_INCFLAGS}} -o $(COMPOBJROOT)/$(*F).o $<
46 $(COMPOBJROOT)/$(KMOD_NAME).a: $(KMOD_OFILES)
47 @echo LIBTOOL $(notdir $@)
48 $(_v)$(LIBTOOL) -static -o $@ $^ $(_vstdout) 2>&1
50 $(COMPOBJROOT)/$(KMODCPP_NAME).a: $(KMODCPP_OFILES)
51 @echo LIBTOOL $(notdir $@)
52 $(_v)$(LIBTOOL) -static -o $@ $^ $(_vstdout) 2>&1
54 do_build_all: $(COMPOBJROOT)/$(KMOD_NAME).a $(COMPOBJROOT)/$(KMODCPP_NAME).a
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 \
62 for onearch in $(INSTALL_ARCHS); do \
63 if [ $${onearch} = ARM ] ; then \
64 archdir=$(OBJROOT)/$(KERNEL_CONFIG)_$${onearch}_$(DEFAULT_ARM_MACHINE_CONFIG)/$(COMPONENT); \
66 archdir=$(OBJROOT)/$(KERNEL_CONFIG)_$${onearch}/$(COMPONENT); \
68 if [ -e $${archdir}/kmod/$(*F).a ]; then \
69 allarchs="$${allarchs} $${archdir}/kmod/$(*F).a"; \
72 cmd="$(LIPO) $${allarchs} -create -output $(SYMROOT)/$(*F).a"; \
73 echo $$cmd; eval $$cmd; \
77 outputfile=$(SYMROOT)/$(*F).a; \
78 for my_config in $(TARGET_CONFIGS_UC); do \
79 if [ $${my_counter} -eq 1 ]; then \
81 my_kconfig=$${my_config}; \
82 elif [ $${my_counter} -eq 2 ]; then \
84 my_aconfig=$${my_config}; \
87 if [ $${my_aconfig} = ARM ] ; then \
88 if [ $${my_config} = DEFAULT ] ; then \
89 my_config=$(DEFAULT_ARM_MACHINE_CONFIG); \
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 \
96 cmd="$(LIPO) -create $${inputfile} -o $${outputfile}"; \
98 cmd="$(LIPO) -create $${outputfile} $${inputfile} -o $${outputfile} || true"; \
100 echo $$cmd; eval $$cmd; \
105 cmd="$(INSTALL) $(LIB_INSTALL_FLAGS) $(SYMROOT)/$(*F).a $@"; \
106 echo $$cmd; eval $$cmd
108 do_build_install: $(INSTALL_DIR)/$(KMOD_NAME).a $(INSTALL_DIR)/$(KMODCPP_NAME).a
110 # include $(MakeInc_rule)
111 include $(MakeInc_dir)