From 5ecc6d64b4e81bb05e8601a63d212e116465acf1 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sun, 15 Feb 2015 15:47:36 +0100 Subject: [PATCH] Move test.c and joystick.c to examples/ Signed-off-by: Joachim Nilsson --- Makefile | 30 +++++++++--------- README.md | 14 +++++---- examples/Makefile | 52 +++++++++++++++++++++++++++++++ joystick.c => examples/joystick.c | 0 test.c => examples/test.c | 4 +-- rules.mk | 9 ++++++ 6 files changed, 87 insertions(+), 22 deletions(-) create mode 100644 examples/Makefile rename joystick.c => examples/joystick.c (100%) rename test.c => examples/test.c (99%) create mode 100644 rules.mk diff --git a/Makefile b/Makefile index 2ff0a56..4e75ae8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# -*-Makefile-*- for libuEv +# libuEv main build file # # Copyright (c) 2012 Flemming Madsen # Copyright (c) 2013-2015 Joachim Nilsson @@ -22,7 +22,7 @@ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # -.PHONY: all test clean +.PHONY: all test clean joystick test examples #VERSION = $(shell git tag -l | tail -1) VERSION ?= 1.0.5-dev @@ -36,7 +36,9 @@ STRIP ?= $(CROSS)strip CFLAGS += -fPIC -Os CPPFLAGS += -W -Wall -Werror ARFLAGS = crus -JUNK = *~ *.bak *.map .*.d DEADJOE *.gdb *.elf core core.* +JUNK = *~ *.bak *.map .*.d DEADJOE *.gdb *.elf core core.* *.html + +MAKEFLAGS = --no-print-directory ROOTDIR ?= $(shell pwd) LIBNAME = $(NAME) @@ -56,11 +58,11 @@ SYMLIB = $(LIBNAME).so STATICLIB = $(LIBNAME).a TARGET = $(STATICLIB) $(SOLIB) -# Pretty printing and GCC -M for auto dep files -%.o: %.c - @printf " CC $(subst $(ROOTDIR)/,,$(shell pwd)/)$@\n" - @$(CC) $(CFLAGS) $(CPPFLAGS) -c -MMD -MP -o $@ $< +export STATICLIB JUNK ROOTDIR CFLAGS CPPFLAGS +# This magic trick looks like a comment, but works on BSD PMake +#include +include rules.mk # Build rules all: $(TARGET) @@ -95,26 +97,26 @@ strip: $(TARGET) @$(STRIP) --strip-unneeded $(TARGET) @size $(TARGET) -test: Makefile test.o $(STATICLIB) - @printf " TEST %s\n" $(STATICLIB) - @$(CC) $(CPPFLAGS) -g -o test test.c $(STATICLIB) && ./test - bench: Makefile bench.o $(STATICLIB) @printf " BENCH %s\n" $(STATICLIB) @$(CC) $(CPPFLAGS) -g -o bench bench.c $(STATICLIB) && ./bench -joystick: Makefile joystick.o $(STATICLIB) - @printf " JOTST %s\n" $(STATICLIB) - @$(CC) $(CPPFLAGS) -g -o joystick joystick.c $(STATICLIB) && ./joystick +examples: + @$(MAKE) -C examples + +test joystick: + @$(MAKE) -C examples $@ # Runs Clang scan-build on the whole tree check: clean @scan-build $(MAKE) all clean: + -@$(MAKE) -C examples $@ -@$(RM) $(TARGET) *.o test joystick bench distclean: clean + -@$(MAKE) -C examples $@ -@$(RM) $(DEPS) $(JUNK) dist: diff --git a/README.md b/README.md index 30f8f25..b612bde 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ libuEv | Simple event loop for Linux ==================================== -[![Build Status](https://travis-ci.org/troglobit/libuev.png?branch=master)](https://travis-ci.org/troglobit/libuev) -[![Coverity Scan Status](https://scan.coverity.com/projects/3846/badge.svg)](https://scan.coverity.com/projects/3846) +[![Travis Status]][Travis] [![Coverity Status]][Coverity Scan] Table of Contents @@ -249,12 +248,15 @@ used for inspiration is the very small [Picoev][9] by [Oku Kazuho]. [7]: http://libev.schmorp.de/bench.html [8]: http://code.google.com/p/libuevent/ [9]: https://github.com/kazuho/picoev -[LibuEV]: https://github.com/troglobit/libuev -[Oku Kazuho]: https://github.com/kazuho -[Mark Lehmann]: http://software.schmorp.de +[Travis]: https://travis-ci.org/troglobit/libuev +[Travis Status]: https://travis-ci.org/troglobit/libuev.png?branch=master +[Coverity Scan]: https://scan.coverity.com/projects/3846 +[Coverity Status]: https://scan.coverity.com/projects/3846/badge.svg +[LibuEV]: https://github.com/troglobit/libuev +[Oku Kazuho]: https://github.com/kazuho +[Mark Lehmann]: http://software.schmorp.de [Joachim Nilsson]: http://troglobit.com [Flemming Madsen]: http://www.madsensoft.dk [Dave Zarzycki, Apple]: http://www.youtube.com/watch?v=cD_s6Fjdri8 [libuEv] is developed and maintained by [Joachim Nilsson] - diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..93c26c3 --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,52 @@ +# libuEv examples +# +# Copyright (c) 2012 Flemming Madsen +# Copyright (c) 2013-2015 Joachim Nilsson +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +.PHONY: all clean + +TARGET = joystick test +OBJS := $(addsuffix .o, $(TARGET)) +SRCS := $(OBJS:.o=.c) +DEPS := $(SRCS:.c=.d) +CPPFLAGS += -I../ +LDFLAGS := -L../ +LDLIBS := ../$(STATICLIB) + +# This magic trick looks like a comment, but works on BSD PMake +#include <../rules.mk> +include ../rules.mk + +all: $(TARGET) + +test: test.o + +joystick: joystick.o + +clean: + -@$(RM) $(TARGET) *.o + +distclean: clean + -@$(RM) $(DEPS) $(JUNK) + +# Include automatically generated rules +-include $(DEPS) diff --git a/joystick.c b/examples/joystick.c similarity index 100% rename from joystick.c rename to examples/joystick.c diff --git a/test.c b/examples/test.c similarity index 99% rename from test.c rename to examples/test.c index 216ca9e..22c7c42 100644 --- a/test.c +++ b/examples/test.c @@ -111,7 +111,7 @@ int main(void) if (pipe(fd) < 0) return 1; - /* */ + /* Initialize libuEv */ uev_init(&ctx); /* Signal watchers, Ctrl-C => SIGINT, Ctrl-\ => SIGQUIT */ @@ -141,7 +141,7 @@ int main(void) fprintf(stderr, "Period is %d must be 10: %s\n", period, 10 == period ? "OK" : "ERROR!"); if (10 != period) return 1; - + return 0; } diff --git a/rules.mk b/rules.mk new file mode 100644 index 0000000..b8ef61b --- /dev/null +++ b/rules.mk @@ -0,0 +1,9 @@ +# Pretty printing and GCC -M for auto dep files +%.o: %.c + @printf " CC $(subst $(ROOTDIR)/,,$(shell pwd)/)$@\n" + @$(CC) $(CFLAGS) $(CPPFLAGS) -c -MMD -MP -o $@ $< + +%: %.o + @printf " LINK $(subst $(ROOTDIR)/,,$(shell pwd)/)$@\n" + @$(CC) $(CFLAGS) $(LDFLAGS) -Wl,-Map,$@.map -o $@ $^ $(LDLIBS$(LDLIBS-$(@))) +