Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,126 @@
1
+# lib-type may be given from commandline to control 
2
+# if resulting library will be static or shared
3
+# possible values: static, shared
4
+lib-type ?= shared
5
+
6
+# install directories
7
+prefix ?= /usr/local
8
+bin-dir ?= ${prefix}/bin
9
+include-dir ?= ${prefix}/include
10
+lib-dir ?= ${prefix}/lib
11
+
12
+# install programs
13
+install          ?= install
14
+install-bin      ?= $(install) -m 755
15
+install-lib      ?= $(install) -m 755
16
+install-includes ?= $(install) -m 644
17
+
18
+# working variables
19
+SRCS := $(wildcard *.c)
20
+HDRS := $(wildcard *.h)
21
+DEP_IN = ${SRCS} ${HDRS}
22
+OBJS := $(patsubst %.c,%.o,$(SRCS))
23
+
24
+####################################
25
+# make rules
26
+
27
+static_lib_name  = lib${NAME}.a
28
+dynamic_lib_name = lib${NAME}.so
29
+prg_name = ${NAME}
30
+
31
+out_name = ${prg_name}
32
+
33
+ifeq ($(TYPE),lib)
34
+INCLUDES += -I$(CURDIR)/..
35
+ifeq ($(lib-type),static)
36
+out_name = ${static_lib_name}
37
+else
38
+out_name = ${dynamic_lib_name}
39
+endif
40
+endif
41
+
42
+default:	${out_name}
43
+
44
+#static library
45
+
46
+${static_lib_name}:	${OBJS}
47
+		ar -r $@ ${OBJS}
48
+
49
+# dynamic library
50
+
51
+${dynamic_lib_name}:	${OBJS}
52
+		${CC} -shared ${DEFS} ${CFLAGS} ${INCLUDES} -o $@ ${OBJS} ${LIBS}
53
+
54
+# executable
55
+
56
+${NAME}:	${OBJS}
57
+		${CC} ${DEFS} ${CFLAGS} ${INCLUDES} -o $@ ${OBJS} ${LIBS}
58
+		
59
+# common rules
60
+
61
+%.o:	%.c
62
+		${CC} ${DEFS} ${CFLAGS} ${INCLUDES} -c $<
63
+
64
+.PHONY:	install clean proper
65
+
66
+proper: clean
67
+
68
+clean:
69
+		-@rm -f ${prg_name} ${static_lib_name} ${dynamic_lib_name} *.o *.so *.d core core.* *~ tags Makefile.deps
70
+
71
+
72
+ifneq ($(MAKECMDGOALS),proper)
73
+ifneq ($(MAKECMDGOALS),clean)
74
+-include $(SRCS:.c=.d)
75
+endif
76
+endif
77
+
78
+%.d:	%.c
79
+		@$(CC) -M ${DEFS} $(CFLAGS) $(INCLUDES) $< > $@.$$$$; \
80
+		sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
81
+		rm -f $@.$$$$
82
+
83
+
84
+# -include Makefile.deps
85
+#
86
+# Makefile.deps: ${DEP_IN}
87
+#		@echo "" > Makefile.deps
88
+#		@makedepend -fMakefile.deps -- ${DEFS} ${CFLAGS} ${INCLUDES} -- ${DEP_IN} 2>/dev/null
89
+#		-@rm -f Makefile.deps.bak
90
+
91
+# instalation rules
92
+
93
+ifeq ($(TYPE),lib)
94
+
95
+# library instalation
96
+
97
+install:	${out_name} install_dirs
98
+			$(install-lib) ${out_name} $(lib-dir)
99
+			@for hdr in ${HDRS} ; do \
100
+				$(install-includes) $$hdr $(include-dir)/$(NAME); \
101
+			done
102
+
103
+install_dirs:	$(lib-dir) $(include-dir)/$(NAME)
104
+
105
+else
106
+
107
+# executable instalation
108
+
109
+install:	${out_name} install_dirs
110
+			$(install-bin) ${out_name} $(bin-dir)
111
+
112
+install_dirs:	$(bin-dir)
113
+				
114
+endif
115
+
116
+# creating install directories
117
+
118
+$(bin-dir):	
119
+			mkdir -p $(bin-dir)
120
+
121
+$(lib-dir):	
122
+			mkdir -p $(lib-dir)
123
+			
124
+$(include-dir)/$(NAME):	
125
+			mkdir -p $(include-dir)/$(NAME)
126
+