1 # Makefile for GPIO Demo Module
3 TARGET_DIR = apps/$(MODULE)/$(NAME)
9 CROSS_COMPILE ?= arm-none-eabi-
10 CC = $(CROSS_COMPILE)gcc
11 FOPTS = -fno-builtin -ffunction-sections -fdata-sections -ffreestanding
12 CFLAGS = -Wall -O2 -mthumb -mcpu=$(CPU) $(FOPTS)
13 LINKOPTS = -static -nostartfiles -nostdlib \
14 -Wl,--gc-sections -Wl,--build-id=none \
15 -Wl,-Map=$(TARGET_DIR)/lpc_map_$(LPC).map -Tlpc_link_$(LPC).ld
18 APPS = $(subst apps/,,$(wildcard apps/*/*))
24 TARGET_INCLUDES = $(TARGET_DIR)/
27 SRC = $(wildcard */*.c)
28 OBJS = ${SRC:%.c=${OBJDIR}/%.o}
29 DEPS = ${OBJS:%.o=$(OBJDIR)/%.d}
31 NAME_SRC = $(wildcard $(TARGET_DIR)/*.c)
32 NAME_OBJS = ${NAME_SRC:%.c=${OBJDIR}/%.o}
33 NAME_DEPS = ${NAME_OBJS:%.o=$(OBJDIR)/%.d}
35 -include $(DEPS) $(NAME_DEPS)
37 .SECONDARY: $(OBJS) $(NAME_OBJS)
39 %.elf: $(OBJS) $(NAME_OBJS)
40 @echo "Linking $(MODULE)/$(NAME) ..."
41 @$(CC) $(LINKOPTS) $(OBJS) $(NAME_OBJS) -o $@
44 @echo "Creating image :
\e[32m$@
\e[39m"
45 @$(CROSS_COMPILE)objcopy -R .stack -R .bss -O binary $^ $@
47 @$(CROSS_COMPILE)size $^
52 @echo "-- compiling" $<
53 @$(CC) -MMD -MP -MF ${OBJDIR}/$*.d $(CFLAGS) $< -c -o $@ -I$(INCLUDES) -I$(TARGET_INCLUDES)
57 @make --no-print-directory MODULE=$(shell dirname $@) NAME=$(shell basename $@) apps/$(shell dirname $@)/$(shell basename $@)/$(shell basename $@).bin
65 rm -f apps/*/*/*.bin apps/*/*/*.elf apps/*/*/*.map
69 # The command "make -f /path/to/here/Makefile module/app_name" does not work, as well
70 # as the command "make -f /path/to/here/apps/module/app_name/Makefile".
71 # This could be solved in the app Makefiles by replacing
72 # "NAME = $(shell basename $(CURDIR))"
74 # "NAME = $(shell basename $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))"
75 # and possibly some similar trick for the base Makefile but this is just
76 # unreadable and moslty unusefull, so it won't be supported.
77 # Use "make -C /path/to/here/ module/app_name" or "make -C /path/to/here/apps/module/app_name"