3 # ax-make: Alex' Simple Makefile System
4 # Copyright (c)2014-2022 Alexander Barton (alex@barton.de)
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.
15 echo "Usage: $NAME [-2|-3|-l <lic>] [<lib-dir>]"
17 echo " -0 Don't create AUTHORS, COPYING and README files."
18 echo ' -2 Use the GNU GPLv2 for the COPYING file.'
19 echo ' -3 Use the GNU GPLv3 for the COPYING file.'
20 echo ' -l <lic> Specify license to use for the COPYING file:'
21 echo ' <lic> can be "gpl2", "gpl3", "lgpl21", "lgpl3".'
22 echo ' By default an empty COPYING file is created.'
23 echo ' -m Use Markdown, create AUTHORS.md and README.md.'
25 echo " <lib-dir> Library directory. Default: current working directory."
34 echo "Downloading $URL to \"$FILE\" ..."
36 if curl --version >/dev/null 2>&1; then
37 curl -#o "$FILE" "$URL" && return 0
38 echo "Failed to download $URL! [curl]"
42 if wget --version >/dev/null 2>&1; then
43 wget -qO "$FILE" --show-progress "$URL" && return 0
44 echo "Failed to download $URL! [wget]"
48 echo "Can't download $URL, no download tool found!"
87 [ -n "$1" ] && LIB_D="$1"
89 if [ -r "/usr/local/share/ax-make/Makefile.ax" ]; then
90 MAKEFILE_AX="/usr/local/share/ax-make/Makefile.ax"
91 elif [ -r "/usr/share/ax-make/Makefile.ax" ]; then
92 MAKEFILE_AX="/usr/share/ax-make/Makefile.ax"
94 echo "$NAME: No source \"Makefile.ax\" found!"
95 echo "$NAME: Please check your installation of \"ax-make\" and try again."
101 if [ ! -d "$LIB_D" ]; then
102 mkdir -pv "$LIB_D" || exit 1
105 target="$LIB_D/$(basename "$MAKEFILE_AX")"
106 if [ ! -e "$target" ] || [ "$MAKEFILE_AX" -nt "$target" ]; then
107 echo "Updating \"$target\" ..."
108 cp -v "$MAKEFILE_AX" "$target" || exit 1
110 echo "Makefile \"$target\" is up to date."
113 # -- Project Makefile's ---
115 if [ ! -e "Makefile" ]; then
116 echo "Creating \"Makefile\" ..."
117 [ "$LIB_D" != "." ] && subdirs="$LIB_D" || subdirs=""
118 cat >"Makefile" <<EOF
123 SOURCE_ROOT ?= \$(CURDIR)
127 include $LIB_D/Makefile.ax
131 if [ "$LIB_D" != "." ] && [ ! -e "$LIB_D/Makefile" ]; then
132 echo "Creating \"$LIB_D/Makefile\" ..."
133 cat >"$LIB_D/Makefile" <<EOF
138 SOURCE_ROOT ?= \$(CURDIR)/..
144 # --- Standard project files ---
146 if [[ ! -e AUTHORS && -n "$ADD_FILES" ]]; then
147 if git --version >/dev/null 2>&1; then
148 echo "Creating \"AUTHORS$SUFFIX\" file ..."
149 echo "$(git config user.name) <$(git config user.email)>" >>"AUTHORS$SUFFIX"
153 if [ ! -e COPYING ]; then
159 LICENSE_URL="http://www.gnu.org/licenses/gpl-2.0.txt"
162 LICENSE_URL="http://www.gnu.org/licenses/gpl-3.0.txt"
165 LICENSE_URL="https://www.gnu.org/licenses/lgpl-2.1.txt"
168 LICENSE_URL="https://www.gnu.org/licenses/lgpl-3.0.txt"
171 echo "Can't setup unknown \"$LICENSE\" license!"
174 [ -n "$LICENSE_URL" ] && Download "$LICENSE_URL" COPYING
176 [ -n "$LICENSE" ] && echo "COPYING file already exists, skipping."
181 if [[ -n "$ADD_FILES" ]]; then
183 files+=("AUTHORS$SUFFIX" "README$SUFFIX")
186 for f in "${files[@]}"; do
187 if [ ! -e "$f" ]; then
188 echo "Creating empty \"$f\" file ..."