summaryrefslogtreecommitdiff
path: root/Makefile
blob: e4fa573ae43e5472f842884bd1cf4ebfbccd52c5 (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
#
# nvidia-xconfig: A tool for manipulating X config files,
# specifically for use by the NVIDIA Linux graphics driver.
#
# Copyright (C) 2005 NVIDIA Corporation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the:
#
#      Free Software Foundation, Inc.
#      59 Temple Place - Suite 330
#      Boston, MA 02111-1307, USA
#
#
# Makefile
#

# default definitions; can be overwritten by users

SHELL = /bin/sh
INSTALL = install
BUILD_OS := $(shell uname)
BUILD_ARCH := $(shell uname -m)

ifndef CC
  CC = gcc
endif

ifndef HOST_CC
  HOST_CC = $(CC)
endif

CPP = cpp

ifndef CFLAGS
  CFLAGS = -g -O -Wall
endif
ifdef NV_CFLAGS
  CFLAGS += $(NV_CFLAGS)
endif

# the NVDEBUG environment variable controls whether we build debug or retail

ifeq ($(NVDEBUG),1)
  STRIP = true
  CFLAGS += -g -DDEBUG
else
  STRIP = strip
  CFLAGS += -O
endif

# default prefix
ifdef ROOT
  prefix = $(ROOT)/usr
else
  prefix = /usr/local
endif

# default echo within SunOS sh does not have -n option. Use /usr/ucb/echo instead.
# Solaris install has a different argument syntax
# Also, man pages are not gzipped on Solaris.
ifeq ($(BUILD_OS),SunOS)
ECHO=/usr/ucb/echo
define INSTALL_RULE
	$(INSTALL) -m 755 -f $(bindir) $<
	mkdir -p $(mandir)
	$(INSTALL) -m 644 -f $(mandir) $(MANPAGE)
endef
LLSCF=-lscf
else
ECHO=echo
define INSTALL_RULE
	$(INSTALL) -m 755 $< $(bindir)
	mkdir -p $(mandir)
	$(INSTALL) -m 644 $(MANPAGE) $(mandir)
	gzip -9f $(mandir)/$(MANPAGE)
endef
LLSCF=
endif

exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
mandir = $(exec_prefix)/share/man/man1

NVIDIA_XCONFIG = nvidia-xconfig
NVIDIA_XCONFIG_VERSION = 1.0

NVIDIA_XCONFIG_DISTDIR = $(NVIDIA_XCONFIG)-$(NVIDIA_XCONFIG_VERSION)

EXTRA_DIST = \
	COPYING \
	nvgetopt.h \
	nvidia-xconfig.h \
	nvidia-cfg.h \
	option_table.h \
	Makefile \
	XF86Config-parser/*.c \
	XF86Config-parser/*.h \
	XF86Config-parser/Makefile \
	nvidia-xconfig.1.m4 \
	gen-manpage-opts.c

MANPAGE = nvidia-xconfig.1

STAMP_C = g_stamp.c

SRC =	util.c			\
	nvidia-xconfig.c 	\
	make_usable.c		\
	multiple_screens.c 	\
	tree.c			\
	nvgetopt.c		\
	options.c		\
	lscf.c			\
	query_gpu_info.c        \
	extract_edids.c

ALL_SRC = $(SRC) $(STAMP_C)

OBJS = $(ALL_SRC:.c=.o)

SUBDIR = XF86Config-parser


CFLAGS += -I $(SUBDIR)
CPPFLAGS = $(CFLAGS)
LDFLAGS = -lm $(LLSCF)

ifneq ($(BUILD_OS),FreeBSD)
LDFLAGS += -ldl
endif


LIB = $(SUBDIR)/libXF86Config-parser.a

default: all

all: $(NVIDIA_XCONFIG) $(MANPAGE)

install: $(NVIDIA_XCONFIG)
	$(STRIP) $<
	$(INSTALL_RULE)

$(NVIDIA_XCONFIG): $(OBJS) $(LIB)
	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $@ $(LIB)

.PHONY: $(LIB) dist clean clobber

$(LIB):
	$(MAKE) NV_CFLAGS='$(NV_CFLAGS)' -C $(SUBDIR)

%.o: %.c
	$(CC) -c $(CFLAGS) $< -o $@

%.d: %.c
	@set -e; $(CC) -MM $(CPPFLAGS) $< \
		| sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \
		[ -s $@ ] || rm -f $@

$(STAMP_C): $(filter-out $(STAMP_C:.c=.o), $(OBJS))
	@ rm -f $@
	@ $(ECHO) -n "const char NV_ID[] = \"nvidia id: " >> $@
	@ $(ECHO) -n "$(NVIDIA_XCONFIG):  " >> $@
	@ $(ECHO) -n "version $(NVIDIA_XCONFIG_VERSION)  " >> $@
	@ $(ECHO) -n "($(shell whoami)@$(shell hostname))  " >> $@
	@ $(ECHO)    "$(shell date)\";" >> $@
	@ $(ECHO)    "const char *pNV_ID = NV_ID + 11;" >> $@

.PHONY: dist print_version clean clobber

dist: $(EXTRA_DIST)
	@ if [ -d $(NVIDIA_XCONFIG_DISTDIR) ]; then \
		chmod 755 $(NVIDIA_XCONFIG_DISTDIR); \
	fi
	@ if [ -f $(NVIDIA_XCONFIG_DISTDIR).tar.gz ]; \
		then chmod 644 $(NVIDIA_XCONFIG_DISTDIR).tar.gz; \
	fi
	rm -rf $(NVIDIA_XCONFIG_DISTDIR) $(NVIDIA_XCONFIG_DISTDIR).tar.gz
	mkdir -p $(NVIDIA_XCONFIG_DISTDIR)/$(SUBDIR)
	@ for i in $(SRC); do \
		if [ $$i ]; then \
			cp $$i $(NVIDIA_XCONFIG_DISTDIR)/$$i ; \
			chmod 644 $(NVIDIA_XCONFIG_DISTDIR)/$$i ; \
		fi ; \
	done
	@ for i in $(EXTRA_DIST); do \
		if [ $$i ]; then \
			cp $$i $(NVIDIA_XCONFIG_DISTDIR)/$$i ; \
			chmod 644 $(NVIDIA_XCONFIG_DISTDIR)/$$i ; \
		fi ; \
	done
	tar czf $(NVIDIA_XCONFIG_DISTDIR).tar.gz $(NVIDIA_XCONFIG_DISTDIR)
	rm -rf $(NVIDIA_XCONFIG_DISTDIR)

print_version:
	@ $(ECHO) $(NVIDIA_XCONFIG_VERSION)

clean clobber:
	rm -rf *.o *~ *.d $(STAMP_C) $(NVIDIA_XCONFIG) $(MANPAGE) gen-manpage-opts options.1.inc
	$(MAKE) -C $(SUBDIR) $@

### Documentation

AUTO_TEXT = ".\\\" WARNING: THIS FILE IS AUTO-GENERATED!  Edit $< instead."

doc: $(MANPAGE)

gen-manpage-opts.o: gen-manpage-opts.c
	$(HOST_CC) $(CFLAGS) -c $<

gen-manpage-opts: gen-manpage-opts.o
	$(HOST_CC) $(CFLAGS) $^ $(LDFLAGS) -o $@

-include gen-manpage-opts.d

options.1.inc: gen-manpage-opts
	./$< > $@

nvidia-xconfig.1: nvidia-xconfig.1.m4 options.1.inc
	m4 -D__HEADER__=$(AUTO_TEXT) $< > $@

###

-include $(SRC:.c=.d)