summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo k <mo@mokhan.ca>2012-02-18 10:05:53 -0700
committermo k <mo@mokhan.ca>2012-02-18 10:05:53 -0700
commit63b1e6e93ad99095883aa02be2350af19106e680 (patch)
tree443304709a24fe46843932bb8759cc231f6c4811
parented95723ec68282031d9335f5f3180863bc0b6ca4 (diff)
move all .c and .h files to root and clean up makefile to simplify compilation.
-rw-r--r--.gitignore2
-rw-r--r--main.c16
-rw-r--r--makefile37
-rwxr-xr-xpracticebin0 -> 8956 bytes
-rw-r--r--reverse.c (renamed from src/main.c)12
-rw-r--r--reverse.h2
6 files changed, 54 insertions, 15 deletions
diff --git a/.gitignore b/.gitignore
index f47cb20..d362c91 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
*.out
+*.o
+*.depend
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..5ac1b65
--- /dev/null
+++ b/main.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "reverse.h"
+
+int main(int argc, const char *argv[])
+{
+ char input[128];
+
+ printf("enter a string to reverse: ");
+ gets(input);
+ reverse(input);
+ printf("%s", input);
+
+ return 0;
+}
diff --git a/makefile b/makefile
index 7b9eee1..7f08710 100644
--- a/makefile
+++ b/makefile
@@ -1,4 +1,35 @@
-FILES = src/*.c
+PROGRAM = practice
+C_FILES := $(wildcard *.c)
+OBJS := $(patsubst %.c, %.o, $(C_FILES))
+CC = cc
+CFLAGS = -Wall -pedantic
+LDFLAGS =
-reverse: $(FILES)
- cc $(FILES) -o reverse.out
+all: $(PROGRAM)
+
+$(PROGRAM): .depend $(OBJS)
+ $(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(PROGRAM)
+
+depend: .depend
+
+.depend: cmd = gcc -MM -MF depend $(var); cat depend >> .depend;
+.depend:
+ @echo "Generating dependencies..."
+ @$(foreach var, $(C_FILES), $(cmd))
+ @rm -f depend
+
+-include .depend
+
+%.o: %.c
+ $(CC) $(CFLAGS) -c $< -o $@
+
+%: %.c
+ $(CC) $(CFLAGS) -o $@ $<
+
+clean:
+ rm -f *.o *.out .depend
+
+.PHONY: clean depend
+
+list:
+ @echo $(C_FILES)
diff --git a/practice b/practice
new file mode 100755
index 0000000..dd7b618
--- /dev/null
+++ b/practice
Binary files differ
diff --git a/src/main.c b/reverse.c
index 3daec0c..7882a65 100644
--- a/src/main.c
+++ b/reverse.c
@@ -16,15 +16,3 @@ void reverse(char* input){
--end;
}
}
-
-int main(int argc, const char *argv[])
-{
- char input[128];
-
- printf("enter a string to reverse: ");
- gets(input);
- reverse(input);
- printf("%s", input);
-
- return 0;
-}
diff --git a/reverse.h b/reverse.h
new file mode 100644
index 0000000..c381abf
--- /dev/null
+++ b/reverse.h
@@ -0,0 +1,2 @@
+
+void reverse(char* input);