init
This commit is contained in:
86
Makefile
Normal file
86
Makefile
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
|
||||||
|
# - - - - - - - - - - - - - - # name = value \
|
||||||
|
# variables names # value
|
||||||
|
# - - - - - - - - - - - - - - # ! name is case sensitive
|
||||||
|
|
||||||
|
NAME = minitalk
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
VPATH = srcs
|
||||||
|
|
||||||
|
IDIR = ./includes
|
||||||
|
_DEPS = fdf.h
|
||||||
|
DEPS = $(_DEPS:%.h=$(IDIR)/%.h)
|
||||||
|
|
||||||
|
LDIR = ./libft
|
||||||
|
_LIBS = libft.a
|
||||||
|
LIBS = $(_LIBS:lib%.a=%)
|
||||||
|
|
||||||
|
SRCS = fdf.c \
|
||||||
|
parse.c \
|
||||||
|
modifs.c \
|
||||||
|
draw.c \
|
||||||
|
keypress.c
|
||||||
|
|
||||||
|
SRCS_B = fdf.c \
|
||||||
|
parse.c \
|
||||||
|
modifs.c \
|
||||||
|
keypress_bonus.c \
|
||||||
|
draw_bonus.c
|
||||||
|
|
||||||
|
ODIR = ./builds
|
||||||
|
OBJS = $(SRCS:%.c=$(ODIR)/%.o)
|
||||||
|
OBJS_B = $(SRCS_B:%.c=$(ODIR)/%.o)
|
||||||
|
|
||||||
|
# flag -g generates debug informations, g3 is maximal version
|
||||||
|
CFLAGS = -I$(IDIR) -g3 -Wall -Wextra -Werror
|
||||||
|
LFLAGS = -L$(LDIR) -l$(LIBS)
|
||||||
|
CFLAGS += -I./minilibx-linux-master
|
||||||
|
LFLAGS += -lm -lmlx -lXext -lX11 -L./minilibx-linux-master
|
||||||
|
|
||||||
|
|
||||||
|
# - - - - - - - - - - - - - - # target: prerequisites | $@ : target
|
||||||
|
# rules to execute # recipe | $< : 1st prerequisite
|
||||||
|
# - - - - - - - - - - - - - - # recipe | $^ : all prerequisites
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(ODIR) $(OBJS) $(DEPS)
|
||||||
|
make -C $(LDIR)
|
||||||
|
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LFLAGS)
|
||||||
|
|
||||||
|
bonus: fclean $(ODIR) $(OBJS_B) $(DEPS)
|
||||||
|
make -C $(LDIR)
|
||||||
|
$(CC) $(CFLAGS) -o fdf $(OBJS_B) $(LFLAGS)
|
||||||
|
|
||||||
|
$(ODIR):
|
||||||
|
mkdir -p $@
|
||||||
|
|
||||||
|
$(ODIR)/%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
debug: CFLAGS += -fsanitize=address
|
||||||
|
debug: clean $(NAME)
|
||||||
|
|
||||||
|
leaks: $(NAME)
|
||||||
|
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) maps/42_color.fdf
|
||||||
|
# valgrind --leak-check=full --leak-resolution=low --show-reachable=yes ./$(NAME) maps/42_color.fdf
|
||||||
|
|
||||||
|
clean:
|
||||||
|
/bin/rm -f $(OBJS) $(OBJS_B)
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
/bin/rm -rf $(ODIR)
|
||||||
|
/bin/rm -f $(NAME)
|
||||||
|
/bin/rm -rf a.out a.out.dSYM
|
||||||
|
|
||||||
|
libfclean:
|
||||||
|
make fclean -C $(LDIR)
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
relib: libfclean re
|
||||||
|
|
||||||
|
.PHONY: all clean fclean re gcc
|
||||||
|
|
||||||
9
includes/minitalk.h
Normal file
9
includes/minitalk.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef FT_PRINTF_H
|
||||||
|
# define FT_PRINTF_H
|
||||||
|
|
||||||
|
# include <signal.h> // for signal kill
|
||||||
|
# include <sys/types.h> // for getpid kill
|
||||||
|
# include <unistd.h> // for getpid
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
BIN
minitalk.pdf
Normal file
BIN
minitalk.pdf
Normal file
Binary file not shown.
BIN
srcs/client
Executable file
BIN
srcs/client
Executable file
Binary file not shown.
10
srcs/client.c
Normal file
10
srcs/client.c
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include "../includes/minitalk.h"
|
||||||
|
#include <stdlib.h> //for atoi
|
||||||
|
|
||||||
|
int main(int ac, char **av)
|
||||||
|
{
|
||||||
|
if (ac != 2)
|
||||||
|
return (0);
|
||||||
|
kill(atoi(av[1]), SIGUSR1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
BIN
srcs/server
Executable file
BIN
srcs/server
Executable file
Binary file not shown.
40
srcs/server.c
Normal file
40
srcs/server.c
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#include "../includes/minitalk.h"
|
||||||
|
#include <stdio.h> // for printf
|
||||||
|
|
||||||
|
void put_client_pid(int client_pid)
|
||||||
|
{
|
||||||
|
printf("%i\n", client_pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int pid;
|
||||||
|
|
||||||
|
pid = (int)getpid();
|
||||||
|
printf("%i\n", pid);
|
||||||
|
signal(SIGUSR1, put_client_pid);
|
||||||
|
while (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
**
|
||||||
|
** allowed functions :
|
||||||
|
** - write
|
||||||
|
** - signal
|
||||||
|
** - sigemptyset
|
||||||
|
** - sigaddset
|
||||||
|
** - sigaction
|
||||||
|
** - kill
|
||||||
|
** - getpid
|
||||||
|
** - malloc
|
||||||
|
** - free
|
||||||
|
** - pause
|
||||||
|
** - sleep
|
||||||
|
** - usleep
|
||||||
|
** - exit
|
||||||
|
**
|
||||||
|
** you can only use two signals :
|
||||||
|
** - SIGUSR1
|
||||||
|
** - SIGUSR2
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user