1 | #!/bin/bash
|
---|
2 | #
|
---|
3 | # $Id$
|
---|
4 | #
|
---|
5 | set -e
|
---|
6 |
|
---|
7 | # Uncomment this when reasy to be used
|
---|
8 | #source ../configuration
|
---|
9 |
|
---|
10 | # TEMPORARY VARIABLES.. development use only
|
---|
11 | declare MKFILE=Makefile
|
---|
12 | declare PREV_PACKAGE=""
|
---|
13 | declare BUILD_SCRIPTS=scripts
|
---|
14 | # Remove this when we can use configuration
|
---|
15 | declare TRACKING_DIR=/var/lib/jhalfs/BLFS
|
---|
16 |
|
---|
17 | HEADER="# This file is automatically generated by jhalfs
|
---|
18 | # YOU MAY NEED TO EDIT THIS FILE MANUALLY
|
---|
19 | #
|
---|
20 | # Generated on `date \"+%F %X %Z\"`"
|
---|
21 |
|
---|
22 |
|
---|
23 | #----------------------------------#
|
---|
24 | __wrt_target() { # Create target and initialize log file
|
---|
25 | #----------------------------------#
|
---|
26 | local i=$1
|
---|
27 | local PREV=$2
|
---|
28 | (
|
---|
29 | cat << EOF
|
---|
30 |
|
---|
31 | $i: $PREV
|
---|
32 | @\$(call echo_message, Building)
|
---|
33 | @./progress_bar.sh \$@ &
|
---|
34 | EOF
|
---|
35 | ) >> $MKFILE.tmp
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 |
|
---|
40 | #----------------------------------#
|
---|
41 | __write_build_cmd() { #
|
---|
42 | #----------------------------------#
|
---|
43 | (
|
---|
44 | cat << EOF
|
---|
45 | @source ../envars.conf && ${BUILD_SCRIPTS}/\$@ >logs/\$@ 2>&1
|
---|
46 | EOF
|
---|
47 | ) >> $MKFILE.tmp
|
---|
48 | }
|
---|
49 |
|
---|
50 | #----------------------------------#
|
---|
51 | __wrt_touch() { #
|
---|
52 | #----------------------------------#
|
---|
53 | local pkg_name=$1
|
---|
54 | local pkg_ver=$2
|
---|
55 |
|
---|
56 | if [[ -n "$pkg_ver" ]] ; then
|
---|
57 | (
|
---|
58 | cat << EOF
|
---|
59 | @touch \$(TRACKING_DIR)/${pkg_name#*-?-}-${pkg_ver}
|
---|
60 | EOF
|
---|
61 | ) >> $MKFILE.tmp
|
---|
62 | fi
|
---|
63 |
|
---|
64 | (
|
---|
65 | cat << EOF
|
---|
66 | @touch \$@ && \\
|
---|
67 | sleep .25 && \\
|
---|
68 | echo -e "\n\n "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
69 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
70 | EOF
|
---|
71 | ) >> $MKFILE.tmp
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | #----------------------------#
|
---|
76 | __write_entry() { #
|
---|
77 | #----------------------------#
|
---|
78 | local script_name=$1
|
---|
79 | local pkg_ver=$2
|
---|
80 |
|
---|
81 | echo -n "${tab_}${tab_} entry for <$script_name>"
|
---|
82 |
|
---|
83 | #--------------------------------------------------------------------#
|
---|
84 | # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
|
---|
85 | #--------------------------------------------------------------------#
|
---|
86 | #
|
---|
87 | # Drop in the name of the target on a new line, and the previous target
|
---|
88 | # as a dependency. Also call the echo_message function.
|
---|
89 | __wrt_target "${script_name}" "$PREV_PACKAGE"
|
---|
90 | __write_build_cmd
|
---|
91 |
|
---|
92 | # Include a touch of the target name so make can check
|
---|
93 | # if it's already been made.
|
---|
94 | __wrt_touch "${script_name}" "${pkg_ver}"
|
---|
95 | #
|
---|
96 | #--------------------------------------------------------------------#
|
---|
97 | # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
|
---|
98 | #--------------------------------------------------------------------#
|
---|
99 | echo " .. OK"
|
---|
100 | }
|
---|
101 |
|
---|
102 | #----------------------------#
|
---|
103 | generate_Makefile () { #
|
---|
104 | #----------------------------#
|
---|
105 |
|
---|
106 |
|
---|
107 | echo "${tab_}Creating Makefile... ${BOLD}START${OFF}"
|
---|
108 |
|
---|
109 | # Start with a clean files
|
---|
110 | >$MKFILE
|
---|
111 | >$MKFILE.tmp
|
---|
112 |
|
---|
113 |
|
---|
114 | for package_script in scripts/* ; do
|
---|
115 | this_script=`basename $package_script`
|
---|
116 | pkg_ver=$(grep "^${this_script#*-?-}[[:space:]]" ../packages | cut -f3)
|
---|
117 | pkg_list="$pkg_list ${this_script}"
|
---|
118 | __write_entry "${this_script}" "${pkg_ver}"
|
---|
119 | PREV_PACKAGE=${this_script}
|
---|
120 | done
|
---|
121 |
|
---|
122 |
|
---|
123 | # Add a header, some variables and include the function file
|
---|
124 | # to the top of the real Makefile.
|
---|
125 | (
|
---|
126 | cat << EOF
|
---|
127 | $HEADER
|
---|
128 |
|
---|
129 | PACKAGE= "`basename $PWD`"
|
---|
130 | TRACKING_DIR= $TRACKING_DIR
|
---|
131 |
|
---|
132 | BOLD= "[0;1m"
|
---|
133 | RED= "[1;31m"
|
---|
134 | GREEN= "[0;32m"
|
---|
135 | ORANGE= "[0;33m"
|
---|
136 | BLUE= "[1;34m"
|
---|
137 | WHITE= "[00m"
|
---|
138 |
|
---|
139 | define echo_message
|
---|
140 | @echo \$(BOLD)
|
---|
141 | @echo --------------------------------------------------------------------------------
|
---|
142 | @echo \$(BOLD)\$(1) target \$(BLUE)\$@\$(BOLD)
|
---|
143 | @echo \$(WHITE)
|
---|
144 | endef
|
---|
145 |
|
---|
146 |
|
---|
147 | define fin_message
|
---|
148 | @echo \$(BOLD)
|
---|
149 | @echo --------------------------------------------------------------------------------
|
---|
150 | @echo \$(BOLD) Build complete for the package \$(BLUE)\$(PACKAGE)\$(BOLD) and its dependencies
|
---|
151 | @echo \$(WHITE)
|
---|
152 | endef
|
---|
153 |
|
---|
154 | all : $pkg_list
|
---|
155 | @\$(call fin_message )
|
---|
156 | EOF
|
---|
157 | ) > $MKFILE
|
---|
158 |
|
---|
159 | cat $MKFILE.tmp >> $MKFILE
|
---|
160 | echo "${tab_}Creating Makefile... ${BOLD}DONE${OFF}"
|
---|
161 |
|
---|
162 | rm $MKFILE.tmp
|
---|
163 |
|
---|
164 | }
|
---|
165 |
|
---|
166 | generate_Makefile
|
---|
167 |
|
---|
168 | cp ../progress_bar.sh .
|
---|
169 |
|
---|
170 | mkdir -p logs
|
---|