rm static libraries before rebuilding

Started by Noah Mischalmost 11 years ago3 messages
#1Noah Misch
noah@leadboat.com
1 attachment(s)

We build static libraries with "ar crs" or "ar cr". If the static library
already exists in the build directory, those commands will add new members and
replace existing members. They will not remove members present in the
existing library but not named on the "ar" command line. This matters when,
for example, you rerun ./configure in a way that removes a file from
$(LIBOBJS). libpgport carries the obsolete member until "make clean". Let's
fix that by issuing "rm -f" before running $(AR). I would back-patch this.

Attachments:

staticlib-rm-v1.patchtext/plain; charset=us-asciiDownload
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 739033f..f96c709 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -296,6 +296,7 @@ all-shared-lib: $(shlib)
 
 ifndef haslibarule
 $(stlib): $(OBJS) | $(SHLIB_PREREQS)
+	rm -f $@
 	$(LINK.static) $@ $^
 	$(RANLIB) $@
 endif #haslibarule
@@ -337,6 +338,7 @@ else # PORTNAME == aix
 
 # AIX case
 $(shlib) $(stlib): $(OBJS) | $(SHLIB_PREREQS)
+	rm -f $(stlib)
 	$(LINK.static) $(stlib) $^
 	$(RANLIB) $(stlib)
 	$(MKLDEXPORT) $(stlib) >$(exports_file)
@@ -356,6 +358,7 @@ $(shlib): $(OBJS) | $(SHLIB_PREREQS)
 	$(CC) $(CFLAGS)  -shared -o $@  $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) $(LDAP_LIBS_BE)
 
 $(stlib): $(OBJS) | $(SHLIB_PREREQS)
+	rm -f $@
 	$(LINK.static) $@ $^
 	$(RANLIB) $@
 
diff --git a/src/common/Makefile b/src/common/Makefile
index 372a21b..c71415e 100644
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -43,6 +43,7 @@ uninstall:
 	rm -f '$(DESTDIR)$(libdir)/libpgcommon.a'
 
 libpgcommon.a: $(OBJS_FRONTEND)
+	rm -f $@
 	$(AR) $(AROPT) $@ $^
 
 #
@@ -50,6 +51,7 @@ libpgcommon.a: $(OBJS_FRONTEND)
 #
 
 libpgcommon_srv.a: $(OBJS_SRV)
+	rm -f $@
 	$(AR) $(AROPT) $@ $^
 
 # Because this uses its own compilation rule, it doesn't use the
diff --git a/src/port/Makefile b/src/port/Makefile
index a0908bf..a862d51 100644
--- a/src/port/Makefile
+++ b/src/port/Makefile
@@ -51,6 +51,7 @@ uninstall:
 	rm -f '$(DESTDIR)$(libdir)/libpgport.a'
 
 libpgport.a: $(OBJS)
+	rm -f $@
 	$(AR) $(AROPT) $@ $^
 
 # thread.o needs PTHREAD_CFLAGS (but thread_srv.o does not)
@@ -61,6 +62,7 @@ thread.o: CFLAGS+=$(PTHREAD_CFLAGS)
 #
 
 libpgport_srv.a: $(OBJS_SRV)
+	rm -f $@
 	$(AR) $(AROPT) $@ $^
 
 # Because this uses its own compilation rule, it doesn't use the
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Noah Misch (#1)
Re: rm static libraries before rebuilding

Noah Misch <noah@leadboat.com> writes:

We build static libraries with "ar crs" or "ar cr". If the static library
already exists in the build directory, those commands will add new members and
replace existing members. They will not remove members present in the
existing library but not named on the "ar" command line. This matters when,
for example, you rerun ./configure in a way that removes a file from
$(LIBOBJS). libpgport carries the obsolete member until "make clean". Let's
fix that by issuing "rm -f" before running $(AR). I would back-patch this.

+1 ... I doubt anybody's thought about this.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Noah Misch (#1)
Re: rm static libraries before rebuilding

Noah Misch wrote:

We build static libraries with "ar crs" or "ar cr". If the static library
already exists in the build directory, those commands will add new members and
replace existing members. They will not remove members present in the
existing library but not named on the "ar" command line. This matters when,
for example, you rerun ./configure in a way that removes a file from
$(LIBOBJS). libpgport carries the obsolete member until "make clean". Let's
fix that by issuing "rm -f" before running $(AR). I would back-patch this.

+1 -- I was (as I expect many were) bitten by this recently.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers