summaryrefslogtreecommitdiffstats
path: root/macosx/Makefile
blob: 5393a04de2cf007bf71360eb21533054ee313f06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
########################################################################################################
#
# Makefile wrapper to build tk on Mac OS X in a way compatible with the tk/macosx Xcode buildsystem
#	uses the standard unix build system in tk/unix (which can be used directly instead of this
#	if you are not using the tk/macosx projects).
#
# RCS: @(#) $Id: Makefile,v 1.7.2.15 2006/09/10 17:07:36 das Exp $
#
########################################################################################################

#-------------------------------------------------------------------------------------------------------
# customizable settings

DESTDIR			?=
INSTALL_ROOT		?= ${DESTDIR}

BUILD_DIR		?= ${CURDIR}/../../build
SYMROOT			?= ${BUILD_DIR}/${PROJECT}
OBJROOT			?= ${SYMROOT}

EXTRA_CONFIGURE_ARGS 	?= 
EXTRA_MAKE_ARGS		?= 

INSTALL_PATH		?= /Library/Frameworks
APPLICATION_INSTALL_PATH ?= /Applications/Utilities
PREFIX			?= /usr/local
BINDIR			?= ${PREFIX}/bin
LIBDIR			?= ${INSTALL_PATH}
MANDIR			?= ${PREFIX}/man

# tcl build directory (containing tclConfig.sh and Makefile)
TCL_BUILD_DIR		?= ${BUILD_DIR}/tcl/${BUILD_STYLE}
# location of installed tcl, only used if tcl in TCL_BUILD_DIR can't be found
TCL_FRAMEWORK_DIR	?= /Library/Frameworks
TCLSH_DIR		?= ${PREFIX}

# set to non-empty value to install manpages in addition to html help:
INSTALL_MANPAGES 	?= 

# set to non-empty value to build TkX11 instead of TkAqua:
TK_X11			?=

#-------------------------------------------------------------------------------------------------------
# meta targets

meta 			:= all install embedded install-embedded clean distclean test

styles			:= develop deploy

all			:= ${styles}
all			: ${all}

install			:= ${styles:%=install-%}
install			: ${install}
install-%:		action := install-

embedded		:= ${styles:%=embedded-%}
embedded		: embedded-deploy
install-embedded	:= ${embedded:%=install-%}
install-embedded	: install-embedded-deploy

clean			:= ${styles:%=clean-%}
clean			: ${clean}
clean-%:		action := clean-
distclean		:= ${styles:%=distclean-%}
distclean		: ${distclean}
distclean-%:		action := distclean-

test			:= ${styles:%=test-%}
test			: ${test}
test-%:			action := test-

targets			:= $(foreach v,${meta},${$v})

#-------------------------------------------------------------------------------------------------------
# build styles

BUILD_STYLE		=
CONFIGURE_ARGS		=
OBJ_DIR			= ${OBJROOT}/${BUILD_STYLE}

develop_make_args	:= BUILD_STYLE=Development CONFIGURE_ARGS=--enable-symbols
deploy_make_args	:= BUILD_STYLE=Deployment INSTALL_TARGET=install-strip
embedded_make_args	:= EMBEDDED_BUILD=1
install_make_args	:= INSTALL_BUILD=1

${targets}: 
	${MAKE} ${action}${PROJECT} \
	$(foreach s,${styles} embedded install,$(if $(findstring $s,$@),${${s}_make_args}))

#-------------------------------------------------------------------------------------------------------
# project specific settings

PROJECT			:= tk
PRODUCT_NAME		:= Tk

UNIX_DIR		:= ${CURDIR}/../unix
VERSION			:= $(shell awk -F= '/^TK_VERSION/ {print $$2; nextfile}' ${UNIX_DIR}/configure.in)
TCL_VERSION		:= ${VERSION}
wish			:= wish
WISH			= wish${VERSION}

BUILD_TARGET		:= all tktest
INSTALL_TARGET		:= install

