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