From 85e981f29c099be2b20ab5a186420254244e1684 Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Sat, 13 Nov 2021 17:37:31 +0000 Subject: [PATCH] Minimize makefile to only output object files --- Makefile | 63 +++++------------------------------- config.mk | 18 +++++++++++ sources.mk | 2 -- dynarray.c => src/dynarray.c | 0 dynarray.h => src/dynarray.h | 0 5 files changed, 26 insertions(+), 57 deletions(-) delete mode 100644 sources.mk rename dynarray.c => src/dynarray.c (100%) rename dynarray.h => src/dynarray.h (100%) diff --git a/Makefile b/Makefile index dc76c4e..42fdd28 100644 --- a/Makefile +++ b/Makefile @@ -1,65 +1,18 @@ include config.mk -include sources.mk - -ifeq (${CC},clang) - -CFLAGS =\ - -std=c99\ - -Weverything\ - -Wno-padded\ - -Wno-disabled-macro-expansion\ - -pedantic - -ifeq (${DEBUG},1) -CFLAGS += -g -else -CFLAGS += -O2 -Werror -endif - -else ifeq (${CC},gcc) - -CFLAGS =\ - -std=c99\ - -Wall\ - -Wextra\ - -Wformat-overflow=2\ - -Wformat-security\ - -Winit-self\ - -Wstrict-overflow=2\ - -Wstringop-overflow=2\ - -Walloc-zero\ - -Wduplicated-branches\ - -Wduplicated-cond\ - -Wtrampolines\ - -Wfloat-equal\ - -Wshadow\ - -Wunsafe-loop-optimizations\ - -Wparentheses\ - -pedantic - -ifeq (${DEBUG},1) -CFLAGS += -g -else -CFLAGS += -O2 -Werror -endif - -endif -CFLAGS += ${EXTRA_CFLAGS} OBJ = ${SRC:.c=.o} -all: ${OBJ} +all: ${OBJ} ${BIN} %.o: %.c - ${CC} -c ${CFLAGS} -o $@ $< + ${CC} -o $@ -c ${CFLAGS} $< clean: - rm -f ${OBJ} + rm -f ${OBJ} ${BIN} -install: all - mkdir -p "${DESTDIR}${PREFIX}/lib/corelibs" - cp -f ${OBJ} "${DESTDIR}${PREFIX}/lib/corelibs" - mkdir -p "${DESTDIR}${PREFIX}/include/corelibs" - cp -f ${HDR} "${DESTDIR}${PREFIX}/include/corelibs" +ifneq (${BIN},) +${BIN}: ${OBJ} + ${CC} -o "$@" ${LDFLAGS} $? +endif -.PHONY: all clean install +.PHONY: all clean diff --git a/config.mk b/config.mk index 83cf38d..7e872cd 100644 --- a/config.mk +++ b/config.mk @@ -1,3 +1,21 @@ +SRC = src/dynarray.c +BIN = + PREFIX = /usr/local CC = clang DEBUG = 1 + +LDFLAGS =\ + -static + +CFLAGS =\ + -std=c99\ + -Weverything\ + -Wno-padded\ + -Wno-disabled-macro-expansion\ + -pedantic +ifeq (${DEBUG},1) +CFLAGS += -g +else +CFLAGS += -O2 -Werror +endif diff --git a/sources.mk b/sources.mk deleted file mode 100644 index 00466ec..0000000 --- a/sources.mk +++ /dev/null @@ -1,2 +0,0 @@ -SRC = dynarray.c -HDR = dynarray.h diff --git a/dynarray.c b/src/dynarray.c similarity index 100% rename from dynarray.c rename to src/dynarray.c diff --git a/dynarray.h b/src/dynarray.h similarity index 100% rename from dynarray.h rename to src/dynarray.h