diff --git a/Makefile b/Makefile index 39aa5ba3..996e6fb1 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,12 @@ -PROGRAM:=coap-server -VERSION:=0.04 +VERSION:=0.05 -prg_sources = main.c -prg_objects:= $(patsubst %.c, %.o, $(prg_sources)) -prg_headers = SOURCES:= pdu.c net.c debug.c encode.c uri.c list.c subscribe.c str.c OBJECTS:= $(patsubst %.c, %.o, $(SOURCES)) HEADERS:=coap.h debug.h pdu.h net.h encode.h uri.h list.h mem.h subscribe.h str.h $(prg_headers) CFLAGS:=-g -Wall -ansi -pedantic DISTDIR=coap-$(VERSION) -FILES:=main.c Makefile $(SOURCES) $(HEADERS) +SUBDIRS:=examples +FILES:=Makefile $(SOURCES) $(HEADERS) LIB:=libcoap.a LDFLAGS:=-L. -l$(patsubst lib%.a,%,$(LIB)) ARFLAGS:=cru @@ -19,10 +16,14 @@ doc:=doc # add this for Solaris #LDFLAGS+=-lsocket -lnsl -.PHONY: clean distclean .gitignore doc +.PHONY: all dirs clean distclean .gitignore doc -$(PROGRAM): $(prg_objects) $(LIB) - $(CC) -o $@ $(prg_objects) $(LDFLAGS) +all: $(LIB) dirs + +dirs: $(SUBDIRS) + for dir in $^; do \ + $(MAKE) -C $$dir ; \ + done $(LIB): $(OBJECTS) $(AR) $(ARFLAGS) $@ $^ @@ -34,6 +35,9 @@ main.o: main.c clean: @rm -f $(PROGRAM) main.o $(LIB) $(OBJECTS) + for dir in $(SUBDIRS); do \ + $(MAKE) -C $$dir clean ; \ + done doc: $(MAKE) -C doc diff --git a/examples/Makefile b/examples/Makefile index eab722a9..7c5e51a4 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,5 +1,5 @@ -PROGRAMS:=tiny coap-client -SOURCES:= tiny.c client.c +PROGRAMS:=tiny coap-server coap-client +SOURCES:= tiny.c client.c server.c OBJECTS:= $(patsubst %.c, %.o, $(SOURCES)) #CFLAGS:=-g -Wall -ansi -pedantic -I.. CFLAGS:=-g -Wall -I.. @@ -20,8 +20,11 @@ tiny: tiny.o coap-client: client.o $(CC) -o $@ $< $(LDFLAGS) +coap-server: server.o + $(CC) -o $@ $< $(LDFLAGS) + clean: - @rm -f tiny $(OBJECTS) + @rm -f $(PROGRAMS) $(OBJECTS) distclean: clean @rm -rf $(DISTDIR) diff --git a/main.c b/examples/server.c similarity index 100% rename from main.c rename to examples/server.c