1#!/bin/sh
2# Helper script which will create the port / distfiles
3# from a checked out git repo
4
5# Set the port
6port="audio/pc-mixer"
7dfile="pc-mixer"
8
9massage_subdir() {
10  cd "$1"
11  if [ $? -ne 0 ] ; then
12     echo "SKIPPING $i"
13     continue
14  fi
15
16comment="`cat Makefile | grep 'COMMENT ='`"
17
18  echo "# \$FreeBSD\$
19#
20
21$comment
22" > Makefile.tmp
23
24  for d in `ls`
25  do
26    if [ "$d" = ".." ]; then continue ; fi
27    if [ "$d" = "." ]; then continue ; fi
28    if [ "$d" = "Makefile" ]; then continue ; fi
29    if [ ! -f "$d/Makefile" ]; then continue ; fi
30    echo "    SUBDIR += $d" >> Makefile.tmp
31  done
32  echo "" >> Makefile.tmp
33  echo ".include <bsd.port.subdir.mk>" >> Makefile.tmp
34  mv Makefile.tmp Makefile
35
36}
37
38if [ -z "$1" ] ; then
39   echo "Usage: ./mkports.sh <portstree> <distfiles>"
40   exit 1
41fi
42
43if [ ! -d "${1}/Mk" ] ; then
44   echo "Invalid directory: $1"
45   exit 1
46fi
47
48portsdir="${1}"
49if [ -z "$portsdir" -o "${portsdir}" = "/" ] ; then
50  portsdir="/usr/ports"
51fi
52
53if [ -z "$2" ] ; then
54  distdir="${portsdir}/distfiles"
55else
56  distdir="${2}"
57fi
58if [ ! -d "$distdir" ] ; then
59  mkdir -p ${distdir}
60fi
61
62echo "Sanity checking the repo..."
63OBJS=`find . | grep '\.o$'`
64if [ -n "$OBJS" ] ; then
65   echo "Found the following .o files, remove them first!"
66   echo $OBJS
67   exit 1
68fi
69
70# Get the GIT tag
71ghtag=`git log -n 1 . | grep '^commit ' | awk '{print $2}'`
72
73# Get the version
74if [ -e "version" ] ; then
75  verTag=$(cat version)
76else
77  verTag=$(date '+%Y%m%d')
78fi
79
80# Cleanup old distfiles
81rm ${distdir}/${dfile}-* 2>/dev/null
82
83# Copy ports files
84if [ -d "${portsdir}/${port}" ] ; then
85  rm -rf ${portsdir}/${port} 2>/dev/null
86fi
87cp -r port-files ${portsdir}/${port}
88
89# Set the version numbers
90sed -i '' "s|%%CHGVERSION%%|${verTag}|g" ${portsdir}/${port}/Makefile
91sed -i '' "s|%%GHTAG%%|${ghtag}|g" ${portsdir}/${port}/Makefile
92
93# Create the makesums / distinfo file
94cd "${portsdir}/${port}"
95make makesum
96if [ $? -ne 0 ] ; then
97  echo "Failed makesum"
98  exit 1
99fi
100
101# Update port cat Makefile
102tcat=$(echo $port | cut -d '/' -f 1)
103massage_subdir ${portsdir}/${tcat}
104