Introduce 'libs'

Recursively search libs/* for source and include dirs

Move mgos_barometer code to its own subdir, in preparation for release
to GitHub.
This commit is contained in:
Pim van Pelt
2018-04-22 14:04:54 +02:00
parent e30784fcad
commit 64fe69d3e3
10 changed files with 13 additions and 10 deletions

View File

@ -1,6 +1,6 @@
TARGET = mgos_i2c
CC = gcc
CFLAGS = -g -O -Wall -I include/
CFLAGS = -g -O -Wall
LINKER = gcc
LFLAGS = -O -Wall -I. -lm
@ -12,21 +12,24 @@ all: default
SRCDIR = src
INCDIR = include
OBJDIR = build
LIBDIR = libs
BINDIR = .
SOURCES := $(wildcard $(SRCDIR)/*.c)
INCLUDES := $(wildcard $(SRCDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
SRCS := $(shell find $(SRCDIR) $(LIBDIR) -type f -name '*.c')
INCS := $(shell find $(SRCDIR) $(LIBDIR) $(INCDIR) -type d -name 'include')
INCFLAGS := $(patsubst %,-I %, $(INCS))
OBJS := $(patsubst %.c, build/%.o, $(SRCS))
RM = rm -f
RMDIR = rm -r -f
$(BINDIR)/$(TARGET): $(OBJS)
$(LINKER) $(OBJS) $(LFLAGS) -o $@
$(BINDIR)/$(TARGET): $(OBJECTS)
$(LINKER) $(OBJECTS) $(LFLAGS) -o $@
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
$(OBJS): $(OBJDIR)/%.o : %.c
@mkdir -p $(shell dirname $(OBJS))
$(CC) $(CFLAGS) $(INCFLAGS) -c $< -o $@
.PHONY: clean
clean:
$(RM) $(OBJECTS)
$(RMDIR) $(OBJDIR)
$(RM) $(BINDIR)/$(TARGET)