2 # shellcheck disable=SC2250
4 # ax-make: Alex' Simple Makefile System
5 # Copyright (c)2014-2023 Alexander Barton (alex@barton.de)
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
16 echo "Usage: $NAME [-2|-3|-l <lic>] [<lib-dir>]"
18 echo " -0 Don't create AUTHORS, COPYING and README files."
19 echo ' -2 Use the GNU GPLv2 for the COPYING file.'
20 echo ' -3 Use the GNU GPLv3 for the COPYING file.'
21 echo ' -l <lic> Specify license to use for the COPYING file:'
22 echo ' <lic> can be "gpl2", "gpl3", "lgpl21", "lgpl3".'
23 echo ' By default an empty COPYING file is created.'
24 echo ' -m Use Markdown, create AUTHORS.md and README.md.'
26 echo " <lib-dir> Library directory. Default: current working directory."
35 echo "Downloading $URL to \"$FILE\" ..."
37 if curl --version >/dev/null 2>&1; then
38 curl -#Lo "$FILE" "$URL" && return 0
39 echo "Failed to download $URL! [curl]"
43 if wget --version >/dev/null 2>&1; then
44 wget -qO "$FILE" --show-progress "$URL" && return 0
45 echo "Failed to download $URL! [wget]"
49 echo "Can't download $URL, no download tool found!"
86 [[ $# -gt 1 ]] && Usage
88 [[ -n "$1" ]] && LIB_D="$1"
90 if [[ -r "/usr/local/share/ax-make/Makefile.ax" ]]; then
91 MAKEFILE_AX="/usr/local/share/ax-make/Makefile.ax"
92 elif [[ -r "/usr/share/ax-make/Makefile.ax" ]]; then
93 MAKEFILE_AX="/usr/share/ax-make/Makefile.ax"
95 echo "$NAME: No source \"Makefile.ax\" found!"
96 echo "$NAME: Please check your installation of \"ax-make\" and try again."
102 if [[ ! -d "$LIB_D" ]]; then
103 mkdir -pv "$LIB_D" || exit 1
106 target="$LIB_D/$(basename "$MAKEFILE_AX")"
107 if [[ ! -e "$target" || "$MAKEFILE_AX" -nt "$target" ]]; then
108 echo "Updating \"$target\" ..."
109 cp -v "$MAKEFILE_AX" "$target" || exit 1
111 echo "Makefile \"$target\" is up to date."
114 # -- Project Makefile's ---
116 if [[ ! -e "Makefile" ]]; then
117 echo "Creating \"Makefile\" ..."
118 [[ "$LIB_D" != "." ]] && subdirs="$LIB_D" || subdirs=""
119 cat >"Makefile" <<EOF
124 SOURCE_ROOT ?= \$(CURDIR)
128 include $LIB_D/Makefile.ax
132 if [[ "$LIB_D" != "." && ! -e "$LIB_D/Makefile" ]]; then
133 echo "Creating \"$LIB_D/Makefile\" ..."
134 cat >"$LIB_D/Makefile" <<EOF
139 SOURCE_ROOT ?= \$(CURDIR)/..
145 # --- Standard project files ---
147 if [[ ! -e "AUTHORS$SUFFIX" && -n "$ADD_FILES" ]]; then
148 if git --version >/dev/null 2>&1; then
149 echo "Creating \"AUTHORS$SUFFIX\" file ..."
150 echo "$(git config user.name) <$(git config user.email)>" >>"AUTHORS$SUFFIX"
154 if [[ ! -e COPYING ]]; then
160 LICENSE_URL="https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt"
163 LICENSE_URL="https://www.gnu.org/licenses/gpl-3.0.txt"
166 LICENSE_URL="https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt"
169 LICENSE_URL="https://www.gnu.org/licenses/lgpl-3.0.txt"
172 echo "Can't setup unknown \"$LICENSE\" license!"
175 [[ -n "$LICENSE_URL" ]] && Download "$LICENSE_URL" COPYING
177 [[ -n "$LICENSE" ]] && echo "COPYING file already exists, skipping."
182 if [[ -n "$ADD_FILES" ]]; then
184 files+=("AUTHORS$SUFFIX" "README$SUFFIX")
187 for f in "${files[@]}"; do
188 if [[ ! -e "$f" ]]; then
189 echo "Creating empty \"$f\" file ..."