Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 6.20 KB | None | 0 0
  1. # **************************************************************************** #
  2. #                                                                              #
  3. #                                                         ::::::::             #
  4. #    Makefile                                           :+:    :+:             #
  5. #                                                      +:+                     #
  6. #    By: pholster <pholster@student.codam.nl>         +#+                      #
  7. #                                                    +#+                       #
  8. #    Created: 2019/01/07 20:00:45 by pholster       #+#    #+#                 #
  9. #    Updated: 2019/08/19 19:21:26 by pholster      ########   odam.nl          #
  10. #                                                                              #
  11. # **************************************************************************** #
  12.  
  13. SYNCOPTIMISE = TRUE
  14. GCOVSILENT = TRUE
  15. CCSILENT = FALSE
  16. GCOV = FALSE
  17.  
  18. GCOVFLAGS = -f -b -c
  19.  
  20. SILENCE = &>/dev/null
  21. GET_OBJS = $(shell ar -t $(1) | grep '\.o' | sed 's/^/$(2:%=%\/src\/)/g')
  22. GET_GCOV = (gcov $(GCOVFLAGS) $(1) && mv $(shell basename $(1:%=%.gcov)) src)
  23. ifeq ($(GCOVSILENT), TRUE)
  24. GET_GCOV += $(SILENCE)
  25. endif
  26.  
  27. PRINTFPATH = ft_printf
  28. PRINTF = $(PRINTFPATH)/libftprintf.a
  29. PRINTF_OBJS = $(call GET_OBJS,$(PRINTF),$(PRINTFPATH))
  30. PRINTF_SRCS = $(PRINTF_OBJS:%.o=%.c)
  31.  
  32. THREADPOOLPATH = threadpool
  33. THREADPOOL = $(THREADPOOLPATH)/threadpool.a
  34. THREADPOOL_OBJS = $(call GET_OBJS,$(THREADPOOL),$(THREADPOOLPATH))
  35. THREADPOOL_SRCS = $(THREADPOOL_OBJS:%.o=%.c)
  36.  
  37. TESTPATH = tests
  38. TEST = $(TESTPATH)/libtest
  39.  
  40. NAME = libft.a
  41. INCLUDES = includes
  42. HEADERS = libft.h typedefs.h
  43. HEADERS := $(HEADERS:%=$(INCLUDES)/%)
  44.  
  45. include $(INCLUDES)/Makefile.color
  46.  
  47. PREFIX = lf
  48. FT_SRCS = putchar putnum putstr sqrt strcmp strdup strlen swap isalpha isalnum \
  49.     isascii isprint toupper tolower putendl putchar_fd putstr_fd putendl_fd \
  50.     putnum_fd strnew strclr strdel striter striteri strmap strmapi isspace \
  51.     itoa pow atoi strncmp strcpy strcat strequ strnequ strncat strlcat strchr \
  52.     strrchr strstr strnstr strsub strjoin strtrim strsplit memset bzero memcpy \
  53.     memdel memalloc memccpy memmove memcmp strncpy lstnew lstdelone lstdel \
  54.     lstadd lstiter lstmap memchr isdigit count_if puterror strtoupper \
  55.     strtolower putline chrin chrnin numin strin strnin putstrarr putnumarr \
  56.     strndup strdlen wrddcount chrtostr lstaddbck lstdelmem lsttostrarr \
  57.     strarrtolst lstlen strmatch strrev lstdup lstdupone putstrlst putbool \
  58.     numarrtolst putnumlst lsttonumarr min max constrain abs memreplace \
  59.     getnextline termclr strarrnew strarrdel itoa_base atoi_base \
  60.     isdigitstr strfldnew chrindex putpointer strdsplit putnum_base strdtrim \
  61.     putnum_base_fd putline_fd isupper islower chrdin numlen_base numlen \
  62.     unumlen unumlen_base strappend memdup lstunlink getchar putnstr putnstr_fd \
  63.     strnlen strjoin_var strarrlen getnextdline chrdindex putnum_cbase_fd \
  64.     putnum_cbase lstfind_content lstfind_size memrcpy lstlast strjoin_arr \
  65.     lstfindadd_content lstrev lstfindadd_size strfldvalid memequ lstnlen \
  66.     strarrnlen strislen putlstsize strarrrev numarrsort numarrsortrev lstsort \
  67.     lstsortrev strarrsort lstinsert lstindex termsetcolor termsetcolorbg \
  68.     termresetcolor termresetcolorbg strnequ_nocase strequ_nocase colorcode \
  69.     strncmp_nocase strmatchlen strcmp_nocase strarrcpy colorncode colorlcode \
  70.     strmatchlen_nocase colorstr termcommand termsetrgbcolorbg termsetrgbcolor \
  71.     pututf8 utf8len utf8strlen utf8strnlen putnutf8str pututf8str putunum_base \
  72.     putunum_cbase putunum_fd putunum_base_fd putunum_cbase_fd putunum memindex \
  73.     strarrnsortrev strarrnsort strarrsortrev numarrsortac strarrsortac inrange \
  74.     lstsortstrac strarrcpy_var strarrdup itoa_cbase putbytes chrsetbytes \
  75.     chrinbytes putdouble isblank putdouble_fd putnutf8str_fd pututf8_fd \
  76.     pututf8str termcommand_fd termclr_fd termresetcolorbg_fd termresetcolor_fd \
  77.     termsetrgbcolorbg_fd termsetrgbcolor_fd termsetcolorbg_fd termsetcolor_fd \
  78.     putbool_fd readfile print_memory putnchar putnchar_fd pututf8str_fd \
  79.     memrchr strarrdup_var strarrtolower strarrtoupper strindex strnindex \
  80.     normalize nearestnum strreplace colorrgbatohex colorhextorgba percentage \
  81.     overflow hashmapnew hashsdbm hashdjb hashmapadd
  82. SRCS =
  83. SRCS := $(FT_SRCS:%=src/ft_%.c) $(SRCS:%=src/$(PREFIX)_%.c)
  84.  
  85. SRCS := $(sort $(SRCS))
  86. OBJS = $(SRCS:.c=.o)
  87. GCOVS = $(OBJS:.o=.c.gcov)
  88. GCDAS = $(OBJS:.o=.gcda)
  89. GCNOS = $(OBJS:.o=.gcno)
  90.  
  91. CCOPTIMISE =
  92. CCSTRICT = -Wall -Werror -Wextra
  93. CCFLAGS = -g $(CCSTRICT) -I$(INCLUDES) $(CCOPTIMISE)
  94. ifeq ($(GCOV), TRUE)
  95. CCFLAGS += -coverage
  96. endif
  97.  
  98. export GCOV
  99. export CCSILENT
  100. export CCSTRICT
  101.  
  102. ifeq ($(SYNCOPTIMISE), TRUE)
  103. export CCOPTIMISE
  104. endif
  105.  
  106. all: $(NAME)
  107.  
  108. ifeq ($(GCOV), TRUE)
  109. $(NAME): $(PRINTF) $(THREADPOOL) $(OBJS) $(GCNOS)
  110. else
  111. $(NAME): $(PRINTF) $(THREADPOOL) $(OBJS)
  112. endif
  113.     @printf '$(PRINT_EQUAL) $(NAME:%.a=%): $(NAME)\n'
  114.     @ar rcs $(NAME) $(OBJS) $(PRINTF_OBJS) $(THREADPOOL_OBJS)
  115.  
  116. %.o %.gcno: %.c $(HEADERS)
  117. ifeq ($(CCSILENT), FALSE)
  118.     @printf '$(PRINT_PLUS) $(NAME:%.a=%): $(shell basename $@)\n'
  119. endif
  120.     @rm -f $(<:.c=.o)
  121.     @gcc $(CCFLAGS) -o $(<:.c=.o) -c $<
  122.  
  123. $(PRINTF): FORCE
  124.     @$(MAKE) -s -e -C $(PRINTFPATH)
  125.  
  126. $(THREADPOOL): FORCE
  127.     @$(MAKE) -s -e -C $(THREADPOOLPATH)
  128.  
  129. test: $(NAME) FORCE
  130. ifneq ($(wildcard $(TESTPATH)),)
  131.     @$(MAKE) -s -e -C $(TESTPATH)
  132.     @./$(TEST)
  133. ifeq ($(GCOV), TRUE)
  134.     @$(call GET_GCOV,$(SRCS))
  135.     @$(MAKE) -s -e -C $(PRINTFPATH) getgcov
  136.     @$(MAKE) -s -e -C $(THREADPOOLPATH) getgcov
  137. endif
  138. else
  139.     @echo "Error: $(TESTPATH) not present"
  140. endif
  141.  
  142. clean:
  143. ifneq ($(wildcard $(OBJS) $(SRCS:.c=.c~) $(GCOVS) $(GCDAS) $(GCNOS)),)
  144.     @printf '$(PRINT_MIN) $(NAME:%.a=%): cleaning\n'
  145.     @rm -f $(OBJS) $(SRCS:.c=.c~) $(GCOVS) $(GCDAS) $(GCNOS)
  146. endif
  147.     @$(MAKE) -s -C $(PRINTFPATH) clean
  148.     @$(MAKE) -s -C $(THREADPOOLPATH) clean
  149. ifneq ($(wildcard $(TESTPATH)),)
  150.     @$(MAKE) -s -C $(TESTPATH) fclean
  151. endif
  152.  
  153. fclean: clean
  154. ifneq ($(wildcard $(NAME)),)
  155.     @printf '$(PRINT_MIN) $(NAME:%.a=%): deleting $(NAME)\n'
  156.     @rm -f $(NAME)
  157. endif
  158.     @$(MAKE) -s -C $(PRINTFPATH) fclean
  159.     @$(MAKE) -s -C $(THREADPOOLPATH) fclean
  160. ifneq ($(wildcard $(TESTPATH)),)
  161.     @$(MAKE) -s -C $(TESTPATH) fclean
  162. endif
  163.  
  164. re: fclean $(NAME)
  165.  
  166. FORCE: ;
  167.  
  168. .PHONY: test clean fclean re
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement