# Makefile.modinc includes rules for building HAL realtime modules outside # the emc2 source tree. It has three useful targets: # # modules # Actually build the modules # # clean # Cleans up files made by 'modules' # # install # Installs the modules # An example Makefile using Makefile.modinc to build one kernel module from a # single source file would read: # # obj-m += example.o # include .../Makefile.modinc # An example Makefile using Makefile.modinc to build one kernel module from # several source files would read: # # obj-m += complex.o # complex-objs := complex1.o complex2.o complex_main.o # include .../Makefile.modinc # Currently this Makefile is only suitable for 'kbuild' and 'sim' systems, but # there is no technical reason it cannot be extended to pre-kbuild systems. # When there is a single module and it consists of a single source file, an # easier way to build modules is to invoke 'comp': # comp --compile example.c # or # comp --install example.c BUILDSYS = sim KERNELDIR := CC := gcc RTFLAGS = -DSIMULATOR RTFLAGS := -g -I. -I/pub/emc/emc2/src/include $(RTFLAGS) -DRTAPI -D_GNU_SOURCE -Drealtime -D_FORTIFY_SOURCE=0 USE_RTLIBM = EMC2_HOME=/pub/emc/emc2 RUN_IN_PLACE=yes ifeq ($(RUN_IN_PLACE),yes) EXTRA_CFLAGS := $(RTFLAGS) -D__MODULE__ -I$(EMC2_HOME)/include RTLIBDIR := /pub/emc/emc2/rtlib LIBDIR := /pub/emc/emc2/lib else prefix := /pub/emc/emc2 EXTRA_CFLAGS := $(RTFLAGS) -D__MODULE__ -I${prefix}/include/emc2 RTLIBDIR := /pub/emc/emc2/rtlib LIBDIR := ${exec_prefix}/lib endif ifeq ($(BUILDSYS),kbuild) modules: $(MAKE) -C $(KERNELDIR) SUBDIRS=`pwd` CC=$(CC) V=0 -o $(KDIR)/Module.symvers modules clean: rm *.ko *.mod.c *.o install: cp $(patsubst %.o,%.ko,$(obj-m)) $(DESTDIR)$(RTLIBDIR)/ endif ifeq ($(BUILDSYS),sim) EXTRA_CFLAGS += -DSIM -fPIC allmodules = $(patsubst %.o,%.so,$(obj-m)) modules: $(allmodules) install: cp $(allmodules) $(DESTDIR)$(RTLIBDIR)/ getobjs = $(if $(filter undefined, $(origin $(1)-objs)), $(1).o, $($(1)-objs)) getsrcs = $(patsubst %.o,%.c,$(call getobjs,$(1))) maks := $(patsubst %.o,.%.modinc,$(obj-m)) .PHONY: %.so %.so: $(CC) -shared -o $@ $(EXTRA_CFLAGS) $(call getsrcs,$*) endif ifeq ($(BUILDSYS),normal) $(error Makefile.modinc is only suitable for 'kbuild' kernels and 'sim' systems) endif