summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile78
1 files changed, 45 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index 82a9cc2..5e8b052 100644
--- a/Makefile
+++ b/Makefile
@@ -1,40 +1,25 @@
PROJECT=agni
CC=gcc
CFLAGS=
+SOURCES=$(wildcard *.c)
+OBJECTS=$(SOURCES:.c=.o)
+LDFLAGS=-lrt -lm
+INCLUDE=-I./extlibs/ -I./
-make: version
- $(CC) $(CFLAGS) buf.c -c
- $(CC) $(CFLAGS) mmm.c -c
- $(CC) $(CFLAGS) darray.c -c
- $(CC) $(CFLAGS) mq_cmd.c -c
- $(CC) $(CFLAGS) mq_ntf.c -c
- $(CC) $(CFLAGS) tbl_qcmd.c -c
- $(CC) $(CFLAGS) util.c -c
- $(CC) $(CFLAGS) sock_conn.c -c
- $(CC) $(CFLAGS) irc_parse.c -c
- $(CC) $(CFLAGS) mmm.c -c
- $(CC) $(CFLAGS) cmd_date.c -c
- $(CC) $(CFLAGS) cmd_uptime.c -c
- $(CC) $(CFLAGS) cmd_version.c -c
- $(CC) $(CFLAGS) cmd_ping.c -c
- $(CC) $(CFLAGS) cmd_loadavg.c -c
- $(CC) $(CFLAGS) cmd_rusage.c -c
- $(CC) $(CFLAGS) cmd_cmd.c -c
- $(CC) $(CFLAGS) sha1.c -c
- $(CC) $(CFLAGS) cmd_sha1.c -c
- $(CC) $(CFLAGS) cmd_cookie.c -c
- $(CC) $(CFLAGS) cmd_botu.c -c
- $(CC) $(CFLAGS) cmd_fir1p.c -c
- $(CC) $(CFLAGS) sds.c -c
- $(CC) $(CFLAGS) cmd_rand.c -c
- $(CC) $(CFLAGS) cmd_rand_libc.c -c
- $(CC) $(CFLAGS) cmd_fir.c -c
- $(CC) $(CFLAGS) tbl_qcmd.o mq_cmd.o mq_ntf.o buf.o mmm.o darray.o util.o sock_conn.o \
- irc_parse.o mmm.c cmd_date.o cmd_uptime.o cmd_version.o cmd_ping.o cmd_loadavg.o \
- cmd_rusage.o cmd_cmd.o sha1.o cmd_sha1.o cmd_cookie.o cmd_botu.o cmd_fir1p.o sds.o \
- cmd_rand.o cmd_rand_libc.o cmd_fir.o agni.c \
- -o $(PROJECT) -std=c11 -lrt -lm
+all: createcmd createextlib $(OBJECTS) $(PROJECT)
+$(PROJECT): version $(SOURCES) agni.c
+ $(CC) $(OBJECTS) $(CFLAGS) $(LDFLAGS) -std=c11 -o $(PROJECT)
+
+#make: version
+# $(CC) $(CFLAGS) agni.c \
+# -o $(PROJECT) -std=c11 -lrt -lm
+
+%.o: %.c
+ @echo $@
+ $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $(subst .c,.o,$<)
+
+#autogenerate version from git commit and date when it was compiled
version:
#could have bug if commit message have somethign bad in it
rm -f version.h
@@ -44,8 +29,35 @@ version:
echo "#define VERSION_COMMIT \""`git log -1 --oneline`"\"">>version.h
echo "#endif">>version.h
+#get all C files in cmd firectory and compile all of them
+CMD_SOURCES=$(wildcard cmd/*.c)
+CMD_HEADERS=$(wildcard cmd/*.h)
+#output header with all includes to commands
+CMD_INC_HEADER=config_all_cmds.h
+#cmd object files
+CMD_OBJECTS=$(CMD_SOURCES:.c=.o)
+#add commands objects to all objects
+OBJECTS+=$(CMD_OBJECTS)
+createcmd: headerscmd $(CMD_OBJECTS)
+ #echo $(CMD_SOURCES)
+ #echo $(CMD_OBJECTS)
+
+#generate header files with all commands in directory, to include all cmd header files in single include
+headerscmd:
+ rm -f $(CMD_INC_HEADER)
+ echo "#ifndef __CONFIG_CMD_HEADERS_H">>$(CMD_INC_HEADER)
+ echo "#define __CONFIG_CMD_HEADERS_H">>$(CMD_INC_HEADER)
+ for header in $(CMD_HEADERS); do echo -e "#include \"$$header\"">>$(CMD_INC_HEADER); done
+ echo "#endif">>$(CMD_INC_HEADER)
+
+EXTLIB_SOURCES=$(wildcard extlibs/*.c)
+EXTLIB_OBJECTS=$(EXTLIB_SOURCES:.c=.o)
+OBJECTS+=$(EXTLIB_OBJECTS)
+createextlib: $(EXTLIB_OBJECTS)
+ #asd
+
leak:
valgrind --leak-check=full --track-origins=yes --log-file=log.txt ./$(PROJECT)
clean:
- rm -f agni *.o \ No newline at end of file
+ rm -f agni *.o cmd/*.o \ No newline at end of file