# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../protothread/makefile.patch
# Copyright (C) 2009 The OpenSDE Project
#
# More information can be found in the files COPYING and README.
#
# This patch file is dual-licensed. It is available under the license the
# patched project is licensed under, as long as it is an OpenSource license
# as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
# of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# --- SDE-COPYRIGHT-NOTE-END ---

Index: protothread.h
===================================================================
--- ./protothread.h	(revision 3)
+++ ./protothread.h	(working copy)
@@ -6,7 +6,9 @@
 #ifndef PROTOTHREAD_H
 #define PROTOTHREAD_H
 
+#ifndef PT_DEBUG
 #define PT_DEBUG 1  /* enabled (else 0) */
+#endif
 #define pt_assert(condition) if (PT_DEBUG) assert(condition)
 
 /* standard definitions */
Index: Makefile
===================================================================
--- ./Makefile	(revision 3)
+++ ./Makefile	(working copy)
@@ -1,15 +1,56 @@
+CC = gcc
+LD = gcc
+AR = ar
 CFLAGS = -g -Wall
 
-OBJS = \
-       protothread_test.o \
+prefix = /usr/local
+bindir = $(prefix)/bin
+libdir = $(prefix)/lib
+includedir = $(prefix)/include
+DESTDIR =
+
+ifeq ($(DEBUG),yes)
+	CFLAGS += -DPT_DEBUG=1
+else
+ifeq ($(DEBUG),no)
+	CFLAGS += -DPT_DEBUG=0
+endif
+endif
+
+SRCDIR = .
+
+TARGETS = pttest libprotothread.a
+
+LIB_OBJS = \
        protothread_lock.o \
        protothread_sem.o \
        protothread.o \
 
-pttest:	$(OBJS) protothread.h
-	$(CC) $(CFLAGS) -o $@ $(OBJS)
+OBJS = $(LIB_OBJS) \
+       protothread_test.o
 
-$(OBJS): protothread.h
 
+.PHONY: all clean install
+
+all: $(TARGETS)
+
+define OBJ_template
+$(1).o: $(SRCDIR)/$(1).c $(wildcard $(SRCDIR)/$(1).h) $(SRCDIR)/protothread.h
+	$(CC) $(CFLAGS) -c -o $$@ -I$(SRCDIR)/ $$<
+endef
+
+$(foreach x,$(basename $(OBJS)),$(eval $(call OBJ_template,$(x))))
+
+pttest:	$(OBJS)
+	$(LD) $(LDFLAGS) -o $@ $^
+
+libprotothread.a: $(LIB_OBJS)
+	$(AR) rcs $@ $^
+
 clean:
-	rm -f *.o
+	rm -f *.o $(TARGETS)
+
+install:
+	cp -vf pttest $(DESTDIR)$(bindir)/pttest$(SUFFIX)
+	cp -vf libprotothread.a $(DESTDIR)$(libdir)/libprotothread$(SUFFIX).a
+	cp -vf $(SRCDIR)/*.h $(DESTDIR)$(includedir)/