]> arthur.barton.de Git - ax-make.git/blob - scripts/axify
axify: Fix quoting of output in Download() function
[ax-make.git] / scripts / axify
1 #!/bin/sh
2 #
3 # ax-make: Alex' Simple Makefile System
4 # Copyright (c)2014 Alexander Barton (alex@barton.de)
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11
12 NAME=`basename "$0"`
13
14 Usage() {
15         echo "Usage: $NAME [-2|-3|-l <lic>] [<lib-dir>]"
16         echo
17         echo '  -2           Use the GNU GPLv2 for the COPYING file.'
18         echo '  -3           Use the GNU GPLv3 for the COPYING file.'
19         echo '  -l <lic>     Specify license to use for the COPYING file:'
20         echo '               <lic> can be "gpl2", "gpl3", "lgpl21", "lgpl3".'
21         echo '               By default an empty COPYING file is created.'
22         echo
23         echo "  <lib-dir>    Library directory. Default: current working directory."
24         echo
25         exit 2
26 }
27
28 Download() {
29         URL="$1"
30         FILE="$2"
31
32         echo "Downloading $URL to \"$FILE\" ..."
33
34         curl --version >/dev/null 2>&1
35         if [ $? -eq 0 ]; then
36                 curl -#o "$FILE" "$URL" && return 0
37                 echo "Failed to download $URL! [curl]"
38                 return 1
39         fi
40
41         wget --version >/dev/null 2>&1
42         if [ $? -eq 0 ]; then
43                 wget -qO "$FILE" --show-progress "$URL" && return 0
44                 echo "Failed to download $URL! [wget]"
45                 return 1
46         fi
47
48         echo "Can't download $URL, no download tool found!"
49         return 1
50 }
51
52 LIB_D="."
53 LICENSE=""
54
55 while true; do
56         case "$1" in
57                 "-2")
58                         LICENSE="gpl2"
59                         ;;
60                 "-3")
61                         LICENSE="gpl3"
62                         ;;
63                 "-l")
64                         LICENSE="$2"
65                         shift
66                         ;;
67                 "-"*)
68                         Usage
69                         ;;
70                 *)
71                         break
72                         ;;
73         esac
74         shift
75 done
76
77 [ $# -gt 1 ] && Usage
78
79 [ -n "$1" ] && LIB_D="$1"
80
81 if [ -r "/usr/local/share/ax-make/Makefile.ax" ]; then
82         MAKEFILE_AX="/usr/local/share/ax-make/Makefile.ax"
83 elif [ -r "/usr/share/ax-make/Makefile.ax" ]; then
84         MAKEFILE_AX="/usr/share/ax-make/Makefile.ax"
85 else
86         echo "$NAME: No source \"Makefile.ax\" found!"
87         echo "$NAME: Please check your installation of \"ax-make\" and try again."
88         exit 1
89 fi
90
91 # -- Makefile.ax --
92
93 if [ ! -d "$LIB_D" ]; then
94         mkdir -pv "$LIB_D" || exit 1
95 fi
96
97 target="$LIB_D/`basename "$MAKEFILE_AX"`"
98 if [ ! -e "$target" -o "$MAKEFILE_AX" -nt "$target" ]; then
99         echo "Updating \"$target\" ..."
100         cp -v "$MAKEFILE_AX" "$target" || exit 1
101 else
102         echo "Makefile \"$target\" is up to date."
103 fi
104
105 # -- Project Makefile's ---
106
107 if [ ! -e "Makefile" ]; then
108 echo "Creating \"Makefile\" ..."
109 [ "$LIB_D" != "." ] && subdirs="$LIB_D" || subdirs=""
110 cat >"Makefile" <<EOF
111 #
112 # Makefile
113 #
114
115 SUBDIRS = $subdirs
116
117 include $LIB_D/Makefile.ax
118 EOF
119 fi
120
121 if [ "$LIB_D" != "." -a ! -e "$LIB_D/Makefile" ]; then
122 echo "Creating \"$LIB_D/Makefile\" ..."
123 cat >"$LIB_D/Makefile" <<EOF
124 #
125 # Makefile
126 #
127
128 include Makefile.ax
129 EOF
130 fi
131
132 # --- Standard project files ---
133
134 if [ ! -e AUTHORS ]; then
135         if git --version >/dev/null 2>&1; then
136                 echo "Creating \"AUTHORS\" file ..."
137                 echo "`git config user.name` <`git config user.email`>" >>AUTHORS
138         fi
139 fi
140
141 if [ ! -e COPYING ]; then
142         LICENSE_URL=""
143         case "$LICENSE" in
144                 "")
145                         ;;
146                 "gpl2")
147                         LICENSE_URL="http://www.gnu.org/licenses/gpl-2.0.txt"
148                         ;;
149                 "gpl3")
150                         LICENSE_URL="http://www.gnu.org/licenses/gpl-3.0.txt"
151                         ;;
152                 "lgpl21")
153                         LICENSE_URL="https://www.gnu.org/licenses/lgpl-2.1.txt"
154                         ;;
155                 "lgpl3")
156                         LICENSE_URL="https://www.gnu.org/licenses/lgpl-3.0.txt"
157                         ;;
158                 *)
159                         echo "Can't setup unknown \"$LICENSE\" license!"
160                         ;;
161         esac
162         [ -n "$LICENSE_URL" ] && Download "$LICENSE_URL" COPYING
163 else
164         [ -n "$LICENSE" ] && echo "COPYING file already exists, skipping."
165 fi
166
167 for f in AUTHORS COPYING README; do
168         if [ ! -e "$f" ]; then
169                 echo "Creating empty \"$f\" file ..."
170                 touch "$f"
171         fi
172 done
173
174 exit 0