Skip to content

Commit

Permalink
safestringlib: Use order-only dependencies to create directories
Browse files Browse the repository at this point in the history
Order-only dependencies work well for creating object
directories, so use them. Also, remove those directories
when doing a clean. Adds a missing .PHONY for the all
rule.

Signed-off-by: Mark Rustad <MRustad@gmail.com>>
  • Loading branch information
MRustad committed Dec 7, 2019
1 parent 8bf75b0 commit 30fda21
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ OTDIR=objtest
SRCDIR=safeclib
TESTDIR=unittests

all: directories libsafestring.a safestringtest
.PHONY: all
all: libsafestring.a safestringtest

_CLIB := abort_handler_s.c stpcpy_s.c strlastsame_s.c ignore_handler_s.c
_CLIB += stpncpy_s.c strljustify_s.c memcmp16_s.c strcasecmp_s.c strncat_s.c
Expand All @@ -36,7 +37,7 @@ OBJ = $(patsubst %.c,%.o,$(_TLIST))
CLIB =$(addprefix $(SRCDIR)/,$(_CLIB))


${ODIR}/%.o: ${SRCDIR}/%.c
${ODIR}/%.o: ${SRCDIR}/%.c | ${ODIR}
$(CC) $(LDFLAGS) -c -o $@ $< $(CFLAGS)

libsafestring.a: $(OBJ)
Expand Down Expand Up @@ -70,18 +71,13 @@ TOBJ = $(patsubst %.c,%.o,$(_TLIST2))
TCLIB =$(addprefix $(TESTDIR)/,$(_TESTFUNCS))


$(OTDIR)/%.o: $(TESTDIR)/%.c $(TESTDIR)/test_private.h
${OTDIR}/%.o: ${TESTDIR}/%.c ${TESTDIR}/test_private.h | ${OTDIR}
$(CC) -c -o $@ $< $(CFLAGS)


safestringtest: directories libsafestring.a $(TOBJ)
safestringtest: libsafestring.a $(TOBJ) | ${OTDIR}
$(CC) $(LDFLAGS) -o $@ $(TOBJ) libsafestring.a


.PHONY: directories

directories: ${ODIR} ${OTDIR}

${ODIR}:
${MKDIR_P} ${ODIR}

Expand All @@ -91,7 +87,8 @@ ${OTDIR}:
.PHONY: clean

clean:
rm -f ${ODIR}/* *~ core ${INCDIR}/*~ ${OTDIR}/*
rm -f *~ core ${INCDIR}/*~
rm -rf ${ODIR} ${OTDIR}
rm -f libsafestring.a
rm -f safestringtest

Expand Down

0 comments on commit 30fda21

Please sign in to comment.