############################################################################# # # Makefile for building the char-driver sample module # ############################################################################# ifeq ($(DEBUG),y) CFLAGS += -O -g # -O is need to expand inlines else CFLAGS += -O2 endif TARGET = i2c-hello PWD := $(shell pwd) GUMSTIX_BUILDROOT = $(PWD)/../gumstix-buildroot ROBOSTIX = ../robostix BUILD_ARM = $(wildcard $(GUMSTIX_BUILDROOT)/build_arm*) KERNELDIR ?= $(wildcard $(BUILD_ARM)/linux-*) CROSS_COMPILE = $(patsubst %gcc, %, $(wildcard $(BUILD_ARM)/staging_dir/bin/arm-linux-uclibc*-gcc)) TARGET_ARCH=-Os -march=armv5te -mtune=xscale -Wa,-mcpu=xscale CC = $(CROSS_COMPILE)gcc ifeq ($(wildcard $(CC)),) $(error CC = $(CC) doesn't exist) endif CFLAGS += \ -Wall \ -Werror \ -Wimplicit \ -Wpointer-arith \ -Wswitch \ -Wredundant-decls \ -Wreturn-type \ -Wshadow \ -Wunused \ -Wcast-qual \ -Wnested-externs \ -Wmissing-prototypes \ -Wstrict-prototypes \ -Wmissing-declarations COMMON = $(ROBOSTIX)/gumstix/Common SHARED = $(ROBOSTIX)/Shared vpath %.c $(COMMON) $(SHARED) # # If you need additional serch paths for include files, then use the -I flag # and add them to the CPPFLAGS variable # CPPFLAGS += -I . -I $(COMMON) -I $(SHARED) # # If you need addional search paths for library files, then use the -L flag # and add them to LDFLAGS. # # LDFLAGS += -L somedir # # If you need additional libraries, then use -lxxx to search for libxxx.a # # LDLIBS += -lxxx .PHONY: all all: $(TARGET) # # You can change the $(TARGET).c if that's not your main file and you can # add additional .o files to the end of the line # OBJS = \ i2c-hello.o \ i2c-api.o \ Crc8.o \ DumpMem.o \ Log.o #-------------------------------------------------------------------------- # # Run make with v=1 or verbose=1 to get verbose output # ifeq ($(v),) export verbose = 0 else export verbose = 1 endif ifeq ($(verbose),) export verbose = 0 endif ifeq ($(verbose),0) Q = @ MAKEFLAGS += -s else Q = endif export Q DEP_FILES = $(OBJS:.o=.d) DEP_OUTPUT_OPTION = -MMD -MF $(@:.o=.d) #-------------------------------------------------------------------------- # # Remove generated files # clean: @echo "Cleaning ..." rm -rf $(OBJS) $(DEP_FILES) core $(TARGET) #-------------------------------------------------------------------------- # # Compile C source files # # COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c # # Create a rule for when the dependency exists, and one for when it doesn't # .PRECIOUS: %.o %.o : %.c %.d @echo "Compiling $< ..." $(Q)$(COMPILE.c) $(DEP_OUTPUT_OPTION) $(OUTPUT_OPTION) $< %.o : %.c @echo "Compiling $< ..." $(Q)$(COMPILE.c) $(DEP_OUTPUT_OPTION) $(OUTPUT_OPTION) $< # Making the .d's be phony and providing a dummy rule to make them, combined # with the %.o : %.c %.d causes make to work properly when the .d file is # removed, but the .o file isn't. make will now regenerate the .d by # recompiling the .o .PHONY: %.d %.d: ; #-------------------------------------------------------------------------- # # Link simple executable # $(TARGET) : $(OBJS) @echo "Linking $@ ..." $(Q)$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@ #-------------------------------------------------------------------------- # # Include dependency files # ifeq ($(strip $(filter clean% exec print-%, $(MAKECMDGOALS))),) -include $(DEP_FILES) endif