summaryrefslogblamecommitdiff
path: root/Makefile
blob: 8926e9887495cfdfd079241f53407448707d8d30 (plain) (tree)
1
2
3
4
5
6
                                                             


                       

                                   














                                                                                       
                            

           






                                                           


















                                                                                  










                                                       

                         
.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 $@ $<