summaryrefslogtreecommitdiff
path: root/Makefile
blob: 8926e9887495cfdfd079241f53407448707d8d30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
.PHONY: server client shared clean install uninstall cleanall

# > configuration start

inst_dir	=	/usr/local/

lib_name	:=	som_net

CC			=	gcc
CFLAGS		=	-I. -g -Wall -Werror -Wextra
LD_FLAGS	=	-L.

# < configuration end

.SOURCES	:=	$(wildcard $(MAKECMDGOALS)/*.c)
.OBJECTS	:=	$(patsubst $(MAKECMDGOALS)/%.c,$(MAKECMDGOALS)/%.o,$(.SOURCES))

SHARED_LD	=	-shared -fPIC
CLIENT_LD	=	-l${lib_name}
SERVER_LD	=	-l${lib_name}

export LD_LIBRARY_PATH=`pwd`
# help text
default:
	@echo "targets:"
	@echo " build: *shared is required for all targets"
	@echo "	> shared, client, server"
	@echo " delete:"
	@echo "	> clean, uninstall, cleanall"
	@echo " install:"
	@echo "	> install"

# target: client
client: .client_comp
.client_comp: $(.OBJECTS)
	$(CC) ${LD_FLAGS} ${CFLAGS} -o client_example ${.OBJECTS} ${CLIENT_LD}

# target: server
server: .server_comp
.server_comp: $(.OBJECTS)
	$(CC) ${LD_FLAGS} ${CFLAGS} -o server_example ${.OBJECTS} ${SERVER_LD}

# target: shared
shared: .shared_comp
.shared_comp: $(.OBJECTS)
	$(CC) ${LD_FLAGS} ${SHARED_LD} ${CFLAGS} -o lib${lib_name}.so ${.OBJECTS} 

clean:
	rm -f $(wildcard ./**/*.o) client_example server_example lib${lib_name}.so

install:
	cp "lib${lib_name}.so" "${inst_dir}lib/"
	mkdir -p "${inst_dir}include/${lib_name}/"
	cp shared/*.h "${inst_dir}include/${lib_name}/"

uninstall:
	rm "${inst_dir}lib/lib${lib_name}.so"
	rm -r "${inst_dir}include/${lib_name}"

cleanall: clean uninstall

**/%.o: **/%.c
	$(CC) -c -o $@ $<