From 2aeb03374f232d7e9ac833327c55492851073927 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Wed, 2 Jul 2014 09:50:12 +0200 Subject: [PATCH] Much better makefile (from my point of view at least) --- Makefile | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index aca23e0..c1a0004 100644 --- a/Makefile +++ b/Makefile @@ -6,30 +6,40 @@ CFLAGS += -Wall -Wextra -O2 all: lpcisp lpcprog -lpcisp: lpcisp.o isp_utils.o isp_commands.o isp_wrapper.o - -lpcprog: lpcprog.o isp_utils.o isp_commands.o prog_commands.o parts.o - - - -lpcisp.o: isp_utils.h isp_commands.h - -isp_utils.o: - -isp_commands.o: isp_utils.h - -isp_wrapper.o: isp_utils.h isp_commands.h - -lpcprog.o: isp_utils.h isp_commands.h prog_commands.h parts.h - -prog_commands.o: isp_utils.h isp_commands.h parts.h - -parts.o: parts.h +OBJDIR = objs +SRC = $(shell find . -name \*.c) +OBJS = ${SRC:%.c=${OBJDIR}/%.o} + +LPCISP_OBJS = ${OBJDIR}/lpcisp.o \ + ${OBJDIR}/isp_utils.o \ + ${OBJDIR}/isp_commands.o \ + ${OBJDIR}/isp_wrapper.o + +LPCPROG_OBJS = ${OBJDIR}/lpcprog.o \ + ${OBJDIR}/isp_utils.o \ + ${OBJDIR}/isp_commands.o \ + ${OBJDIR}/prog_commands.o \ + ${OBJDIR}/parts.o + +lpcisp: $(LPCISP_OBJS) + @echo "Linking $@ ..." + @$(CC) $(CFLAGS) $(LPCISP_OBJS) -o $@ + @echo Done. + +lpcprog: $(LPCPROG_OBJS) + @echo "Linking $@ ..." + @$(CC) $(CFLAGS) $(LPCPROG_OBJS) -o $@ + @echo Done. + +${OBJDIR}/%.o: %.c + @mkdir -p $(dir $@) + @echo "-- compiling" $< + @$(CC) -MMD -MP -MF ${OBJDIR}/$*.d $(CFLAGS) $< -c -o $@ clean: - rm -f *.o + rm -f ${OBJDIR}/* mrproper: clean rm -f lpcisp rm -f lpcprog -- 2.43.0