]> arthur.barton.de Git - ax-make.git/blob - scripts/axify
axify: Abort when mkdir(1) failed
[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 [ -n "$1" ] && LIB_D="$1" || LIB_D="."
15
16 if [ -r "/usr/local/share/ax-make/Makefile.ax" ]; then
17         MAKEFILE_AX="/usr/local/share/ax-make/Makefile.ax"
18 elif [ -r "/usr/share/ax-make/Makefile.ax" ]; then
19         MAKEFILE_AX="/usr/share/ax-make/Makefile.ax"
20 else
21         echo "$NAME: No source \"Makefile.ax\" found!"
22         echo "$NAME: Please check your installation of \"ax-make\" and try again."
23         exit 1
24 fi
25
26 # -- Makefile.ax --
27
28 if [ ! -d "$LIB_D" ]; then
29         mkdir -pv "$LIB_D" || exit 1
30 fi
31
32 target="$LIB_D/`basename "$MAKEFILE_AX"`"
33 if [ ! -e "$target" -o "$MAKEFILE_AX" -nt "$target" ]; then
34         echo "Updating \"$target\" ..."
35         cp -v "$MAKEFILE_AX" "$target" || exit 1
36 else
37         echo "Makefile \"$target\" is up to date."
38 fi
39
40 # -- Project Makefile's ---
41
42 if [ ! -e "Makefile" ]; then
43 echo "Creating \"Makefile\" ..."
44 [ "$LIB_D" != "." ] && subdirs="$LIB_D" || subdirs=""
45 cat >"Makefile" <<EOF
46 #
47 # Makefile
48 #
49
50 SUBDIRS = $subdirs
51
52 include $LIB_D/Makefile.ax
53 EOF
54 fi
55
56 if [ "$LIB_D" != "." -a ! -e "$LIB_D/Makefile" ]; then
57 echo "Creating \"$LIB_D/Makefile\" ..."
58 cat >"$LIB_D/Makefile" <<EOF
59 #
60 # Makefile
61 #
62
63 include Makefile.ax
64 EOF
65 fi
66
67 # --- Standard project files ---
68
69 authors=AUTHORS
70 if [ ! -e AUTHORS ]; then
71         if git --version >/dev/null 2>&1; then
72                 echo "Creating \"AUTHORS\" file ..."
73                 echo "`git config user.name` <`git config user.email`>" >>AUTHORS
74                 authors=
75         fi
76 fi
77
78 for f in $authors COPYING README; do
79         if [ ! -e "$f" ]; then
80                 echo "Creating empty \"$f\" file ..."
81                 touch "$f"
82         fi
83 done
84
85 exit 0