Damien George
11 years ago
9 changed files with 195 additions and 201 deletions
@ -0,0 +1,52 @@ |
|||||
|
ifneq ($(lastword a b),b) |
||||
|
$(error These Makefiles require make 3.81 or newer) |
||||
|
endif |
||||
|
|
||||
|
# Set TOP to be the path to get from the current directory (where make was
|
||||
|
# invoked) to the top of the tree. $(lastword $(MAKEFILE_LIST)) returns
|
||||
|
# the name of this makefile relative to where make was invoked.
|
||||
|
#
|
||||
|
# We assume that this file is in the py directory so we use $(dir ) twice
|
||||
|
# to get to the top of the tree.
|
||||
|
|
||||
|
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST)) |
||||
|
TOP := $(patsubst %/py/mkenv.mk,%,$(THIS_MAKEFILE)) |
||||
|
|
||||
|
# Turn on increased build verbosity by defining BUILD_VERBOSE in your main
|
||||
|
# Makefile or in your environment. You can also use V=1 on the make command
|
||||
|
# line.
|
||||
|
|
||||
|
ifeq ("$(origin V)", "command line") |
||||
|
BUILD_VERBOSE=$(V) |
||||
|
endif |
||||
|
ifndef BUILD_VERBOSE |
||||
|
BUILD_VERBOSE = 0 |
||||
|
endif |
||||
|
ifeq ($(BUILD_VERBOSE),0) |
||||
|
Q = @ |
||||
|
else |
||||
|
Q = |
||||
|
endif |
||||
|
# Since this is a new feature, advertise it
|
||||
|
ifeq ($(BUILD_VERBOSE),0) |
||||
|
$(info Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.) |
||||
|
endif |
||||
|
|
||||
|
# default settings; can be overriden in main Makefile
|
||||
|
|
||||
|
PY_SRC ?= $(TOP)/py |
||||
|
BUILD ?= build |
||||
|
|
||||
|
RM = rm |
||||
|
ECHO = @echo |
||||
|
|
||||
|
AS = $(CROSS_COMPILE)as |
||||
|
CC = $(CROSS_COMPILE)gcc |
||||
|
LD = $(CROSS_COMPILE)ld |
||||
|
OBJCOPY = $(CROSS_COMPILE)objcopy |
||||
|
SIZE = $(CROSS_COMPILE)size |
||||
|
|
||||
|
all: |
||||
|
.PHONY: all |
||||
|
|
||||
|
MKENV_INCLUDED = 1 |
@ -0,0 +1,92 @@ |
|||||
|
ifneq ($(MKENV_INCLUDED),1) |
||||
|
# We assume that mkenv is in the same directory as this file.
|
||||
|
THIS_MAKEFILE = $(lastword $(MAKEFILE_LIST)) |
||||
|
include $(dir $(THIS_MAKEFILE))mkenv.mk |
||||
|
endif |
||||
|
|
||||
|
# This file expects that OBJ contains a list of all of the object files.
|
||||
|
# The directory portion of each object file is used to locate the source
|
||||
|
# and should not contain any ..'s but rather be relative to the top of the
|
||||
|
# tree.
|
||||
|
#
|
||||
|
# So for example, py/map.c would have an object file name py/map.o
|
||||
|
# The object files will go into the build directory and mantain the same
|
||||
|
# directory structure as the source tree. So the final dependency will look
|
||||
|
# like this:
|
||||
|
#
|
||||
|
# build/py/map.o: py/map.c
|
||||
|
#
|
||||
|
# We set vpath to point to the top of the tree so that the source files
|
||||
|
# can be located. By following this scheme, it allows a single build rule
|
||||
|
# to be used to compile all .c files.
|
||||
|
|
||||
|
vpath %.S . $(TOP) |
||||
|
$(BUILD)/%.o: %.S |
||||
|
$(ECHO) "CC $<" |
||||
|
$(Q)$(CC) $(CFLAGS) -c -o $@ $< |
||||
|
|
||||
|
vpath %.s . $(TOP) |
||||
|
$(BUILD)/%.o: %.s |
||||
|
$(ECHO) "AS $<" |
||||
|
$(Q)$(AS) -o $@ $< |
||||
|
|
||||
|
define compile_c |
||||
|
$(ECHO) "CC $<" |
||||
|
$(Q)$(CC) $(CFLAGS) -c -MD -o $@ $< |
||||
|
@# The following fixes the dependency file.
|
||||
|
@# See http://make.paulandlesley.org/autodep.html for details. |
||||
|
@cp $(@:.o=.d) $(@:.o=.P); \ |
||||
|
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
||||
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.d) >> $(@:.o=.P); \
|
||||
|
rm -f $(@:.o=.d) |
||||
|
endef |
||||
|
|
||||
|
vpath %.c . $(TOP) |
||||
|
$(BUILD)/%.o: %.c |
||||
|
$(call compile_c) |
||||
|
|
||||
|
# The following rule uses | to create an order only prereuisite. Order only
|
||||
|
# prerequisites only get built if they don't exist. They don't cause timestamp
|
||||
|
# checkng to be performed.
|
||||
|
#
|
||||
|
# $(sort $(var)) removes duplicates
|
||||
|
#
|
||||
|
# The net effect of this, is it causes the objects to depend on the
|
||||
|
# object directories (but only for existance), and the object directories
|
||||
|
# will be created if they don't exist.
|
||||
|
OBJ_DIRS = $(sort $(dir $(OBJ))) |
||||
|
$(OBJ): | $(OBJ_DIRS) |
||||
|
$(OBJ_DIRS): |
||||
|
mkdir -p $@ |
||||
|
|
||||
|
ifneq ($(PROG),) |
||||
|
# Build a standalone executable (unix and unix-cpy do this)
|
||||
|
|
||||
|
all: $(PROG) |
||||
|
|
||||
|
$(PROG): $(OBJ) |
||||
|
$(ECHO) "LINK $<" |
||||
|
$(Q)$(CC) -o $@ $(OBJ) $(LIB) $(LDFLAGS) |
||||
|
ifndef DEBUG |
||||
|
$(Q)strip $(PROG) |
||||
|
endif |
||||
|
$(Q)size $(PROG) |
||||
|
|
||||
|
clean: clean-prog |
||||
|
clean-prog: |
||||
|
$(RM) -f $(PROG) |
||||
|
|
||||
|
.PHONY: clean-prog |
||||
|
endif |
||||
|
|
||||
|
clean: |
||||
|
$(RM) -rf $(BUILD) |
||||
|
.PHONY: clean |
||||
|
|
||||
|
print-cfg: |
||||
|
$(ECHO) "PY_SRC = $(PY_SRC)" |
||||
|
$(ECHO) "BUILD = $(BUILD)" |
||||
|
$(ECHO) "OBJ = $(OBJ)" |
||||
|
.PHONY: print-cfg |
||||
|
|
||||
|
-include $(OBJ:.o=.P) |
Loading…
Reference in new issue