From f7e7ee0a1a4982810f35f2c46143f7694cc513ae Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Fri, 26 Dec 2014 11:48:18 +0100 Subject: [PATCH] use build directory --- .gitignore | 4 ++-- Makefile | 35 ++++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 3e26448..a909853 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -*.o -*.d +build twiboot +mpmboot diff --git a/Makefile b/Makefile index 718f5fa..53e85b1 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,37 @@ -TARGET = twiboot -TARGET2 = mpmboot +TARGETS=twiboot mpmboot +TARGET_DIR=~/bin +BUILD_DIR = build -CFLAGS = -Wall -Wno-unused-result -O2 -MMD -MP -MF $(*F).d +CFLAGS= -pipe -O2 -Wall -Wno-unused-result +CFLAGS+= -MMD -MP -MF $(BUILD_DIR)/$(*D)/$(*F).d +LDFLAGS= # ------ -SRC := $(wildcard *.c) +SRC:= $(wildcard *.c) -all: $(TARGET) +all: $(TARGETS) -$(TARGET): $(SRC:.c=.o) +$(TARGETS): $(patsubst %,$(BUILD_DIR)/%, $(SRC:.c=.o)) @echo " Linking file: $@" @$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) > /dev/null - @ln -sf $@ $(TARGET2) -%.o: %.c +$(BUILD_DIR)/%.o: %.c $(MAKEFILE_LIST) @echo " Building file: $<" - @$(CC) -c $(CFLAGS) $< -o $@ + @$(shell test -d $(BUILD_DIR)/$(*D) || mkdir -p $(BUILD_DIR)/$(*D)) + @$(CC) $(CFLAGS) -o $@ -c $< clean: - rm -rf $(TARGET) $(TARGET2) *.o *.d + rm -rf $(BUILD_DIR) $(TARGETS) --include $(shell find . -name \*.d 2> /dev/null) +install: $(TARGETS) + @mkdir -p $(TARGET_DIR) + rm -f $(patsubst %,$(TARGET_DIR)/%, $(TARGETS)) + cp -a $^ $(TARGET_DIR) + +install_links: $(TARGETS) + @mkdir -p $(TARGET_DIR) + rm -f $(patsubst %,$(TARGET_DIR)/%, $(TARGETS)) + ln -s -t $(TARGET_DIR) $(patsubst %,$(PWD)/%, $(TARGETS)) + +-include $(shell find $(BUILD_DIR) -name \*.d 2> /dev/null)