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