1# -----------------------------------------------------------------------------
2#
3# (c) 2010 The University of Glasgow
4#
5# This file is part of the GHC build system.
6#
7# To understand how the build system works and how to modify it, see
8#      https://gitlab.haskell.org/ghc/ghc/wikis/building/architecture
9#      https://gitlab.haskell.org/ghc/ghc/wikis/building/modifying
10#
11# -----------------------------------------------------------------------------
12
13# For each line in $(TOP)/packages:
14#     libraries/foo    tag    ...
15# this calls
16#     $(call $1,foo,tag)
17#
18# Except! If there's a libraries/foo/ghc-packages then it calls
19#     $(call $1,foo/bar,tag)
20# for each word 'bar' in libraries/foo/ghc-packages.
21#
22
23# We use an FEL_ prefix for the variable names, to avoid trampling on
24# other variables, as make has no concept of local variables.
25
26# We need to handle the following packages specially, as those don't
27# have an entry in the packages file, since they don't live in
28# repositories of their own:
29#
30#  - base
31#  - ghc-boot
32#  - ghc-boot-th
33#  - ghc-prim
34#  - integer-gmp
35#  - integer-simple
36#  - template-haskell
37
38define foreachLibrary
39# $1 = function to call for each library
40# We will give it the package path and the tag as arguments
41$$(foreach hashline,libraries/ghc-boot-th#-#no-remote-repo#no-vcs           \
42                    libraries/ghc-boot#-#no-remote-repo#no-vcs              \
43                    libraries/ghci#-#no-remote-repo#no-vcs                  \
44                    libraries/base#-#no-remote-repo#no-vcs                  \
45                    libraries/ghc-prim#-#no-remote-repo#no-vcs              \
46                    libraries/integer-gmp#-#no-remote-repo#no-vcs           \
47                    libraries/integer-simple#-#no-remote-repo#no-vcs        \
48                    libraries/template-haskell#-#no-remote-repo#no-vcs      \
49                    $$(shell grep '^libraries/' packages | sed 's/  */#/g'),\
50    $$(eval FEL_line    := $$(subst #,$$(space),$$(hashline)))              \
51    $$(eval FEL_libdir  := $$(word 1,$$(FEL_line)))                         \
52    $$(eval FEL_tag     := $$(word 2,$$(FEL_line)))                         \
53    $$(eval FEL_libroot := $$(patsubst libraries/%,%,$$(FEL_libdir)))       \
54    $$(if $$(wildcard $$(FEL_libdir)/ghc-packages),                         \
55        $$(foreach lib,$$(shell cat $$(FEL_libdir)/ghc-packages),           \
56            $$(eval $$(call $1,$$(FEL_libroot)/$$(lib),$$(FEL_tag)))),      \
57        $$(if $$(wildcard $$(FEL_libdir)/),                                 \
58            $$(eval $$(call $1,$$(FEL_libroot),$$(FEL_tag))))))
59endef
60