Hi paul,

If the project needs to opt in or out some source files.
With ar D, the archive can actually remove stale member object files or have new
member object files in. Though it rebuilds when source files remain unchanged.


With ar U, the archive will have stale member object files.


I am not sure if it is reasonable requirement in practice.


I am also sorry that I am using a free web mail, it is tricky for me to deal
with text format emails.


Thanks




---




# example 1. with ar D


$ pwd
/home/ljh/doc/hello_cpp2/src/main
$ ls
Makefile a.c b.c main main.d
$
$ cat Makefile
ARFLAGS = rsD # rsU, rsD
(%): % ;
%.a: ; rm -f $@; $(AR) $(ARFLAGS) $@ $^
libfoo.a: libfoo.a($(patsubst %.c,%.o,$(wildcard *.c)))
.SECONDARY: $(patsubst %.c,%.o,$(wildcard *.c))
.PHONY: clean
clean: ; rm -f *.o lib*.a
$
$ make
cc -c -o a.o a.c
cc -c -o b.o b.c
rm -f libfoo.a; ar rsD libfoo.a a.o b.o
ar: creating libfoo.a
$
$ ar -t libfoo.a
a.o
b.o
$


# OK: remove source file, member removed from archive


$ mv b.c b-c
$
$ make
rm -f libfoo.a; ar rsD libfoo.a a.o
ar: creating libfoo.a
$
$ ar -t libfoo.a
a.o
$


# OK: add new source file, archive has new member


$ mv b-c b.c
$
$ make
rm -f libfoo.a; ar rsD libfoo.a a.o b.o
ar: creating libfoo.a
$
$ ar -t libfoo.a
a.o
b.o
$




---




# example 2. with ar U


$ pwd
/home/ljh/doc/hello_cpp2/src/main
$ ls
Makefile a.c b.c main main.d
$
$ cat Makefile
ARFLAGS = rsU # rsU, rsD
(%): % ;
%.a: ; rm -f $@; $(AR) $(ARFLAGS) $@ $^
libfoo.a: libfoo.a($(patsubst %.c,%.o,$(wildcard *.c)))
.SECONDARY: $(patsubst %.c,%.o,$(wildcard *.c))
.PHONY: clean
clean: ; rm -f *.o lib*.a
$
$ make
cc -c -o a.o a.c
cc -c -o b.o b.c
rm -f libfoo.a; ar rsU libfoo.a a.o b.o
ar: creating libfoo.a
$
$ ar -t libfoo.a
a.o
b.o
$


# remove source file, archive has stale member object file


$ mv b.c b-c
$
$ make
make: 'libfoo.a' is up to date.
$
$ ar -t libfoo.a
a.o
b.o
$

Reply via email to