--- ppp-2.4.5/chat/Makefile.linux
+++ ppp-2.4.5/chat/Makefile.linux
@@ -10,7 +10,6 @@
 CDEF4=	-DFNDELAY=O_NDELAY		# Old name value
 CDEFS=	$(CDEF1) $(CDEF2) $(CDEF3) $(CDEF4)
 
-COPTS=	-O2 -g -pipe
 CFLAGS=	$(COPTS) $(CDEFS)
 
 INSTALL= install
@@ -18,7 +17,7 @@
 all:	chat
 
 chat:	chat.o
-	$(CC) -o chat chat.o
+	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^
 
 chat.o:	chat.c
 	$(CC) -c $(CFLAGS) -o chat.o chat.c
--- ppp-2.4.5/pppd/Makefile.linux
+++ ppp-2.4.5/pppd/Makefile.linux
@@ -32,7 +32,7 @@
 
 # CC = gcc
 #
-COPTS = -O2 -pipe -Wall -g
+COPTS+= -Wall
 LIBS =
 
 # Uncomment the next 2 lines to include support for Microsoft's
--- ppp-2.4.5/pppd/plugins/Makefile.linux
+++ ppp-2.4.5/pppd/plugins/Makefile.linux
@@ -1,7 +1,11 @@
 #CC	= gcc
-COPTS	= -O2 -g
 CFLAGS	= $(COPTS) -I.. -I../../include -fPIC
-LDFLAGS	= -shared
+LDFLAGS_PROG := $(LDFLAGS)
+export LDFLAGS LDFLAGS_PROG
+LDFLAGS	+= -shared
+# need the following option, otherwise linking plugins might fail with undef errors (Gentoo bug 210837)
+LDFLAGS += -Wl,--allow-shlib-undefined
+LIBS = 
 INSTALL	= install
 
 DESTDIR = $(INSTROOT)@DESTDIR@
@@ -23,7 +27,7 @@
 	for d in $(SUBDIRS); do $(MAKE) $(MFLAGS) -C $$d all; done
 
 %.so: %.c
-	$(CC) -o $@ $(LDFLAGS) $(CFLAGS) $^
+	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBS)
 
 VERSION = $(shell awk -F '"' '/VERSION/ { print $$2; }' ../patchlevel.h)
 
--- ppp-2.4.5/pppd/plugins/pppoatm/Makefile.linux
+++ ppp-2.4.5/pppd/plugins/pppoatm/Makefile.linux
@@ -1,7 +1,5 @@
 #CC	= gcc
-COPTS	= -O2 -g
 CFLAGS	= $(COPTS) -I../.. -I../../../include -fPIC
-LDFLAGS	= -shared
 INSTALL	= install
 
 #***********************************************************************
@@ -33,7 +31,7 @@
 all: $(PLUGIN)
 
 $(PLUGIN): $(PLUGIN_OBJS)
-	$(CC) $(CFLAGS) -o $@ -shared $^ $(LIBS)
+	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBS)
 
 install: all
 	$(INSTALL) -d -m 755 $(LIBDIR)
--- ppp-2.4.5/pppd/plugins/pppol2tp/Makefile.linux
+++ ppp-2.4.5/pppd/plugins/pppol2tp/Makefile.linux
@@ -1,7 +1,5 @@
 #CC	= gcc
-COPTS	= -O2 -g
 CFLAGS	= $(COPTS) -I. -I../.. -I../../../include -fPIC
-LDFLAGS	= -shared
 INSTALL	= install
 
 #***********************************************************************
@@ -16,7 +14,7 @@
 all: $(PLUGINS)
 
 %.so: %.o
-	$(CC) $(CFLAGS) -o $@ -shared $^ $(LIBS)
+	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBS)
 
 install: all
 	$(INSTALL) -d -m 755 $(LIBDIR)
--- ppp-2.4.5/pppd/plugins/radius/Makefile.linux
+++ ppp-2.4.5/pppd/plugins/radius/Makefile.linux
@@ -12,7 +12,7 @@
 INSTALL	= install
 
 PLUGIN=radius.so radattr.so radrealms.so
