xref: /minix/etc/usr/Makefile (revision 83133719)
1# Makefile - installed as /usr/Makefile
2#
3# Provides simple targets to download and maintain /usr/pkgsrc and /usr/src.
4
5########################################################################
6# Entry point
7########################################################################
8all help: usage
9
10MINIX_RELEASE!=	uname -r
11
12########################################################################
13# PKGSRC
14########################################################################
15PKGSRC_REPO_DIR:= ${.CURDIR}/pkgsrc
16PKGSRC_REPO_URL:= git://git.minix3.org/pkgsrc-ng.git
17PKGSRC_BRANCH:=	${MINIX_RELEASE}
18MSG_RENAMED_BRANCH:= "\
19\n======================================================================== \
20\nWarning: \
21\n  Renaming $$$${current_name} to $$$${new_name}. \
22\n======================================================================== \
23"
24MSG_RESET_PKGSRC:= "\
25\n======================================================================== \
26\nNote: \
27\n  If problems occur you may have to rm -rf ${PKGSRC_REPO_DIR} \
28\n  and try again. \
29\n======================================================================== \
30"
31
32.if exists(${PKGSRC_REPO_DIR}/.git)
33# We can only update the repository if it *does* exist
34pkgsrc-update: git
35	# If we can fast-forward, just do it, otherwise rename current branch
36	# and checkout the official branch (also warn the user).
37	@cd ${PKGSRC_REPO_DIR} && git pull --ff-only || \
38	( current_name=$$(git rev-parse --abbrev-ref HEAD); \
39	  new_name=$${current_name}-$$(git rev-parse --short HEAD); \
40	  echo -e ${MSG_RENAMED_BRANCH}; \
41	  echo -n "Do you want to continue [Y/n]? "; \
42	  read ok; \
43	  if [ "$${ok}" = "" -o "$${ok}" = "y" -o "$${ok}" = "Y" ]; then \
44	    git branch -m $${new_name}; \
45	    git checkout -t origin/${PKGSRC_BRANCH}; \
46	  else \
47	    exit 1; \
48	  fi; \
49	)
50	@cd ${PKGSRC_REPO_DIR}/minix && sh minibootstrap.sh
51
52.if !exists(${PKGSRC_REPO_DIR}/Makefile)
53# If the .git directory is available, but not yet checked out, then
54pkgsrc-checkout: git
55	@cd ${PKGSRC_REPO_DIR} && git checkout ${PKGSRC_BRANCH}
56	@cd ${PKGSRC_REPO_DIR}/minix && sh minibootstrap.sh
57
58.endif # !exists(${PKGSRC_REPO_DIR}/Makefile)
59.else
60# We can only create the repository if it does *not* exist
61pkgsrc: git
62	@echo -e ${MSG_RESET_PKGSRC}
63	@git clone -b ${PKGSRC_BRANCH} ${PKGSRC_REPO_URL} ${PKGSRC_REPO_DIR}
64	@cd ${PKGSRC_REPO_DIR}/minix && sh minibootstrap.sh
65
66.endif # exists(${PKGSRC_REPO_DIR}/.git)
67
68########################################################################
69# MINIX SRC
70########################################################################
71SRC_REPO_DIR:= ${.CURDIR}/src
72SRC_REPO_URL:= git://git.minix3.org/minix.git
73SRC_BRANCH:= master
74MSG_WRONG_BRANCH_SRC:= "\
75\n======================================================================== \
76\nERROR: \
77\n  An unknown branch is presently checked out, please checkout \
78\n  first the following branch: ${SRC_BRANCH} \
79\n======================================================================== \
80"
81MSG_RESET_SRC:= "\
82\n======================================================================== \
83\nNote: \
84\n  If problems occur you may have to rm -rf ${SRC_REPO_DIR} \
85\n  and try again. \
86\n======================================================================== \
87"
88.if exists(${SRC_REPO_DIR}/.git)
89# We can only update the repository if it *does* exist
90src-update: git
91	@cd ${SRC_REPO_DIR} && \
92		[ "$$(git rev-parse --abbrev-ref HEAD)" = "${SRC_BRANCH}" ] || \
93		( echo -e ${MSG_WRONG_BRANCH_SRC}; exit 1 )
94	@cd ${SRC_REPO_DIR} && git pull
95
96.if !exists(${SRC_REPO_DIR}/Makefile)
97src-checkout: git
98	@cd ${SRC_REPO_DIR} && git checkout ${SRC_BRANCH}
99.endif # !exists(${SRC_REPO_DIR}/Makefile)
100.else
101# We can only create the repository if it does not exist
102src: git
103	@echo -e ${MSG_RESET_SRC}
104	@git clone ${SRC_REPO_URL} ${SRC_REPO_DIR}
105
106.endif # exists(${SRC_REPO_DIR}/.git)
107
108########################################################################
109# Support rules
110########################################################################
111git:
112	@pkgin -y update 2>&1 > /dev/null
113	@pkgin -y install git-base 2>&1 > /dev/null
114
115usage:
116	@echo "Usage: make [target]"
117	@echo ""
118	@echo " Where target is one of:"
119	@echo "    help, all, usage	 - print this help"
120	@echo ""
121
122.if exists(${SRC_REPO_DIR}/.git)
123	@echo "    make src-update	 - update the src repo from the net"
124.if !exists(${SRC_REPO_DIR}/Makefile)
125	@echo "    make src-checkout	 - initial checkout of your pre-packaged"
126	@echo "				   pkgsrc repo."
127.endif # !exists(${SRC_REPO_DIR}/Makefile)
128.else
129	@echo "    make src		 - fetch initial src repo from the net"
130.endif # exists(${SRC_REPO_DIR}/.git)
131	@echo ""
132
133.if exists(${PKGSRC_REPO_DIR}/.git)
134.if !exists(${PKGSRC_REPO_DIR}/Makefile)
135	@echo "    make pkgsrc-checkout - initial checkout of your pre-packaged"
136	@echo "				  pkgsrc repo."
137.endif # !exists(${PKGSRC_REPO_DIR}/Makefile)
138	@echo "    make pkgsrc-update	 - update your pkgsrc repo from the net"
139.else
140	@echo "    make pkgsrc		 - fetch initial pkgsrc repo from the net"
141.endif # exists(${PKGSRC_REPO_DIR}/.git)
142	@echo ""
143
144_debug:
145	@echo "Settings:"
146.for var in MINIX_RELEASE \
147	SRC_REPO_DIR SRC_REPO_URL SRC_BRANCH \
148	PKGSRC_REPO_DIR PKGSRC_REPO_URL PKGSRC_BRANCH
149	@echo "  ${var} = ${${var}}"
150
151.endfor
152
153