Merge pull request #21 from ungureanuvladvictor/generic_folder_structure
authorMichael Göhler <somebody.here@gmx.de>
Sat, 20 Sep 2014 15:22:38 +0000 (17:22 +0200)
committerMichael Göhler <somebody.here@gmx.de>
Mon, 22 Sep 2014 10:23:24 +0000 (12:23 +0200)
Moved all *.c files into src folder and created separate Makefile
Updated base Makefile to support src folder
closes #21

Makefile
include/main.h [moved from include/mdp.h with 92% similarity]
src/Makefile [new file with mode: 0644]
src/cstack.c [moved from cstack.c with 98% similarity]
src/cstring.c [moved from cstring.c with 98% similarity]
src/main.c [moved from mdp.c with 99% similarity]
src/markdown.c [moved from markdown.c with 98% similarity]
src/parser.c [moved from parser.c with 99% similarity]
src/viewer.c [moved from viewer.c with 99% similarity]

index 46ed432..f922b7e 100644 (file)
--- a/Makefile
+++ b/Makefile
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
 
-CFLAGS   = -O3 -Wall
-
-ifeq ($(DEBUG),1)
-CFLAGS  := -O0 -Wall -g
-LDFLAGS :=
-endif
-
 OSTYPE  := $(shell uname -o)
 CURSES   = ncursesw
 ifeq (Windows_NT, $(OS))
 ifneq (Cygwin, $(OSTYPE))
 CURSES  := pdcurses
-CFLAGS  += -DWIN32=1
 endif
 endif
 
 LDFLAGS  = -s
 LDLIBS   = -l$(CURSES)
-OBJECTS  = cstring.o cstack.o markdown.o parser.o viewer.o mdp.o
+SOURCES  = $(wildcard src/*.c)
+OBJECTS  = $(SOURCES:.c=.o)
+TARGET   = mdp
 DESTDIR  = /usr/bin
 
-all: mdp
+ifeq ($(DEBUG),1)
+LDFLAGS :=
+endif
+
+all: $(TARGET)
+
+$(TARGET): src
+       $(CC) $(OBJECTS) $(LDLIBS) $(LDFLAGS) -o $(TARGET)
 
-mdp: $(OBJECTS)
+src:
+       $(MAKE) $(MFLAGS) -C src
 
 clean:
-       $(RM) $(OBJECTS) mdp
+       $(MAKE) -C src clean
+       $(RM) $(TARGET)
 
-install: mdp
+install:
        install -d $(PREFIX)$(DESTDIR)
-       install -m 755 mdp $(PREFIX)$(DESTDIR)/mdp
+       install -m 755 mdp $(PREFIX)$(DESTDIR)/$(TARGET)
 
 uninstall:
-       $(RM) $(PREFIX)$(DESTDIR)/mdp
+       $(RM) $(PREFIX)$(DESTDIR)/$(TARGET)
 
-.PHONY: all clean install uninstall
+.PHONY: all clean install src uninstall
 
similarity index 92%
rename from include/mdp.h
rename to include/main.h
index 8713623..05d05f4 100644 (file)
@@ -1,5 +1,5 @@
-#if !defined( MDP_H )
-#define MDP_H
+#if !defined( MAIN_H )
+#define MAIN_H
 
 /*
  * mdp -- A command-line based markdown presentation tool.
@@ -27,4 +27,4 @@
 #define MDP_VER_MINOR 91
 #define MDP_VER_REVISION 1
 
-#endif // !defined( MDP_H )
+#endif // !defined( MAIN_H )
diff --git a/src/Makefile b/src/Makefile
new file mode 100644 (file)
index 0000000..f0783e9
--- /dev/null
@@ -0,0 +1,40 @@
+#                                                                                                                           
+#                                                                                                                             1 # Makefile
+# Copyright (C) 2014 Michael Goehler
+#
+# This file is part of mdp.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+SOURCES = $(wildcard *.c)
+OBJECTS = $(SOURCES:.c=.o)
+
+CFLAGS   = -O3 -Wall -I../include
+ifeq ($(DEBUG),1)
+CFLAGS  := -O0 -Wall -g -I../include
+endif
+
+OSTYPE  := $(shell uname -o)
+ifeq (Windows_NT, $(OS))
+ifneq (Cygwin, $(OSTYPE))
+CFLAGS  += -DWIN32=1
+endif
+endif
+
+all: $(OBJECTS)
+
+clean:
+       $(RM) $(OBJECTS)
+
similarity index 98%
rename from cstack.c
rename to src/cstack.c
index f56ee2c..aafb95f 100644 (file)
--- a/cstack.c
@@ -21,7 +21,7 @@
 
 #include <stdlib.h> // malloc, realloc
 
-#include "include/cstack.h"
+#include "cstack.h"
 
 cstack_t *cstack_init() {
     cstack_t *stack = malloc(sizeof(cstack_t));
similarity index 98%
rename from cstring.c
rename to src/cstring.c
index 958062b..1939572 100644 (file)
--- a/cstring.c
@@ -22,7 +22,7 @@
 #include <string.h> // strlen
 #include <stdlib.h> // malloc, realloc
 
-#include "include/cstring.h"
+#include "cstring.h"
 
 cstring_t *cstring_init() {
     cstring_t *x = malloc(sizeof(cstring_t));
similarity index 99%
rename from mdp.c
rename to src/main.c
index 4fe4a63..c94330a 100644 (file)
--- a/mdp.c
@@ -23,7 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "include/mdp.h"
+#include "main.h"
 
 void usage() {
     fprintf(stderr, "%s", "Usage: mdp [OPTION]... [FILE]\n");
similarity index 98%
rename from markdown.c
rename to src/markdown.c
index 45c4940..6e7d15f 100644 (file)
@@ -22,7 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "include/markdown.h"
+#include "markdown.h"
 
 line_t *new_line() {
     line_t *x = malloc(sizeof(line_t));
similarity index 99%
rename from parser.c
rename to src/parser.c
index 1ff125c..0852e80 100644 (file)
--- a/parser.c
@@ -25,7 +25,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include "include/parser.h"
+#include "parser.h"
 
 deck_t *markdown_load(FILE *input) {
 
similarity index 99%
rename from viewer.c
rename to src/viewer.c
index c1a0188..76dc18c 100644 (file)
--- a/viewer.c
@@ -26,7 +26,7 @@
 #include <string.h> // strchr
 #include <unistd.h>
 
-#include "include/viewer.h"
+#include "viewer.h"
 
 // color ramp for fading from black to color
 static short white_ramp[24] = { 16, 232, 233, 234, 235, 236,