# **************************************************************************** #
#                                                                              #
#                                                         :::      ::::::::    #
#    Makefile                                           :+:      :+:    :+:    #
#                                                     +:+ +:+         +:+      #
#    By: gbaconni@student.42lausanne.ch             +#+  +:+       +#+         #
#                                                 +#+#+#+#+#+   +#+            #
#    Created: 2022/04/16 20:12:38 by gbaconni          #+#    #+#              #
#    Updated: 2022/04/29 22:04:24 by gbaconni         ###   lausanne.ch        #
#                                                                              #
# **************************************************************************** #

KERNEL = $(shell uname -s)
MACHINE = $(shell uname -m)

all: test

libftprintf:
	@ln -snf ../libftprintf libftprintf

libftprintf.a: libftprintf
	@ln -snf libftprintf/libftprintf.a libftprintf.a

bonus: libftprintf
	@make -C libftprintf bonus

test: test-pft test-printftester

test2: test-pft2 test-printftester2

test3: test-pft3 test-printftester3

test-pft: pft
	@cd pft && ./test mix

test-pft2: pft
	@cd pft && ./test

test-pft3: pft
	@cd pft && ./test c
	@cd pft && ./test s
	@cd pft && ./test p
	@cd pft && ./test d
	@cd pft && ./test i
	@cd pft && ./test u
	@cd pft && ./test x
	@cd pft && ./test X

test-printftester: printftester
	@make -C printftester m

test-printftester2: printftester
	@make -C printftester b

test-printftester3: printftester
	@make -C printftester a

printftester: bonus libftprintf
	@test -d ~/goinfre/ || ln -snf /goinfre/$(USER) ~/goinfre
	@test -d ~/goinfre/docker/ || install -d ~/goinfre/docker
	@test -d ~/goinfre/agent/ || install -d ~/goinfre/agent
	@test -d ~/.docker/ || ln -snf ~/goinfre/docker ~/.docker
ifeq ($(KERNEL),Darwin)
	@test -d ~/Library/Containers/com.docker.docker || ln -snf ~/goinfre/agent ~/Library/Containers/com.docker.docker
endif
	@test -d printftester || git clone https://github.com/Tripouille/printfTester.git printftester
	@grep -qF '../libftprintf' printftester/Makefile || sed -i '' 's/\(\.\.\)/\1\/libftprintf/' printftester/Makefile

pft: bonus libftprintf.a
	@test -d pft || git clone https://github.com/gavinfielder/pft.git pft
ifeq ($(KERNEL),Linux)
	@which php >/dev/null 2>&1 || sudo apt-get install -qq -y php-cli
	@sed -i -r 's/^(INCLUDE_LIBPTHREAD)=.*/\1=1/' pft/options-config.ini
endif
	@make -C pft

clean:
	@make -C pft clean

fclean:
	@rm -f libftprintf libftprintf.a
	@rm -fr pft printftester

