Commit 834dd388 authored by Alejandro Mery's avatar Alejandro Mery
Browse files

lib: recursive makefiles considered harmful (tm)


Signed-off-by: default avatarAlejandro Mery <amery@geeks.cl>
parent 6edc1502
.PHONY: all libs
CC = gcc
AR = ar
srctree ?= ..
O ?= $(srctree)/out
OBJDIR := $(O)/lib
DEPS := $(OBJDIR)/deps.mk
INCLUDES = -I$(srctree)/include
CFLAGS = -O2
CFLAGS += -Wall -Wextra -std=c99 -D_POSIX_C_SOURCE=200112L
CFLAGS += $(INCLUDES)
SRCS :=
all: libs
include libfex/Makefile
# *.a
%.a:
@mkdir -vp $(@D)
$(AR) rcs $@ $^
# *.o
%.o: SRC=$(patsubst $(OBJDIR)/%.o,%.c,$@)
%.o:
@mkdir -vp $(@D)
$(CC) $(CFLAGS) -c -o $@ $(SRC)
# dependencies
$(DEPS): Makefile libfex/Makefile
mkdir -p $(@D)
for x in $(SRCS); do \
$(CC) -MM -MT $(OBJDIR)/$${x%.c}.o $$x $(INCLUDES); \
done > $@~
mv $@~ $@
include $(DEPS)
CC = gcc
AR = ar
libfex_SOURCES := $(wildcard libfex/*.c)
libfex_OBJS := $(patsubst %.c,$(OBJDIR)/%.o,$(libfex_SOURCES))
libfex_LIB := $(O)/libfex.a
srctree ?= ../..
O ?= $(srctree)/out
SRCS += $(libfex_SOURCES)
OBJS += $(libfex_OBJS)
OBJDIR := $(O)/libfex
LIBFEX := $(O)/libfex.a
libs: $(libfex_LIB)
SRCS := $(wildcard *.c)
OBJS := $(patsubst %.c,$(OBJDIR)/%.o,$(SRCS))
INCLUDES = -I$(srctree)/include
CFLAGS = -O2
CFLAGS += -Wall -Wextra -std=c99 -D_POSIX_C_SOURCE=200112L
CFLAGS += $(INCLUDES)
DEPS := $(OBJDIR)/deps.mk
# libfex.a
$(LIBFEX): $(OBJS)
@mkdir -vp $(@D)
$(AR) rcs $@ $^
# out/foo.o: foo.c
$(OBJS): SRC=$(patsubst $(OBJDIR)/%.o,%.c,$@)
$(OBJS):
@mkdir -vp $(@D)
$(CC) $(CFLAGS) -c -o $@ $(SRC)
# dependencies
$(DEPS): Makefile
mkdir -p $(@D)
for x in $(SRCS); do \
$(CC) -MM -MT $(OBJDIR)/$${x%.c}.o $$x $(INCLUDES); \
done > $@~
mv $@~ $@
include $(DEPS)
$(libfex_LIB): $(libfex_OBJS)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment