1#
2# APRSC
3#
4
5# -------------------------------------------------------------------- #
6# target paths
7
8VARRUN=		/opt/aprsc/logs	# directory for aprsc.state and pid-file
9VARLOG=		/opt/aprsc/logs	# directory for direct logfiles
10SBINDIR=	@sbindir@	# installation path for programs
11MANDIR=		@mandir@	# installation path for manual pages
12
13# generate version strings
14VERSION:=$(shell cat VERSION)
15GIT_CMD:=$(shell which git)
16GITVERSION:=$(shell if test -x $(GIT_CMD) -a \( -d .git -o -d ../.git \) ; then \
17		($(GIT_CMD) describe --long --dirty=M || $(GIT_CMD) describe --long)| sed -e 's/^.*-//' | tee GITVERSION; \
18	else \
19		(if test -f GITVERSION; then \
20			cat GITVERSION; \
21		else \
22			(pwd | sed -e 's/.*-//' | sed -e 's/\/.*//' | egrep '^[a-f0-9]+$$' | tee GITVERSION ) \
23		fi); \
24	fi)
25SRCVERSION:=$(GITVERSION)
26DATE:=$(shell TZ=UTC date +"%Y %B %d")
27RFCDATE:=$(shell TZ=UTC date +"%a, %d %b %Y %H:%M:%S %z")
28BUILD_TIME:=$(shell TZ=UTC date +"%Y-%m-%d %H:%M:%S %z")
29LINUXCODENAME:=$(shell lsb_release -sc 2>/dev/null || true)
30BUILD_USER:=$(shell whoami)
31
32# -------------------------------------------------------------------- #
33
34# strip extra whitespace from paths
35VARRUN:=$(strip $(VARRUN))
36VARLOG:=$(strip $(VARLOG))
37CFGFILE:=$(strip $(CFGFILE))
38SBINDIR:=$(strip $(SBINDIR))
39MANDIR:=$(strip $(MANDIR))
40
41srcdir = @srcdir@
42VPATH = @srcdir@
43@SET_MAKE@
44
45# Compiler and flags
46CC=		@CC@
47PROF=
48CFLAGS=		@CFLAGS@ @CPPFLAGS@ @CFLAGS_ARCH@ $(PROF) $(DEFS)
49
50# On solaris, should use -D_REENTRANT  CFLAGS
51
52# Linker and flags
53LD=		@LD@
54LDFLAGS=	@LDFLAGS@ $(PROF)
55
56INSTALL=	$(srcdir)/install-sh
57INSTALL_PROGRAM=$(INSTALL)  -m 755
58INSTALL_DATA=	$(INSTALL)  -m 644
59INSTALL_DIR=$(INSTALL)  -m 755 -d
60
61LIBS=		@LIBEVENT@ @LIBM@ @LIBRT@ @LIBPTHREAD@ @LIBSOCKET@ @LIBGETNAMEINFO@ @LIBCAP@ @LIBZ@ @LIBCRYPTO@ @LIBSSL@
62
63#LIBS += -L/data/www/mapt1/extsrc/libevent-2.0.14-stable/installed/usr/local/lib
64#CFLAGS += -I/data/www/mapt1/extsrc/libevent-2.0.14-stable/installed/usr/local/include
65
66
67# Linux:
68# -lpthread
69# Solaris 2.8:
70# -lpthread -lxnet -lsocket -lnss -lrt
71# Solaris 2.6:
72# -lpthread -lxnet -lsocket -lnsl -lposix4 -lresolv
73
74# -------------------------------------------------------------------- #
75
76DEFS=	-Wall -Wstrict-prototypes -D_REENTRANT
77
78
79# -------------------------------------------------------------------- #
80
81.PHONY: 	all clean distclean valgrind profile
82
83all: aprsc aprsc.8
84
85
86### "valgrind" is not for running the valgrind, rather for compiling
87### the software so that internal cellmalloc et.al. are disabled.
88
89valgrind:
90	@echo "Did you do 'make clean' before 'make valgrind' ?"
91	make all CFLAGS="${CFLAGS} -D_FOR_VALGRIND_"
92
93profile:
94	@echo "Did you do 'make clean' before 'make profile' ?"
95	make all PROF=-pg
96
97
98# -------------------------------------------------------------------- #
99
100DATAMODE = 0644
101DATAINSTALL = install --preserve-timestamps -m $(DATAMODE)
102
103WEBFILES = \
104	src/web/aprsc.css src/web/aprsc.js src/web/aprsc-graph.js \
105	src/web/strings-en.json \
106	src/web/strings-fi.json \
107	src/web/index.html \
108	src/web/favicon.ico \
109	src/web/aprsc-logo4.png \
110	src/web/aprsc-logo4@2x.png \
111	src/web/aprsc-joulukissa.jpg \
112 	src/web/excanvas.min.js \
113	src/web/angular.min.js \
114	src/web/angular-translate.min.js \
115	src/web/angular-translate-loader-url.min.js \
116	src/web/ngDialog.min.js \
117	src/web/ngDialog.min.css \
118	src/web/ngDialog-theme-plain.min.css \
119 	src/web/jquery.min.js \
120	src/web/jquery.flot.min.js \
121	src/web/jquery.flot.time.min.js \
122	src/web/jquery.flot.selection.min.js \
123	src/web/jquery.flot.resize.min.js \
124	src/web/bootstrap/css/bootstrap.min.css \
125	src/web/bootstrap/fonts/glyphicons-halflings-regular.eot \
126	src/web/bootstrap/fonts/glyphicons-halflings-regular.ttf \
127	src/web/bootstrap/fonts/glyphicons-halflings-regular.woff \
128	src/web/bootstrap/fonts/glyphicons-halflings-regular.woff2
129
130testinstall:
131	mkdir -p ../tests/web ../tests/data ../tests/logs
132	cp -p $(subst src/,,$(WEBFILES)) ../tests/web/
133
134test: all testinstall
135	cd ../tests && make
136
137# -------------------------------------------------------------------- #
138
139.PHONY:	version_data.h
140version_data.h:
141	@echo "Generating version_data.h"
142	@echo "/* generated automatically by Makefile - mark your branch in version_branch.h */" > version_data.h.new
143	@echo "#ifndef VERSIONDATA_H" >> version_data.h.new
144	@echo "#define VERSIONDATA_H" >> version_data.h.new
145	@echo "#define VERSION \"$(VERSION)\"" >> version_data.h.new
146	@echo "#define SRCVERSION \"$(SRCVERSION)\"" >> version_data.h.new
147	@echo "#define BUILD_TIME \"$(BUILD_TIME)\"" >> version_data.h.new
148	@echo "#define BUILD_USER \"$(BUILD_USER)\"" >> version_data.h.new
149	@echo "#endif" >> version_data.h.new
150	@if test ! -f /version_data.h; then cp version_data.h.new version_data.h; fi
151	@diff version_data.h.new version_data.h > /dev/null || mv version_data.h.new version_data.h
152	@rm -f version_data.h.new
153
154# -------------------------------------------------------------------- #
155
156OBJS = aprsc.o accept.o worker.o errno_aprsc.o \
157	login.o incoming.o dupecheck.o outgoing.o \
158	clientlist.o client_heard.o \
159	parse_aprs.o parse_qc.o \
160	messaging.o \
161	config.o netlib.o xpoll.o acl.o \
162	cfgfile.o passcode.o uplink.o \
163	rwlock.o hmalloc.o hlog.o \
164	keyhash.o \
165	filter.o cellmalloc.o historydb.o \
166	counterdata.o status.o cJSON.o \
167	http.o ssl.o sctp.o version.o \
168	@LIBOBJS@
169
170clean:
171	rm -f *.o *~ */*~ ../*~ core *.d
172	rm -f ../svn-commit* svn-commit*
173
174distclean: clean
175	rm -f aprsc
176	rm -f aprsc.8
177	rm -f ac-hdrs.h Makefile config.log config.status
178	rm -rf autom4te.cache
179	rm -f build-stamp configure-stamp
180	rm -rf ../build/build-out ../build/build-down
181	rm -rf debian/aprsc debian/*.debhelper debian/*.log \
182		debian/aprsc.substvars debian/changelog
183	rm -f ../*.deb ../*.changes
184	rm -f ../tests/data/* ../tests/logs/*
185	rm -rf ../tests/web/*
186
187aprsc: $(OBJS)
188	$(LD) $(LDFLAGS) -g -o aprsc $(OBJS) $(LIBS)
189
190%.o: %.c VERSION Makefile
191	$(CC) $(CFLAGS) -c $<
192	@$(CC) -MM $(CFLAGS) $< > $(@:.o=.d)
193
194version.o: version_data.h
195
196aprsc.8 : % : %.in VERSION Makefile
197	perl -ne "s{\@DATEVERSION\@}{$(VERSION)-$(SRCVERSION) - $(DATE)}g;	\
198	          s{\@VARRUN\@}{$(VARRUN)}g;			\
199	          s{\@VARLOG\@}{$(VARLOG)}g;			\
200	          s{\@CFGFILE\@}{$(CFGFILE)}g;			\
201		  print;"					\
202	 < $< > $@
203
204
205# -------------------------------------------------------------------- #
206
207# target paths
208#VARRUN=	/var/run	# directory for pid-file
209#VARLOG=	/var/log/aprsc	# directory for direct logfiles
210#CFGFILE=	@sysconfdir@/aprsc.conf	# default configuration file
211#SBINDIR=	@sbindir@# installation path for programs
212#MANDIR=	@mandir@	# installation path for manual pages
213#DATAROOTDIR=	@datarootdir@
214
215.PHONY:	install install-deb
216install: all
217	$(INSTALL_DIR) $(DESTDIR)$(PREFIX)/etc/aprsc/web
218	$(INSTALL_PROGRAM) aprsc $(DESTDIR)$(PREFIX)$(SBINDIR)/aprsc
219	$(INSTALL_PROGRAM) aprsc_munin $(DESTDIR)$(PREFIX)$(SBINDIR)/aprsc_munin
220	$(INSTALL_PROGRAM) aprsc-prepare-chroot.sh $(DESTDIR)$(PREFIX)$(SBINDIR)/aprsc-prepare-chroot.sh
221	$(INSTALL_DATA) aprsc.8 $(DESTDIR)$(MANDIR)/man8/aprsc.8
222	$(INSTALL_DATA) $(subst src/,,$(WEBFILES)) $(DESTDIR)$(PREFIX)/etc/aprsc/web
223	if [ ! -f  $(DESTDIR)$(CFGFILE) ] ; then \
224		$(INSTALL_DATA) aprsc.conf $(DESTDIR)$(PREFIX)/etc/aprsc/aprsc.conf.sample ; \
225	else true ; fi
226
227# -------------------------------------------------------------------- #
228
229DISTVERSION:=aprsc-$(VERSION).$(SRCVERSION)
230DISTTARGET:=../../$(DISTVERSION)
231RPMVERSION:=$(shell echo "${DISTVERSION}" | sed -e 's/aprsc-//')
232.PHONY: dist rpm/aprsc.spec
233dist: rpm/aprsc.spec
234	@# Special for the source maintainer only..
235	@if [ ! -z "$(shell echo -n $(SVNVERSION) | tr -d 0-9)" ]; then	    \
236	  echo "Mixed or modified tree ($(SVNVERSION)), ARE YOU SURE ??." ; \
237	  echo -n "Y/^C ? "; read var ;					    \
238	fi
239	if [ ! -d $(DISTTARGET) ] ; then	\
240		mkdir $(DISTTARGET) ;		\
241	fi
242	tar cf - --exclude=windows --exclude-vcs --exclude=.svn --exclude="*.log*" \
243		--exclude=tools --exclude="*.pid" \
244		--exclude="*~" \
245		--exclude="build" --exclude "HOME.md" \
246		--exclude="javaprssrvr" --exclude="javaprssrvr4" \
247		--exclude=build-out --exclude=build-down \
248		.. | (cd $(DISTTARGET) ; tar xf -)
249	make -C $(DISTTARGET)/src distclean
250	cd ../.. && 	\
251	tar czf $(DISTVERSION).tar.gz $(DISTVERSION)
252
253dist-upload: dist
254	scp ../../$(DISTVERSION).tar.gz aprsc-dist:/data/www/hes/html/aprsc/down/
255	ssh aprsc-dist "cd /data/www/hes/html/aprsc/down/ && rm aprsc-latest.tar.gz; ln -s $(DISTVERSION).tar.gz aprsc-latest.tar.gz"
256
257rpm/aprsc.spec: rpm/aprsc.spec.in
258	perl -ne "s{\@VERSION\@}{$(RPMVERSION)}g;	\
259		  s{\@DATE0\@}{$(DATE0)}g;		\
260		  print;"				\
261		  < rpm/aprsc.spec.in	\
262		  > rpm/aprsc.spec
263
264# -------------------------------------------------------------------- #
265
266.PHONY: make-deb make-rpm
267
268make-deb:
269	if [ -f debian/changelog.release ] ; then \
270	perl -ne "\$$ver = '$(DISTVERSION)'; 	\
271		  \$$ver =~ s/^.*?-//;	\
272		  \$$cname = '$(LINUXCODENAME)';	\
273		  \$$cname =~ s/\///g;		\
274		  \$$ver .= \"+\$$cname\" . '1';	\
275		  s{\@VERSION\@}{\$$ver}g;	\
276		  s{\@RFCDATE\@}{$(RFCDATE)}g;	\
277		  print;"			\
278		  < debian/changelog.release	\
279		  > debian/changelog ; \
280	fi
281	nice dpkg-buildpackage -b -us -uc -rfakeroot -j2
282
283make-rpm: # actually just a reminder of how to do it..
284	rpmbuild --target i686 -ta $(DISTVERSION).tar.gz
285
286# -------------------------------------------------------------------- #
287
288MARKDOWN=perl ../tools/Markdown.pl
289WEBDOCS=/data/www/hes/html/aprsc
290DOCS=README.md INSTALLING.md BUILDING.md CONFIGURATION.md DEBUGGING.md \
291	HOME.md CONTRIBUTING.md MONITORING.md TIPS.md WINDOWS.md \
292	TRANSLATING.md
293DESTDOCS=$(addprefix $(WEBDOCS)/,$(addsuffix .html,$(basename $(DOCS))))
294SRCDOCS=$(addprefix ../doc/,$(DOCS))
295install-webdoc: $(DESTDOCS)
296$(DESTDOCS): $(SRCDOCS) ../doc/web-header.html ../doc/web-footer.html
297	cp ../doc/web-header.html $@
298	$(MARKDOWN) < $(addprefix ../doc/,$(basename $(notdir $@))).md >> $@
299	cat ../doc/web-footer.html >> $@
300
301# -------------------------------------------------------------------- #
302
303
304# include object depencies if available
305@ifGNUmake@ -include $(OBJS:.o=.d)
306
307