ifneq ($(wildcard ${TCL_BUILD_DIR}/tclConfig.sh),)
TCL_DIR			:= ${TCL_BUILD_DIR}
TCL_FRAMEWORK_DIR	:= ${TCL_BUILD_DIR}/..
else
TCL_DIR			:= ${TCL_FRAMEWORK_DIR}/Tcl.framework
TCL_EXE                 := ${TCLSH_DIR}/tclsh${TCL_VERSION}
MAKE_VARS		= TCL_EXE
export DYLD_FRAMEWORK_PATH := ${TCL_FRAMEWORK_DIR}
endif
export CPPROG		:= cp -p

ifeq (${TK_X11},)
override CONFIGURE_ARGS := ${CONFIGURE_ARGS} --enable-aqua
else
VERSION			:= ${VERSION}-X11
wish			:= ${wish}-X11
endif

INSTALL_TARGETS		= install-binaries install-libraries
ifeq (${EMBEDDED_BUILD},)
INSTALL_TARGETS		+= install-private-headers install-demos
endif
ifeq (${INSTALL_BUILD}_${EMBEDDED_BUILD}_${BUILD_STYLE},1__Deployment)
INSTALL_TARGETS		+= html-tk
ifneq (${INSTALL_MANPAGES},)
INSTALL_TARGETS		+= install-doc
endif
endif

MAKE_VARS		+= INSTALL_ROOT INSTALL_TARGETS VERSION
MAKE_ARGS_V		= $(foreach v,${MAKE_VARS},$v='${$v}')

build-${PROJECT}:	target = ${BUILD_TARGET}
install-${PROJECT}:	target = ${INSTALL_TARGET}
clean-${PROJECT} distclean-${PROJECT} test-${PROJECT}: \
			target = $*

DO_MAKE			= +${MAKE} -C ${OBJ_DIR} ${target} ${MAKE_ARGS_V} ${MAKE_ARGS} ${EXTRA_MAKE_ARGS}

#-------------------------------------------------------------------------------------------------------
# locations for custom tk install actions

ifeq (${INSTALL_BUILD},1)
TOP_DIR			:= ${INSTALL_ROOT}/
APP_DIR			:= ${APPLICATION_INSTALL_PATH}
FMWK_DIR		:= ${LIBDIR}
else
TOP_DIR			:= ${SYMROOT}
APP_DIR			:= .
FMWK_DIR		:= .
endif

TCL_FMWK_DIR		:= ${FMWK_DIR}/Tcl.framework/Versions/${TCL_VERSION}
TK_FMWK_DIR		:= ${FMWK_DIR}/${PRODUCT_NAME}.framework/Versions/${VERSION}

#-------------------------------------------------------------------------------------------------------
# build rules

${PROJECT}:
	${MAKE} install-${PROJECT} INSTALL_ROOT=${OBJ_DIR}/

${OBJ_DIR}/Makefile: ${UNIX_DIR}/Makefile.in ${UNIX_DIR}/configure \
                     ${UNIX_DIR}/tkConfig.sh.in Tk-Info.plist.in Wish-Info.plist.in
	mkdir -p ${OBJ_DIR} && cd ${OBJ_DIR} && \
	if [ ${UNIX_DIR}/configure -nt config.status ]; then ${UNIX_DIR}/configure \
	--prefix=${PREFIX} --bindir=${BINDIR} --libdir=${LIBDIR} \
	--mandir=${MANDIR} --enable-threads --enable-framework \
	--with-tcl=${TCL_DIR} \
	${CONFIGURE_ARGS} ${EXTRA_CONFIGURE_ARGS}; else ./config.status; fi
ifneq (${TK_X11},)
	@cd ${OBJ_DIR} && sed -e 's#/Versions/${TCL_VERSION}#/Versions/${VERSION}#' \
	tkConfig.sh > tkConfig.sh.1 && mv -f tkConfig.sh.1 tkConfig.sh
endif

build-${PROJECT}: ${OBJ_DIR}/Makefile
	${DO_MAKE}
ifeq (${INSTALL_BUILD},)
# symolic link hackery to trick
# 'make install INSTALL_ROOT=${OBJ_DIR}'
# into building Tk.framework and wish in ${SYMROOT}
	@cd ${OBJ_DIR} && mkdir -p $(dir ./${LIBDIR}) $(dir ./${BINDIR}) ${SYMROOT} && \
	rm -rf ./${LIBDIR} ./${BINDIR} && ln -fs ${SYMROOT} ./${LIBDIR} && \
	ln -fs ${SYMROOT} ./${BINDIR} && ln -fs ${OBJ_DIR}/tktest ${SYMROOT}
