old Makefile for building library no longer works

William Parsons gyliamos at gmail.com
Sun Oct 21 21:52:37 UTC 2018


I haven't been doing a lot of C programming lately, but recently I
revisited an old project and found the old Makefile to build a library
under FreeBSD no longer works.  (I've verified that this still worked as
of FreeBSD 9.3 and will still work if gmake is used.)  Here's a much
simplified version of the Makefile that used to work:

--8<---------------cut here---------------start------------->8---
LIBTEST	= libTest.a

.PRECIOUS: $(LIBTEST)

all: $(LIBTEST)

LIBSRC  = test.c

# Do not automatically delete library source files
.SECONDARY: $(LIBSRC)

LIBOBJ	= $(LIBSRC:%.c=%.o)

$(LIBTEST): $(LIBTEST)($(LIBOBJ))
	$(AR) $(ARFLAGS) $@ $?
	rm -f $?

clean:
	@rm -f *.o $(LIBTEST)
--8<---------------cut here---------------end--------------->8---

And here's a trivial C source file to go with it:

--8<---------------cut here---------------start------------->8---
/* test.c */
#include <stdio.h>

int
test(char const *text)
{
    printf("%s\n", text);
    return 1;
}
--8<---------------cut here---------------end--------------->8---

It looks like the Makefile directive dependency:

$(LIBTEST): $(LIBTEST)($(LIBOBJ))

no longer works and claims the target is up to date when it doesn't even
exist.

I've been perusing 'man make' without success.

One thing that puzzles me is that 'man make' says "For a more thorough
description of make and makefiles, please refer to PMake - A Tutorial."

Is this accurate?  I was under the impression that pmake was replaced by
bsdmake in recent versions of FreeBSD - is this the source of my
problems?

-- 
Will


More information about the freebsd-questions mailing list