diff options
| author | mo k <mo@mokhan.ca> | 2012-02-18 10:05:53 -0700 |
|---|---|---|
| committer | mo k <mo@mokhan.ca> | 2012-02-18 10:05:53 -0700 |
| commit | 63b1e6e93ad99095883aa02be2350af19106e680 (patch) | |
| tree | 443304709a24fe46843932bb8759cc231f6c4811 | |
| parent | ed95723ec68282031d9335f5f3180863bc0b6ca4 (diff) | |
move all .c and .h files to root and clean up makefile to simplify compilation.
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | main.c | 16 | ||||
| -rw-r--r-- | makefile | 37 | ||||
| -rwxr-xr-x | practice | bin | 0 -> 8956 bytes | |||
| -rw-r--r-- | reverse.c (renamed from src/main.c) | 12 | ||||
| -rw-r--r-- | reverse.h | 2 |
6 files changed, 54 insertions, 15 deletions
@@ -1 +1,3 @@ *.out +*.o +*.depend @@ -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; +} @@ -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 Binary files differnew file mode 100755 index 0000000..dd7b618 --- /dev/null +++ b/practice @@ -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); |