ifeq (${TK_X11},)
	@rm -f ${OBJ_DIR}/${BINDIR} && \
	ln -fs Wish.app/Contents/MacOS/Wish ${SYMROOT}/${WISH}
endif
# Create symbolic link to Tcl.framework in ${SYMROOT}if necessary
	@cd ${SYMROOT} && if [ ! -e Tcl.framework -o -L Tcl.framework ]; then \
	rm -f Tcl.framework && ln -s ${TCL_FRAMEWORK_DIR}/Tcl.framework . ; fi
endif

install-${PROJECT}: build-${PROJECT}
ifeq (${EMBEDDED_BUILD}_${INSTALL_ROOT},1_)
	@echo "Cannot install-embedded with empty INSTALL_ROOT !" && false
endif
ifeq (${EMBEDDED_BUILD},1)
	@rm -rf "${INSTALL_ROOT}/${LIBDIR}/Tk.framework"
endif
	${DO_MAKE}
ifeq (${EMBEDDED_BUILD}_${TK_X11},1_)
# workaround bug with 'cp -pRH' on Darwin 6 and earlier
	@if [ "`uname -r | awk -F. '{print $$1}'`" -lt 7 ]; then \
	mkdir -p ${TOP_DIR}/{"${TCL_FMWK_DIR}","${TK_FMWK_DIR}"}/PrivateHeaders; fi
endif
ifeq (${INSTALL_BUILD},1)
ifeq (${EMBEDDED_BUILD},1)
# if we are embedding frameworks, don't install wish
	@rm -f "${INSTALL_ROOT}${BINDIR}/${WISH}" && \
	rmdir -p "${INSTALL_ROOT}${BINDIR}" 2>&- || true
else
# redo prebinding
	@cd ${INSTALL_ROOT}/ && \
	if [ ! -d usr/lib ]; then mkdir -p usr && ln -fs /usr/lib usr/ && RM_USRLIB=1; fi; \
	if [ -n "${TK_X11}" -a ! -d usr/X11R6 ]; then mkdir -p usr && ln -fs /usr/X11R6 usr/ && RM_USRX11=1; fi; \
	if [ ! -d System ]; then ln -fs /System . && RM_SYSTEM=1; fi; \
	if [ ! -d ./${LIBDIR}/Tcl.framework ]; then ln -fs ${TCL_FRAMEWORK_DIR}/Tcl.framework ./${LIBDIR}; RM_TCL=1; fi; \
	redo_prebinding -r . "./${TK_FMWK_DIR}/${PRODUCT_NAME}"; \
	if [ -z "${TK_X11}" ]; then redo_prebinding -r . "./${TK_FMWK_DIR}/Resources/Wish.app/Contents/MacOS/Wish"; \
	else redo_prebinding -r . "./${BINDIR}/${WISH}"; fi; \
	if [ -n "$${RM_USRLIB:-}" ]; then rm -f usr/lib; rmdir -p usr 2>&-; fi; \
	if [ -n "$${RM_USRX11:-}" ]; then rm -f usr/X11R6; rmdir -p usr 2>&-; fi; \
	if [ -n "$${RM_SYSTEM:-}" ]; then rm -f System; fi; \
	if [ -n "$${RM_TCL:-}" ]; then rm -f ./${LIBDIR}/Tcl.framework; fi
# install wish symbolic link
	@ln -fs ${WISH} ${INSTALL_ROOT}${BINDIR}/${wish}
endif
endif
ifeq (${BUILD_STYLE}_${EMBEDDED_BUILD},Development_)
# keep copy of debug library around, so that
# Deployment build can be installed on top
# of Development build without overwriting
# the debug library
	@cd ${INSTALL_ROOT}${LIBDIR}/${PRODUCT_NAME}.framework/Versions/${VERSION} && \
	ln -f "${PRODUCT_NAME}" "${PRODUCT_NAME}_debug"
