Makefile: Add support for -

- ..'s in the source path
- USER_LISTINGS to control whether listings are generated
- dependancy directory now a MACRO
- support for Code::Blocks make targets
ugfx_release_2.6
inmarket 2014-09-26 16:27:34 +10:00
parent 10dc968427
commit 8410c8c8b5
1 changed files with 59 additions and 21 deletions

View File

@ -12,15 +12,32 @@
# To rebuild project do "make clean" and "make all". # To rebuild project do "make clean" and "make all".
# #
##############################################################################################
# Start of make control
#
# Turn ChibiOS simimulator on or off?
USE_CHIBIOS=no
# Verbose compiling?
USE_VERBOSE_COMPILE=no
# Generate listing files?
USE_LISTING=no
# Your project name and executable file name - Optional, defaults to the project directory name
#PROJECT=uGFX
#
# End of make control
##############################################################################################
############################################################################################## ##############################################################################################
# Start of default section # Start of default section
# #
CC = i686-pc-mingw32-gcc -g CC = i686-pc-mingw32-gcc -g
# Turn ChibiOS simimulator on or off - uGFX doesn't need it but you might for other purposes.
USE_CHIBIOS=no
# List all default C defines here, like -D_DEBUG=1 # List all default C defines here, like -D_DEBUG=1
DDEFS = DDEFS =
@ -34,7 +51,7 @@ DLIBDIR =
DLIBS = -lws2_32 -lgdi32 -lwinmm DLIBS = -lws2_32 -lgdi32 -lwinmm
# Make sure this empty for now # Make sure this empty for now
SRC = SRC =
# #
# End of default section # End of default section
@ -44,9 +61,6 @@ SRC =
# Start of user section # Start of user section
# #
# Define project name here
PROJECT = uGFX
# Imported source files and paths for uGFX # Imported source files and paths for uGFX
GFXLIB = ../uGFX GFXLIB = ../uGFX
include $(GFXLIB)/gfx.mk include $(GFXLIB)/gfx.mk
@ -108,51 +122,75 @@ OPT = -ggdb -O0 -fomit-frame-pointer
############################################################################################## ##############################################################################################
# Output directory and files # Default project name is the project directory name
ifeq ($(BUILDDIR),) ifeq ($(PROJECT),)
BUILDDIR = .build PROJECT := $(notdir $(patsubst %/,%,$(dir $(abspath $(firstword $(MAKEFILE_LIST))))))
endif endif
ifeq ($(BUILDDIR),.)
# Output directory and files
ifeq ($(MAKECMDGOALS),Debug)
BUILDDIR = bin/Debug
else ifeq ($(MAKECMDGOALS),Release)
BUILDDIR = bin/Release
else ifeq ($(BUILDDIR),)
BUILDDIR = .build
else ifeq ($(BUILDDIR),.)
BUILDDIR = .build BUILDDIR = .build
endif endif
OBJDIR = $(BUILDDIR)/obj OBJDIR = $(BUILDDIR)/obj
LSTDIR = $(BUILDDIR)/lst LSTDIR = $(BUILDDIR)/lst
MAPDIR = $(BUILDDIR)/map MAPDIR = $(BUILDDIR)/map
DEPDIR = .dep
INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR)) INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR)) LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
DEFS = $(DDEFS) $(UDEFS) DEFS = $(DDEFS) $(UDEFS)
ADEFS = $(DADEFS) $(UADEFS) ADEFS = $(DADEFS) $(UADEFS)
COBJ = $(addprefix $(OBJDIR)/, $(SRC:.c=.o)) COBJ = $(addprefix $(OBJDIR)/, $(subst ../,_dot_dot/,$(SRC:.c=.o)))
AOBJ = $(addprefix $(OBJDIR)/, $(ASRC:.s=.o)) AOBJ = $(addprefix $(OBJDIR)/, $(subst ../,_dot_dot/,$(ASRC:.s=.o)))
OBJS = $(AOBJ) $(COBJ) OBJS = $(AOBJ) $(COBJ)
LIBS = $(DLIBS) $(ULIBS) LIBS = $(DLIBS) $(ULIBS)
LDFLAGS = -Wl,-Map=$(MAPDIR)/$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR) LDFLAGS = -Wl,-Map=$(MAPDIR)/$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR)
CPFLAGS = $(OPT) -Wall -Wextra -Wstrict-prototypes -fverbose-asm -Wa,-alms=$(LSTDIR)/$(<:.c=.lst) $(DEFS) CPFLAGS = $(OPT) -Wall -Wextra -Wstrict-prototypes -fverbose-asm $(DEFS)
ifeq ($(USE_LISTING),yes)
CPFLAGS += -Wa,-alms=$(LSTDIR)/$(<:.c=.lst)
endif
# Generate dependency information # Generate dependency information
CPFLAGS += -MD -MP -MF .dep/$(@F).d CPFLAGS += -MD -MP -MF $(DEPDIR)/$(@F).d
# #
# makefile rules # makefile rules
# #
Debug Release: all
cleanDebug cleanRelease: clean
-rm -fR bin
all: $(BUILDDIR) $(OBJS) $(BUILDDIR)/$(PROJECT).exe MAKE_ALL_RULE_HOOK all: $(BUILDDIR) $(OBJS) $(BUILDDIR)/$(PROJECT).exe MAKE_ALL_RULE_HOOK
#all: main.cp
main.cp: $(MYCSRC)
$(CC) -c $(CPFLAGS) -E -P -I. $(INCDIR) $< -o $@
MAKE_ALL_RULE_HOOK: MAKE_ALL_RULE_HOOK:
$(BUILDDIR) $(OBJDIR) $(LSTDIR): $(BUILDDIR) $(OBJDIR) $(LSTDIR):
mkdir -p $(OBJDIR) mkdir -p $(OBJDIR)
mkdir -p $(LSTDIR)
mkdir -p $(MAPDIR) mkdir -p $(MAPDIR)
ifeq ($(USE_LISTING),yes)
mkdir -p $(LSTDIR)
endif
ifneq ($(USE_VERBOSE_COMPILE),yes) ifneq ($(USE_VERBOSE_COMPILE),yes)
@echo Compiler Options - $(CC) -c $(CPFLAGS) -I. $(INCDIR) main.c -o $(OBJDIR)/main.o @echo Compiler Options - $(CC) -c $(CPFLAGS) -I. $(INCDIR) main.c -o $(OBJDIR)/main.o
@echo @echo
endif endif
$(OBJDIR)/%.o : %.c .SECONDEXPANSION:
$(OBJDIR)/%.o : $$(subst _dot_dot/,../,%.c)
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
ifeq ($(USE_VERBOSE_COMPILE),yes) ifeq ($(USE_VERBOSE_COMPILE),yes)
@echo @echo
@ -162,7 +200,7 @@ else
@$(CC) -c $(CPFLAGS) -I. $(INCDIR) $< -o $@ @$(CC) -c $(CPFLAGS) -I. $(INCDIR) $< -o $@
endif endif
$(OBJDIR)/%.o : %.s $(OBJDIR)/%.o : $$(subst _dot_dot/,../,%.s)
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
ifeq ($(USE_VERBOSE_COMPILE),yes) ifeq ($(USE_VERBOSE_COMPILE),yes)
@echo @echo
@ -187,12 +225,12 @@ gcov:
-mv *.gcov ./gcov -mv *.gcov ./gcov
clean: clean:
-rm -fR .build -rm -fR $(BUILDDIR)
-rm -fR .dep -rm -fR $(DEPDIR)
# #
# Include the dependency files, should be the last of the makefile # Include the dependency files, should be the last of the makefile
# #
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*) -include $(shell mkdir $(DEPDIR) 2>/dev/null) $(wildcard $(DEPDIR)/*)
# *** EOF *** # *** EOF ***