diff --git a/Makefile.dep b/Makefile.dep
index c1e1ba57877a206183d541cc7960c100730b06a6..3ab7ee9882d2ac64cb88dfe57a699edd66f113a1 100644
--- a/Makefile.dep
+++ b/Makefile.dep
@@ -1,3 +1,9 @@
+ifneq (,$(filter libcoap,$(USEPKG)))
+	ifeq (,$(filter pnet,$(USEMODULE)))
+		USEMODULE += pnet
+	endif
+endif
+
 ifneq (,$(filter pnet,$(USEMODULE)))
 	ifeq (,$(filter posix,$(USEMODULE)))
 		USEMODULE += posix
diff --git a/Makefile.modules b/Makefile.modules
index c7380ba3a1af55a9ab057b6e7f6444ff7c27fd99..30600b2560fbddb520f653aef87e1ff0274cfd74 100644
--- a/Makefile.modules
+++ b/Makefile.modules
@@ -4,6 +4,7 @@ UNDEF += $(BINDIR)startup.o
 USEMODULE += cpu core sys
 INCLUDES += -I$(RIOTBASE)/core/include -I$(RIOTBASE)/drivers/include -I$(RIOTBASE)/sys/include
 ED = $(USEMODULE:%=-DMODULE_%)
+ED += $(USEPKG:%=-DMODULE_%)
 EXTDEFINES = $(shell echo $(ED)|tr 'a-z' 'A-Z')
 BL=$(USEMODULE:%= $(BINDIR)%.a)
 
diff --git a/pkg/libcoap/0001-Add-RIOT-Makefile.patch b/pkg/libcoap/0001-Add-RIOT-Makefile.patch
new file mode 100644
index 0000000000000000000000000000000000000000..9481c500c58d59153c5f79db87694f14d57c062c
Binary files /dev/null and b/pkg/libcoap/0001-Add-RIOT-Makefile.patch differ
diff --git a/pkg/libcoap/0002-Add-config.h.patch b/pkg/libcoap/0002-Add-config.h.patch
new file mode 100644
index 0000000000000000000000000000000000000000..ac8c7a7604e918ab6508ec051b9fc95506070fcd
Binary files /dev/null and b/pkg/libcoap/0002-Add-config.h.patch differ
diff --git a/pkg/libcoap/patch.txt b/pkg/libcoap/0003-Remove-two-example-programs-in-root.patch
similarity index 75%
rename from pkg/libcoap/patch.txt
rename to pkg/libcoap/0003-Remove-two-example-programs-in-root.patch
index 45e6b8a0cb1ed7995d4b715f02cc5d06a82c7dbf..08b5bd9b1670a044b13ff54a38568dcef72f4a0d 100644
Binary files a/pkg/libcoap/patch.txt and b/pkg/libcoap/0003-Remove-two-example-programs-in-root.patch differ
diff --git a/pkg/libcoap/0004-Eliminate-some-compiler-warnings-and-errors.patch b/pkg/libcoap/0004-Eliminate-some-compiler-warnings-and-errors.patch
new file mode 100644
index 0000000000000000000000000000000000000000..9307d10c17d0d1f6aa454df5459a6b193493c6d2
Binary files /dev/null and b/pkg/libcoap/0004-Eliminate-some-compiler-warnings-and-errors.patch differ
diff --git a/pkg/libcoap/Makefile b/pkg/libcoap/Makefile
index 9a91f013bd99b845e416d4f4358dedc31fd387b2..1205f4f6d41f752c9ba38c5ae91736fa3f9ac5c1 100644
--- a/pkg/libcoap/Makefile
+++ b/pkg/libcoap/Makefile
@@ -1,6 +1,6 @@
 PKG_NAME=libcoap
 PKG_URL=http://git.code.sf.net/p/libcoap/code
-PKG_VERSION=89acaa6775ca3a4aedea510557e6b9c0c01fa5db
+PKG_VERSION=ef41ce5d02d64cec0751882ae8fd95f6c32bc018
 
 ifneq ($(RIOTBOARD),)
 include $(RIOTBOARD)/$(BOARD)/Makefile.include
@@ -19,7 +19,7 @@ all: patch
 patch: $(CURDIR)/$(PKG_NAME)/Makefile
 
 $(CURDIR)/$(PKG_NAME)/Makefile: $(CURDIR)/$(PKG_NAME)
-	cd $< && git apply ../patch.txt
+	cd "$<" && git am --ignore-whitespace $(CURDIR)/*.patch || true
 
 $(CURDIR)/$(PKG_NAME)/:
 	git clone $(PKG_URL) $@ && \