-CFLAGS=-I. -I../.. -I../../../include -O2 -fPIC -DRC_LOG_FACILITY=LOG_DAEMON
+CFLAGS=$(COPTS) -I. -I../.. -I../../../include -fPIC -DRC_LOG_FACILITY=LOG_DAEMON
 
 # Uncomment the next line to include support for Microsoft's
 # MS-CHAP authentication protocol.
@@ -43,13 +43,13 @@
 	$(INSTALL) -c -m 444 pppd-radattr.8 $(MANDIR)
 
 radius.so: radius.o libradiusclient.a
-	$(CC) -o radius.so -shared radius.o libradiusclient.a
+	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^
 
 radattr.so: radattr.o
-	$(CC) -o radattr.so -shared radattr.o
+	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^
 
 radrealms.so: radrealms.o
-	$(CC) -o radrealms.so -shared radrealms.o
+	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^
 
 CLIENTOBJS = avpair.o buildreq.o config.o dict.o ip_util.o \
 	clientid.o sendserver.o lock.o util.o md5.o
--- ppp-2.4.5/pppd/plugins/rp-pppoe/Makefile.linux
+++ ppp-2.4.5/pppd/plugins/rp-pppoe/Makefile.linux
@@ -25,12 +25,11 @@
 # Version is set ONLY IN THE MAKEFILE!  Don't delete this!
 RP_VERSION=3.8p
 
-COPTS=-O2 -g
 CFLAGS=$(COPTS) -I../../../include '-DRP_VERSION="$(RP_VERSION)"'
 all: rp-pppoe.so pppoe-discovery
 
 pppoe-discovery: pppoe-discovery.o debug.o
-	$(CC) -o pppoe-discovery pppoe-discovery.o debug.o
+	$(CC) $(LDFLAGS_PROG) $(CFLAGS) -o pppoe-discovery pppoe-discovery.o debug.o
 
 pppoe-discovery.o: pppoe-discovery.c
 	$(CC) $(CFLAGS) -c -o pppoe-discovery.o pppoe-discovery.c
@@ -39,7 +38,7 @@
 	$(CC) $(CFLAGS) -c -o debug.o debug.c
 
 rp-pppoe.so: plugin.o discovery.o if.o common.o
-	$(CC) -o rp-pppoe.so -shared plugin.o discovery.o if.o common.o
+	$(CC) $(LDFLAGS) $(CFLAGS) -o rp-pppoe.so plugin.o discovery.o if.o common.o
 
 install: all
 	$(INSTALL) -d -m 755 $(LIBDIR)
--- ppp-2.4.5/pppdump/Makefile.linux
+++ ppp-2.4.5/pppdump/Makefile.linux
@@ -2,7 +2,7 @@
 BINDIR = $(DESTDIR)/sbin
 MANDIR = $(DESTDIR)/share/man/man8
 
-CFLAGS= -O -I../include/net
+CFLAGS=$(COPTS) -I../include/net
 OBJS = pppdump.o bsd-comp.o deflate.o zlib.o
 
 INSTALL= install
@@ -10,7 +10,7 @@
 all:	pppdump
 
 pppdump: $(OBJS)
-	$(CC) -o pppdump $(OBJS)
+	$(CC) $(LDFLAGS) -o pppdump $(OBJS)
 
 clean:
 	rm -f pppdump $(OBJS) *~
--- ppp-2.4.5/pppstats/Makefile.linux
+++ ppp-2.4.5/pppstats/Makefile.linux
@@ -10,7 +10,6 @@
 PPPSTATOBJS = pppstats.o
 
 #CC = gcc
-COPTS = -O
 COMPILE_FLAGS = -I../include
 LIBS =
 
@@ -26,7 +25,7 @@
 	$(INSTALL) -c -m 444 pppstats.8 $(MANDIR)
 
 pppstats: $(PPPSTATSRCS)
-	$(CC) $(CFLAGS) -o pppstats pppstats.c $(LIBS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o pppstats pppstats.c $(LIBS)
 
 clean:
 	rm -f pppstats *~ #* core