Skip to content

Commit 30fda21

Browse files
committed
safestringlib: Use order-only dependencies to create directories
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 <[email protected]>>
1 parent 8bf75b0 commit 30fda21

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

makefile

+7-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ OTDIR=objtest
1111
SRCDIR=safeclib
1212
TESTDIR=unittests
1313

14-
all: directories libsafestring.a safestringtest
14+
.PHONY: all
15+
all: libsafestring.a safestringtest
1516

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

3839

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

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

7273

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

7677

77-
safestringtest: directories libsafestring.a $(TOBJ)
78+
safestringtest: libsafestring.a $(TOBJ) | ${OTDIR}
7879
$(CC) $(LDFLAGS) -o $@ $(TOBJ) libsafestring.a
7980

80-
81-
.PHONY: directories
82-
83-
directories: ${ODIR} ${OTDIR}
84-
8581
${ODIR}:
8682
${MKDIR_P} ${ODIR}
8783

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

9389
clean:
94-
rm -f ${ODIR}/* *~ core ${INCDIR}/*~ ${OTDIR}/*
90+
rm -f *~ core ${INCDIR}/*~
91+
rm -rf ${ODIR} ${OTDIR}
9592
rm -f libsafestring.a
9693
rm -f safestringtest
9794

0 commit comments

Comments
 (0)