for python3: specfile and makefile, taking this chance for some overdue cleanups
[nodemanager.git] / Makefile
1 #
2 # Node Manager Makefile
3 #
4 # David Eisenstat <deisenst@cs.princeton.edu>
5 # Mark Huang <mlhuang@cs.princeton.edu>
6 # Copyright (C) 2006 The Trustees of Princeton University
7 #
8
9 # autoconf compatible variables
10 datadir := /usr/share
11 bindir := /usr/bin
12 initdir=/etc/rc.d/init.d
13 systemddir := /usr/lib/systemd/system
14
15 PYTHON = python3
16
17 # call with either WITH_SYSTEMD=true or WITH_INIT=true
18 # otherwise we try to guess some reasonable default
19 ifeq "$(WITH_INIT)$(WITH_SYSTEMD)" ""
20 ifeq "$(wildcard $systemddir/*)" ""
21 WITH_INIT=true
22 else
23 WITH_SYSTEMD=true
24 endif
25 endif
26 ####################
27 all: forward_api_calls
28         $(PYTHON) setup.py build
29
30 forward_api_calls: forward_api_calls.c
31         $(CC) -Wall -Os -o $@ $?
32         strip $@
33
34 #################### install
35 install: install-miscell install-startup
36         $(PYTHON) setup.py install \
37                 --install-purelib=$(DESTDIR)/$(datadir)/NodeManager \
38                 --install-platlib=$(DESTDIR)/$(datadir)/NodeManager \
39                 --install-scripts=$(DESTDIR)/$(bindir)
40
41 # might be better in setup.py ?
42 # NOTE: the sliver-initscripts/ and sliver-systemd stuff, being, well, for slivers,
43 # need to ship on all nodes regardless of WITH_INIT and WITH_SYSTEMD that
44 # impacts how nodemanager itself gets started
45 install-miscell:
46         install -d -m 755 $(DESTDIR)/var/lib/nodemanager
47         install -D -m 644 /dev/null $(DESTDIR)/etc/sysconfig/nodemanager
48         install -D -m 444 README $(DESTDIR)/$(datadir)/NodeManager/README
49         install -D -m 644 logrotate/nodemanager $(DESTDIR)/etc/logrotate.d/nodemanager
50         mkdir -p $(DESTDIR)/$(datadir)/NodeManager/sliver-initscripts
51         rsync -av sliver-initscripts/ $(DESTDIR)/$(datadir)/NodeManager/sliver-initscripts/
52         chmod 755 $(DESTDIR)/$(datadir)/NodeManager/sliver-initscripts/
53         mkdir -p $(DESTDIR)/$(datadir)/NodeManager/sliver-systemd
54         rsync -av sliver-systemd/ $(DESTDIR)/$(datadir)/NodeManager/sliver-systemd/
55         chmod 755 $(DESTDIR)/$(datadir)/NodeManager/sliver-systemd/
56
57 # this now is for the startup of nodemanager itself
58 ifneq "$(WITH_SYSTEMD)" ""
59 install-startup: install-systemd
60 endif
61 ifneq "$(WITH_INIT)" ""
62 install-startup: install-init
63 endif
64
65 install-init:
66         mkdir -p $(DESTDIR)$(initdir)
67         chmod 755 initscripts/*
68         rsync -av initscripts/ $(DESTDIR)$(initdir)/
69
70 install-systemd:
71         mkdir -p $(DESTDIR)/$(systemddir)
72         rsync -av systemd/ $(DESTDIR)/$(systemddir)
73
74 #################### clean
75 clean:
76         $(PYTHON) setup.py clean
77         rm -f forward_api_calls *.pyc build
78
79 .PHONY: all install clean
80
81 ################################################## devel-oriented
82 tags:
83         git ls-files | xargs etags
84
85 .PHONY: tags
86
87 ########## sync
88 # for use with the test framework; push local stuff on a test node
89 # howto use: go on testmaster in the build you want to use and just run
90 # $ exp
91 # cut'n paste the result in a terminal in your working dir, e.g. (although all are not required)
92 # $ export BUILD=2013.07.02--lxc18
93 # $ export PLCHOSTLXC=gotan.pl.sophia.inria.fr
94 # $ export GUESTNAME=2013.07.02--lxc18-1-vplc01
95 # $ export GUESTHOSTNAME=vplc01.pl.sophia.inria.fr
96 # $ export KVMHOST=kvm64-6.pl.sophia.inria.fr
97 # $ export NODE=vnode01.pl.sophia.inria.fr
98 # and then just run
99 # $ make sync
100
101 LOCAL_RSYNC_EXCLUDES    := --exclude '*.pyc'
102 RSYNC_EXCLUDES          := --exclude .git  --exclude .svn --exclude '*~' --exclude TAGS $(LOCAL_RSYNC_EXCLUDES)
103 RSYNC_COND_DRY_RUN      := $(if $(findstring n,$(MAKEFLAGS)),--dry-run,)
104 RSYNC                   := rsync -e "ssh -i $(NODE).key.rsa" -a -v $(RSYNC_COND_DRY_RUN) $(RSYNC_EXCLUDES)
105
106 ifdef NODE
107 NODEURL:=root@$(NODE):/
108 endif
109
110 # this is for lxc only, we need to exclude the vs stuff that otherwise messes up everything on node
111 # WARNING: keep this in sync with setup.spec
112 LXC_EXCLUDES= --exclude sliver_vs.py --exclude coresched_vs.py --exclude drl.py
113
114 # run with make SYNC_RESTART=false if you want to skip restarting nm
115 SYNC_RESTART=true
116
117 sync:synclxc
118
119 synclxc: $(NODE).key.rsa
120 ifeq (,$(NODEURL))
121         @echo "sync: You must define NODE on the command line"
122         @echo "  e.g. make sync NODE=vnode01.inria.fr"
123         @exit 1
124 else
125         @echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
126         @echo WARNING : this target might not be very reliable - use with care
127         @echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
128         +$(RSYNC) $(LXC_EXCLUDES) --delete-excluded ./ $(NODEURL)/usr/share/NodeManager/
129 #       +$(RSYNC) ./initscripts/ $(NODEURL)/etc/init.d/
130         +$(RSYNC) ./systemd/ $(NODEURL)/usr/lib/systemd/system/
131         -$(SYNC_RESTART) && { ssh -i $(NODE).key.rsa root@$(NODE) service nm restart ; } ||:
132 endif
133
134 # this is for vs only, we need to exclude the lxc stuff that otherwise messes up everything on node
135 # xxx keep this in sync with setup.spec
136 VS_EXCLUDES= --exclude sliver_libvirt.py --exclude sliver_lxc.py --exclude cgroups.py --exclude coresched_lxc.py --exclude privatebridge.py
137
138 syncvs: $(NODE).key.rsa
139 ifeq (,$(NODEURL))
140         @echo "syncvs: You must define NODE on the command line"
141         @echo "  e.g. make sync NODE=vnode01.inria.fr"
142         @exit 1
143 else
144         @echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
145         @echo WARNING : this target might not be very reliable - use with care
146         @echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
147         +$(RSYNC) $(VS_EXCLUDES) --delete-excluded ./ $(NODEURL)/usr/share/NodeManager/
148         +$(RSYNC) ./initscripts/ $(NODEURL)/etc/init.d/
149 #       +$(RSYNC) ./systemd/ $(NODEURL)/usr/lib/systemd/system/
150         -$(SYNC_RESTART) && { ssh -i $(NODE).key.rsa root@$(NODE) service nm restart ; } ||:
151 endif
152
153
154 ### fetching the key
155
156 TESTMASTER ?= testmaster.onelab.eu
157
158 ifdef BUILD
159 KEYURL:=root@$(TESTMASTER):$(BUILD)/keys/key_admin.rsa
160 endif
161
162 key: $(NODE).key.rsa
163
164 $(NODE).key.rsa:
165 ifeq (,$(KEYURL))
166         @echo "sync: fetching $@ - You must define TESTMASTER, BUILD and NODE on the command line"
167         @echo "  e.g. make sync TESTMASTER=testmaster.onelab.eu BUILD=2010.01.22--1l-f8-32 NODE=vnode01.inria.fr"
168         @echo "  note that for now all test builds use the same key, so any BUILD would do"
169         @exit 1
170 else
171         @echo "FETCHING key"
172         +scp $(KEYURL) $@
173 endif
174
175 ########## exp. too
176 SLICE=inri_sl1
177
178 syncvinit:
179         $(RSYNC) sliver-systemd/vinit.st* $(NODEURL)/vservers/$(SLICE)/usr/bin/
180         $(RSYNC) sliver-systemd/vinit.service $(NODEURL)/vservers/$(SLICE)/usr/lib/systemd/system/
181         echo "remember to run 'systemctl --system daemon-reload' within this slice"