aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 14b92219fbef02926e0e4111a0b31b0c0a4fd252 (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
#!/usr/bin/make -f

INSTALL_DIR=install -d -m 755
INSTALL_FILE=install -m 644
INSTALL_PROGRAM=install -m 755
INSTALL_SYMLINK=ln -s -f
COPY_SYMLINK=cp -a
COPY_DEREFERENCED=cp -RH
RM_FILE=rm -f
RM_DIR=rmdir -p --ignore-fail-on-non-empty

ETCDIR_NX   ?= /etc/nxagent
PREFIX      ?= /usr/local
BINDIR      ?= $(PREFIX)/bin
LIBDIR      ?= $(PREFIX)/lib
SHLIBDIR    ?= $(LIBDIR)
NXLIBDIR    ?= $(SHLIBDIR)/nx
USRLIBDIR   ?= $(NXLIBDIR)/X11
INCLUDEDIR  ?= $(PREFIX)/include
CONFIGURE   ?= ./configure

NX_VERSION_MAJOR=$(shell ./version.sh 1)
NX_VERSION_MINOR=$(shell ./version.sh 2)
NX_VERSION_MICRO=$(shell ./version.sh 3)
NX_VERSION_PATCH=$(shell ./version.sh 4)

SHELL:=/bin/bash

%:
	if test -f nxcomp/Makefile; then ${MAKE} -C nxcomp $@; fi
	if test -f nxproxy/Makefile; then ${MAKE} -C nxproxy $@; fi
	if test -d nx-X11; then \
	    if test -f nxcompshad/Makefile; then ${MAKE} -C nxcompshad $@; fi; \
	    if test -f nx-X11/Makefile; then ${MAKE} -C nx-X11 $@; fi; \
	fi

	# clean auto-generated nxversion.def file \
	if [ "x$@" == "xclean" ] || [ "x$@" = "xdistclean" ]; then \
	    rm -f nx-X11/config/cf/nxversion.def; \
	    rm -f bin/nxagent; \
	    rm -f bin/nxproxy; \
	fi

all: build

test:
	echo "No testing for NX (redistributed)"

build-lite:
	cd nxcomp && autoconf && (${CONFIGURE}) && ${MAKE}
	cd nxproxy && autoconf && (${CONFIGURE}) && ${MAKE}

build-full:
# in the full case, we rely on "magic" in the nx-X11 imake-based makefiles...
	cd nxcomp && autoconf && (${CONFIGURE}) && ${MAKE}

	# prepare nx-X11/config/cf/nxversion.def
	sed \
	    -e 's/###NX_VERSION_MAJOR###/$(NX_VERSION_MAJOR)/' \
	    -e 's/###NX_VERSION_MINOR###/$(NX_VERSION_MINOR)/' \
	    -e 's/###NX_VERSION_MICRO###/$(NX_VERSION_MICRO)/' \
	    -e 's/###NX_VERSION_PATCH###/$(NX_VERSION_PATCH)/' \
	    nx-X11/config/cf/nxversion.def.in \
	    > nx-X11/config/cf/nxversion.def

	# prepare Makefiles and the nx-X11 symlinking magic
	cd nx-X11 && make BuildEnv

	# build libNX_X11 and libNX_Xext prior to building
	# nxcomp{ext,shad}.
	cd nx-X11/lib && make

	cd nxcompshad && autoconf && (${CONFIGURE}) && ${MAKE}

	cd nx-X11 && ${MAKE} World USRLIBDIR=$(USRLIBDIR) SHLIBDIR=$(SHLIBDIR)

	cd nxproxy && autoconf && (${CONFIGURE}) && ${MAKE}

build:
	if ! test -d nx-X11; then \
	    ${MAKE} build-lite; \
	else \
	    ${MAKE} build-full; \
	fi

install:
	$(MAKE) install-lite
	[ ! -d nx-X11 ] || $(MAKE) install-full

install-lite:
	# install nxcomp library
	$(MAKE) -C nxcomp install

	# install nxproxy wrapper script
	$(INSTALL_DIR) $(DESTDIR)$(BINDIR)
	sed -e 's|@@NXLIBDIR@@|$(NXLIBDIR)|g' bin/nxproxy.in > bin/nxproxy
	$(INSTALL_PROGRAM) bin/nxproxy $(DESTDIR)$(BINDIR)

	# FIXME: the below install logic should work via nxproxy/Makefile.in
	# overriding for now...
	$(INSTALL_DIR) $(DESTDIR)$(NXLIBDIR)/bin
	$(INSTALL_PROGRAM) nxproxy/nxproxy $(DESTDIR)$(NXLIBDIR)/bin

	$(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/man/man1/
	$(INSTALL_FILE) nxproxy/man/nxproxy.1 $(DESTDIR)$(PREFIX)/share/man/man1/
	gzip $(DESTDIR)$(PREFIX)/share/man/man1/*.1

install-full:
	# install nxagent wrapper script
	$(INSTALL_DIR) $(DESTDIR)$(BINDIR)
	sed -e 's|@@NXLIBDIR@@|$(NXLIBDIR)|g' bin/nxagent.in > bin/nxagent
	$(INSTALL_PROGRAM) bin/nxagent $(DESTDIR)$(BINDIR)

	$(MAKE) -C nxcompshad install

	$(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/pixmaps
	$(INSTALL_FILE) nx-X11/programs/Xserver/hw/nxagent/nxagent.xpm $(DESTDIR)$(PREFIX)/share/pixmaps

	$(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/nx
	$(INSTALL_FILE) nx-X11/programs/Xserver/Xext/SecurityPolicy $(DESTDIR)$(PREFIX)/share/nx

	$(INSTALL_DIR) $(DESTDIR)$(NXLIBDIR)/bin
	$(INSTALL_PROGRAM) nx-X11/programs/Xserver/nxagent $(DESTDIR)$(NXLIBDIR)/bin

	$(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/man/man1/
	$(INSTALL_FILE) nx-X11/programs/Xserver/hw/nxagent/man/nxagent.1 $(DESTDIR)$(PREFIX)/share/man/man1/
	gzip $(DESTDIR)$(PREFIX)/share/man/man1/*.1

	# create a clean nx-X11/.build-exports space
	rm -Rf nx-X11/.build-exports
	mkdir -p nx-X11/.build-exports/include
	mkdir -p nx-X11/.build-exports/lib

	# copy headers (for libnx-x11-dev)
	cp -aL nx-X11/exports/include/* nx-X11/.build-exports/include

	# copy libs (for libnx-x11), we want the targets of the links
	. replace.sh; set -x; find nx-X11/exports/lib/ | grep -F ".so" | while read libpath; do \
	    libfile=$$(basename $$libpath); \
	    libdir=$$(dirname $$libpath); \
	    link=$$(readlink $$libpath); \
	\
	    mkdir -p "$$(string_rep "$$libdir" exports .build-exports)"; \
	    cp -a "$$(string_rep "$$libpath" "$$libfile" "$$link")" "$$(string_rep "$$libdir" exports .build-exports)"; \
	done;

	$(INSTALL_DIR) $(DESTDIR)$(SHLIBDIR)
	$(COPY_SYMLINK) nx-X11/.build-exports/lib/libNX_X11.so $(DESTDIR)$(SHLIBDIR)/
	$(COPY_SYMLINK) nx-X11/.build-exports/lib/libNX_X11.so.6 $(DESTDIR)$(SHLIBDIR)/
	$(COPY_DEREFERENCED) nx-X11/.build-exports/lib/libNX_X11.so.6.2 $(DESTDIR)$(SHLIBDIR)/
	$(INSTALL_DIR) $(DESTDIR)$(USRLIBDIR)
	$(INSTALL_SYMLINK) ../../libNX_X11.so.6 $(DESTDIR)$(USRLIBDIR)/libX11.so.6
	$(INSTALL_SYMLINK) ../../libNX_X11.so.6.2 $(DESTDIR)$(USRLIBDIR)/libX11.so.6.2

	. replace.sh; set -x; find nx-X11/.build-exports/include/{nx*,GL} -type d | \
	    while read dirname; do \
	        $(INSTALL_DIR) "$$(string_rep "$$dirname" nx-X11/.build-exports/include "$(DESTDIR)$(INCLUDEDIR)/")"; \
	        $(INSTALL_FILE) $${dirname}/*.h \
	                        "$$(string_rep "$$dirname" nx-X11/.build-exports/include "$(DESTDIR)$(INCLUDEDIR)/")"/ || true; \
	    done; \

	$(INSTALL_DIR) $(DESTDIR)/$(ETCDIR_NX)
	$(INSTALL_FILE) etc/keystrokes.cfg $(DESTDIR)/$(ETCDIR_NX)/
	$(INSTALL_FILE) etc/rgb $(DESTDIR)$(ETCDIR_NX)/
	$(INSTALL_FILE) etc/nxagent.keyboard $(DESTDIR)$(ETCDIR_NX)/

	$(INSTALL_DIR) $(DESTDIR)$(PREFIX)/share/nx
	$(INSTALL_FILE) nx-X11/lib/X11/XErrorDB $(DESTDIR)$(PREFIX)/share/nx/
	$(INSTALL_FILE) nx-X11/lib/X11/Xcms.txt $(DESTDIR)$(PREFIX)/share/nx/
	$(INSTALL_SYMLINK) $(ETCDIR_NX)/rgb $(DESTDIR)$(PREFIX)/share/nx/rgb
	$(INSTALL_FILE) VERSION $(DESTDIR)$(PREFIX)/share/nx/VERSION.nxagent
	$(INSTALL_FILE) VERSION $(DESTDIR)$(PREFIX)/share/nx/VERSION.nxproxy

uninstall:
	$(MAKE) uninstall-lite
	[ ! -d nx-X11 ] || $(MAKE) uninstall-full

uninstall-lite:
	if test -f nxcomp/Makefile; then ${MAKE} -C nxcomp $@; fi

	# uninstall nproxy wrapper script
	$(RM_FILE) $(DESTDIR)$(BINDIR)/nxproxy
	# FIXME: don't use uninstall rule in nxproxy/Makefile.in, let's do
        # it on our own for now...
	$(RM_FILE) $(DESTDIR)$(NXLIBDIR)/bin/nxproxy
	$(RM_DIR) $(DESTDIR)$(NXLIBDIR)/bin/
	$(RM_FILE) $(DESTDIR)$(PREFIX)/share/man/man1/*.1
	$(RM_FILE) $(DESTDIR)$(PREFIX)/share/nx/VERSION.nxproxy
	$(RM_DIR) $(DESTDIR)$(NXLIBDIR)/share/nx/

uninstall-full:
	for f in nxagent; do \
	    $(RM_FILE) $(DESTDIR)$(BINDIR)/$$f; done

	$(RM_FILE) $(DESTDIR)$(PREFIX)/share/nx/VERSION.nxagent
	$(RM_DIR) $(DESTDIR)$(NXLIBDIR)/share/nx/

	if test -d nx-X11; then \
	    if test -f nxcompshad/Makefile; then ${MAKE} -C nxcompshad $@; fi; \
	    if test -f nx-X11/Makefile; then \
	        if test -d $(NXLIBDIR); then rm -rf $(NXLIBDIR); fi; \
	        if test -d $(INCLUDEDIR)/nx; then rm -rf $(INCLUDEDIR)/nx; fi; \
	    fi; \
	fi