endif
ifeq (${TK_X11},)
ifeq (${EMBEDDED_BUILD},)
# install Wish.app link in APPLICATION_INSTALL_PATH and setup 'Wish Shell' compatibility links
	@cd ${TOP_DIR} && if [ -n "${APP_DIR}" ]; then mkdir -p "./${APP_DIR}" && rm -rf "./${APP_DIR}/Wish.app" && \
	ln -fsh "./$$(echo ${APP_DIR} | sed -e 's#/[^/][^/]*#/..#g')/${FMWK_DIR}/${PRODUCT_NAME}.framework/Resources/Wish.app" "./${APP_DIR}" && \
	ln -fsh Wish.app "./${APP_DIR}/Wish Shell.app"; fi && \
	ln -fsh Wish.app "./${TK_FMWK_DIR}/Resources/Wish Shell.app" && \
	ln -fsh Wish "./${TK_FMWK_DIR}/Resources/Wish.app/Contents/MacOS/Wish Shell"
else
# if we are embedding frameworks, move them into the app and fix their install names
	@cd ${TOP_DIR} && \
	rm -rf "./${APP_DIR}/Wish.app" && mkdir -p "./${APP_DIR}" && \
	mv -f "./${TK_FMWK_DIR}/Resources/Wish.app" "./${APP_DIR}" && \
	ln -fsh Wish.app "./${APP_DIR}/Wish Shell.app" && \
	rm -rf "./${APP_DIR}/Wish.app/Contents/Frameworks" && \
	mkdir -p "./${APP_DIR}/Wish.app/Contents/Frameworks" && \
	${CPPROG} -RH "./${FMWK_DIR}"/T{cl,k}.framework "./${APP_DIR}/Wish.app/Contents/Frameworks" && \
	cd "./${APP_DIR}/Wish.app/Contents" && \
	rm -rf Frameworks/Tcl.framework/{,/Versions/$(TCL_VERSION)}/{Headers,PrivateHeaders,*_debug,lib*.a,*Config.sh} && \
	rm -rf Frameworks/Tk.framework/{,/Versions/$(VERSION)}/{Headers,PrivateHeaders,*_debug,lib*.a,*Config.sh} && \
	fix_install_id ( ) { \
	    chmod -RH a+w "$$1"; \
	    install_name_tool -id $$(otool -L "$$1" | awk "/$$2\.framework.*[^:]\$$/ {sub(\"^.*/Frameworks\",\"@executable_path/../Frameworks\",\$$1); print \$$1}") "$$1"; \
	    chmod -RH a-w "$$1"; \
	} && \
	fix_install_name ( ) { \
	    chmod -RH a+w "$$1"; \
	    install_name_tool -change $$(otool -L "$$1" | awk "/$$2\.framework.*[^:]\$$/ {print \$$1; sub(\"^.*/Frameworks\",\"@executable_path/../Frameworks\",\$$1); print \$$1}") "$$1"; \
	    chmod -RH a-w "$$1"; \
	} && \
	fix_install_id Frameworks/Tcl.framework/Tcl Tcl && fix_install_id Frameworks/Tk.framework/Tk Tk && \
	fix_install_name MacOS/Wish Tcl && fix_install_name MacOS/Wish Tk
ifeq (${INSTALL_BUILD},1)
	@cd ${TOP_DIR} && rm -rf "./${FMWK_DIR}"/T{cl,k}.framework && rmdir -p "./${FMWK_DIR}" 2>&- || true
endif
endif
endif

clean-${PROJECT}: %-${PROJECT}:
	${DO_MAKE}
	rm -rf ${SYMROOT}/{${PRODUCT_NAME}.framework,${WISH},tktest}
	rm -f ${OBJ_DIR}{${LIBDIR},${BINDIR}} && \
	rmdir -p ${OBJ_DIR}$(dir ${LIBDIR}) 2>&- || true && \
	rmdir -p ${OBJ_DIR}$(dir ${BINDIR}) 2>&- || true

distclean-${PROJECT}: %-${PROJECT}: clean-${PROJECT}
	${DO_MAKE}
	rm -rf ${OBJ_DIR}
	
test-${PROJECT}: %-${PROJECT}: build-${PROJECT}
	${DO_MAKE}

#-------------------------------------------------------------------------------------------------------

.PHONY: ${meta} ${targets} ${PROJECT} build-${PROJECT} install-${PROJECT} \
	clean-${PROJECT} distclean-${PROJECT}

.NOTPARALLEL:

#-------------------------------------------------------------------------------------------------------