works as of old
[otp-base.git] / tools / .appgen / blank_app_rel / Makefile
blob34dab003fbaa9062867b6520462a65e35e0ad8c3
1 # ----------------------------------------------------
2 # Make file for creating an otp release.
3 # ----------------------------------------------------
5 ##
6 # Basename of this release.
7 ##
8 RELS=$(shell basename `pwd`)
9 APP_NAME=$(shell echo $(RELS) | sed s/_rel$$//)
11 include ../../build/otp.mk
13 include ./vsn.mk
15 USR_LIBPATH=../../lib
16 ERLWARE_LIB_PATH=$(ERLWARE_HOME)/application_packages/$(TARGET_ERTS_VSN)/lib
17 FSLIB_DIR=$(ERLWARE_LIB_PATH)/$(shell ls $(ERLWARE_LIB_PATH) | grep fslib | sort -r | head -n 1)
18 INSTALL_DIR=/usr/local/lib
19 ABS_USER_LIBPATH=$(shell cd ../../lib;pwd)
21 # ----------------------------------------------------
22 # CREATE DIR STRUCTURE HERE
23 # ----------------------------------------------------
25 HTDOCS=$(wildcard $(ABS_USER_LIBPATH)/$(APP_NAME)/htdocs/*.html) \
26 $(wildcard $(ABS_USER_LIBPATH)/$(APP_NAME)/htdocs/*.htm) \
27 $(wildcard $(ABS_USER_LIBPATH)/$(APP_NAME)/htdocs/*.yaws)
28 BUILD_FILES=fs_boot_smithe.beam fs_lists.beam fs_lib.beam
30 LOCAL_DIR=local
31 #LOCAL_DIR=$(shell cat $(RELS).rel.src |grep -m 1 '$(APP_NAME)' |awk -F '"' '{printf "%s-%s", $$2,$$4}')
33 DIR_STRUCTURE= \
34 $(LOCAL_DIR) \
35 $(LOCAL_DIR)/log/$(REL_VSN) \
36 $(LOCAL_DIR)/var/$(REL_VSN) \
37 $(LOCAL_DIR)/var/$(REL_VSN)/www/conf \
38 $(LOCAL_DIR)/var/$(REL_VSN)/www/htdocs
40 PRODUCTION_DIR_STRUCTURE= \
41 $(RELS) \
42 $(RELS)/release/$(REL_VSN) \
43 $(RELS)/stage \
44 $(RELS)/log/$(REL_VSN) \
45 $(RELS)/var/$(REL_VSN) \
46 $(RELS)/var/$(REL_VSN)/www \
47 $(RELS)/var/$(REL_VSN)/www/htdocs \
48 $(RELS)/var/$(REL_VSN)/www/conf
50 # ----------------------------------------------------
51 SCRIPT_AND_BOOT_FILES= \
52 $(RELS).script \
53 $(RELS).boot
55 LOCAL_SCRIPT_AND_BOOT_FILES= \
56 $(LOCAL_DIR)/$(RELS).script \
57 $(LOCAL_DIR)/$(RELS).boot
59 LOCAL_HTTP_CONF= \
60 $(LOCAL_DIR)/var/$(REL_VSN)/www/conf/yaws.conf \
61 $(LOCAL_DIR)/var/$(REL_VSN)/www/conf/mime.types
63 PRODUCTION_HTTP_CONF= \
64 $(LOCAL_DIR)/var/$(REL_VSN)/www/conf/yaws.conf \
65 $(LOCAL_DIR)/var/$(REL_VSN)/www/conf/mime.types
67 LOCAL_TARGET_FILES=$(LOCAL_HTTP_CONF) $(LOCAL_DIR)/$(RELS).config $(LOCAL_SCRIPT_AND_BOOT_FILES)
69 LOCAL_TARGETS=$(LOCAL_DIR)/$(RELS).sh vsnit $(LOCAL_TARGET_FILES)
71 PRODUCTION_TARGETS=$(RELS)/build/$(REL_VSN) \
72 $(RELS)/lib \
73 $(RELS)/stage/$(RELS).rel.src \
74 $(RELS)/stage/$(RELS).config.src \
75 $(RELS)/stage/yaws.conf.src \
76 $(RELS)/stage/$(RELS).sh.src \
77 $(RELS)/var/$(REL_VSN)/www/htdocs \
78 $(RELS)/install.sh \
79 $(RELS)/release/$(REL_VSN)/clean_release
81 # ----------------------------------------------------
82 # TARGETS
83 # ----------------------------------------------------
85 all debug opt instr script: $(DIR_STRUCTURE) $(LOCAL_TARGETS) $(PRODUCTION_DIR_STRUCTURE) $(PRODUCTION_TARGETS)
86 @echo $(HTDOCS)
88 install: stage
90 tar: $(RELS)-$(LOCATION)-$(REL_VSN).tgz
92 $(DIR_STRUCTURE):
93 mkdir -p $@
95 $(PRODUCTION_DIR_STRUCTURE):
96 mkdir -p $@
98 clean:
99 $(RM) $(REL_SCRIPTS) $(TARGET_FILES)
100 $(RM) -r $(LOCAL_DIR) $(PRODN_DIR)
101 $(RM) $(RELS).rel
102 $(RM) -r $(RELS)
103 $(RM) $(RELS)*.tgz
104 $(RM) $(RELS).rel.src.tmp
105 $(RM) $(SCRIPT_AND_BOOT_FILES)
107 docs:
109 # ----------------------------------------------------
110 # TARGETS FOR LOCAL MODE
111 # ----------------------------------------------------
113 # startup script for local mode
114 $(LOCAL_DIR)/$(RELS).sh:
115 @echo '#!/bin/sh' > $@
116 @echo "cd $(CURDIR)/$(LOCAL_DIR)" >> $@
117 @echo "erl -name $${USER}_$(RELS) -boot $(RELS) -config $(RELS).config \$$@" >> $@
118 chmod +x $@
119 @echo
120 @echo "==== Start local node with \"sh $@\" ===="
121 @echo
123 # Create the config file for local mode.
124 $(LOCAL_DIR)/$(RELS).config: $(RELS).config.src
125 sed -e 's;%LOG_OTP%;$(CURDIR)/$(LOCAL_DIR)/log/$(REL_VSN);' \
126 -e 's;%VAR_OTP%;$(CURDIR)/$(LOCAL_DIR)/var/$(REL_VSN);' \
127 -e 's;%RELS%;$(RELS);g' \
128 -e 's;%HOME%;$(HOME);g' \
129 -e 's;%BROADCAST_ADDRESS%;$(BROADCAST_ADDRESS);g' \
130 -e 's;%CONTACT_NODE%;$(CONTACT_NODE);g' \
131 -e "s;%HOSTNAME%;`hostname --long`;" \
132 -e 's;%APP_NAME%;$(APP_NAME);' \
133 -e 's;%APP_VERSION%;$(APP_VERSION);g' \
134 $< > $@
136 # Create the httpd conf file for local mode.
137 $(LOCAL_DIR)/var/$(REL_VSN)/www/conf/yaws.conf: yaws.conf.src
138 sed -e 's;%VAR_OTP%;$(CURDIR)/$(LOCAL_DIR)/var/$(REL_VSN);' \
139 -e 's;%LOG_OTP%;$(CURDIR)/$(LOCAL_DIR)/log/$(REL_VSN);' \
140 -e 's;%HTDOC_ROOT%;$(ABS_USER_LIBPATH)/$(APP_NAME)/htdocs;' \
141 -e 's;%APP_NAME%;$(APP_NAME);' \
142 -e 's;%RELS%;$(RELS);' \
143 -e 's;%USER%;$(USER);' \
144 -e 's;%HTDOC_ROOT%;$(ABS_USER_LIBPATH);' \
145 -e 's;%MHOST%;$(MHOST);' \
146 $< > $@
148 # Create the config file for local mode.
149 vsnit: $(RELS).rel.src
150 sed -e 's;%REL_VSN%;$(REL_VSN);' \
151 $< > $<.tmp
153 # Create and position script and boot files for local mode.
154 $(LOCAL_SCRIPT_AND_BOOT_FILES):
155 @echo "FSLIB_DIR: $(FSLIB_DIR)"
156 @ erl -pz $(FSLIB_DIR)/ebin \
157 -noshell \
158 -s fs_lib commandline_apply fs_boot_smithe make_script_and_boot [\"$(ERLWARE_LIB_PATH)/*\",\"$(ERL_RUN_TOP)/*\",\"$(USR_LIBPATH)\"] \
159 \"$$(basename `pwd`).rel.src.tmp\" \
160 [local] \
161 -s init stop
162 cp $(SCRIPT_AND_BOOT_FILES) $(LOCAL_DIR)/
164 $(LOCAL_DIR)/var/$(REL_VSN)/www/conf/mime.types: ../../build/mime.types
165 cp $< $@
167 # ----------------------------------------------------
168 # TARGETS FOR PRODUCTION MODE
169 # ----------------------------------------------------
170 $(RELS)/lib:
171 # For some reason this will not happen if added to PRODUCTION_DIR_STRUCTURE
172 mkdir $@
173 @ erl -pz $(RELS)/build/$(REL_VSN) \
174 -noshell \
175 -s fs_lib commandline_apply fs_boot_smithe stage_from_relsrc [\"$(USR_LIBPATH)\"] \
176 \"$$(basename `pwd`).rel.src\" \
177 \"$@\" \
178 -s init stop
180 # Move the htdocs from the local apps to the production htdoc root directory.
181 $(RELS)/var/$(REL_VSN)/www/htdocs/: $(HTDOCS)
182 @mkdir -p $(RELS)/var/$(REL_VSN)/www/htdocs; \
183 for x in $(HTDOCS);do \
184 cp $$x $@; \
185 done
187 # startup script for production mode
188 $(RELS)/stage/$(RELS).sh.src:
189 @echo '#!/bin/sh' > $@
190 @echo "cd %INSTALL_DIR%/$(RELS)/release/$(REL_VSN)" >> $@
191 @echo "erl -name $(RELS) -boot $(RELS) -config $(RELS).config -detached \$$@" >> $@
192 chmod +x $@
194 $(RELS)/build/$(REL_VSN): $(FSLIB_DIR)/ebin
195 mkdir -p $(RELS)/build/$(REL_VSN)
196 cp $</fs_boot_smithe.beam $@
197 cp $</fs_lib.beam $@
198 cp $</fs_lists.beam $@
200 $(RELS)/stage/$(RELS).rel.src: $(RELS).rel.src.tmp
201 cp $< $@
203 $(RELS)/stage/$(RELS).config.src: $(RELS).config.src
204 cp $< $@
206 $(RELS)/stage/yaws.conf.src: yaws.conf.src
207 cp $< $@
209 $(RELS)/install.sh:
210 @echo '#!/bin/sh' > $@
211 @echo "" >> $@
212 @echo "if [ \$$# -eq 1 ];then" >> $@
213 @echo " INSTALL_DIR=\$$1;" >> $@
214 @echo "else" >> $@
215 @echo " INSTALL_DIR=$(INSTALL_DIR);" >> $@
216 @echo "fi" >> $@
217 @echo "" >> $@
218 @echo "function munge() {" >> $@
219 @echo " sed -e \"s;%LOG_OTP%;\$$INSTALL_DIR/$(RELS)/log/$(REL_VSN);g\" \\" >> $@
220 @echo " -e \"s;%VAR_OTP%;\$$INSTALL_DIR/$(RELS)/var/$(REL_VSN);g\" \\" >> $@
221 @echo " -e \"s;%RELS%;$(RELS);g\" \\" >> $@
222 @echo " -e \"s;%REL_VSN%;$(REL_VSN);g\" \\" >> $@
223 @echo " -e \"s;%USER%;$$USER;g\" \\" >> $@
224 @echo " -e \"s;%HTDOC_ROOT%;\$$INSTALL_DIR/$(RELS)/var/$(REL_VSN)/www/htdocs;g\" \\" >> $@
225 @echo " -e \"s;%MHOST%;\`hostname\`;g\" \\" >> $@
226 @echo " -e \"s;%BROADCAST_ADDRESS%;$(BROADCAST_ADDRESS);g\" \\" >> $@
227 @echo " -e \"s;%INSTALL_DIR%;\$$INSTALL_DIR;g\" \\" >> $@
228 @echo " -e \"s;%CONTACT_NODE%;$(CONTACT_NODE);g\" \\" >> $@
229 @echo " -e \"s;%HOSTNAME%;\`hostname --long\`;g\" \\" >> $@
230 @echo " -e \"s;%APP_NAME%;$(APP_NAME);g\" \\" >> $@
231 @echo " -e \"s;%APP_VERSION%;$(APP_VERSION);g\" \\" >> $@
232 @echo ' $$1 > $$2' >> $@
233 @echo "}" >> $@
234 @echo "" >> $@
235 @echo "munge stage/yaws.conf.src var/$(REL_VSN)/www/conf/yaws.conf;" >> $@
236 @echo "munge stage/$(RELS).config.src release/$(REL_VSN)/$(RELS).config;" >> $@
237 @echo "munge stage/$(RELS).sh.src release/$(REL_VSN)/$(RELS).sh;" >> $@
238 @echo "munge stage/$(RELS).rel.src release/$(REL_VSN)/$(RELS).rel;" >> $@
239 @echo "chmod +x release/$(REL_VSN)/$(RELS).sh;" >> $@
240 @echo "" >> $@
241 @echo "cd ..;" >> $@
242 @echo "find $(RELS) | cpio -o > \$$INSTALL_DIR/$(RELS).cpio;" >> $@
243 @echo "cd -;" >> $@
244 @echo "cd \$$INSTALL_DIR; " >> $@
245 @echo "echo -n \"Unpacked: \"" >> $@
246 @echo "cpio -uid < $(RELS).cpio;" >> $@
247 @echo "rm $(RELS).cpio;" >> $@
248 @echo "" >> $@
249 @echo "echo \"pwd is \`pwd\`\";" >> $@
250 @echo "cd $(RELS);" >> $@
251 @echo " erl -pz build/$(REL_VSN) \\" >> $@
252 @echo " -noshell \\" >> $@
253 @echo -n " -s fs_lib s_apply fs_boot_smithe make_script_and_boot \"[\\\"$(ERLWARE_HOME)/*\\\", \\\"$(ERL_RUN_TOP)/*\\\", \\\"lib/\\\"]. \" " >> $@
254 @echo -n "\"\\\"stage/$$(basename `pwd`).rel.src\\\". \" " >> $@
255 @echo -n "\"[local]. \" " >> $@
256 @echo "-s init stop | egrep '*terminate*|ERROR'" >> $@
257 @echo "if [ \$$? -eq 0 ]; then" >> $@
258 @echo "echo \"============================================\";" >> $@
259 @echo "echo \"STAGE FAILURE \$$? - Silence the discord.\";" >> $@
260 @echo "echo \"============================================\";" >> $@
261 @echo "exit 1;" >> $@
262 @echo "fi" >> $@
263 @echo "" >> $@
264 @echo "mv $(RELS).rel $(RELS).script $(RELS).boot release/$(REL_VSN);" >> $@
265 @echo "" >> $@
266 @echo "rm -r stage;" >> $@
267 @echo "rm -r build;" >> $@
268 @echo "cd -;" >> $@
269 @echo "" >> $@
270 @echo "chgrp -R erts $(RELS); " >> $@
271 @echo "chmod -R 775 $(RELS); " >> $@
272 @echo "cd -" >> $@
273 @echo "" >> $@
274 @echo "rm -f /usr/local/bin/$(APP_NAME);" >> $@
275 @echo "ln -s \$$INSTALL_DIR/$(RELS)/release/$(REL_VSN)/$(RELS).sh /usr/local/bin/$(APP_NAME);" >> $@
276 @echo "chgrp -R erts /usr/local/bin/$(APP_NAME); " >> $@
277 @echo "chmod -R 775 /usr/local/bin/$(APP_NAME); " >> $@
278 @echo "rm \$$INSTALL_DIR/$(RELS)/install.sh;" >> $@
279 @echo "echo -n $$'\e[0;32m'" >> $@
280 @echo "echo \"$(APP_NAME) installation to \$$INSTALL_DIR complete.\"" >> $@
281 @echo "echo -n $$'\e[0m'" >> $@
282 chmod +x $@
285 stage: $(RELS)
286 cd $(RELS); \
287 ./install.sh; \
288 cd -
290 $(RELS)/var/$(REL_VSN)/www/conf/mime.types: ../../build/mime.types
291 cp $< $@
293 $(RELS)-$(LOCATION)-$(REL_VSN).tgz: $(RELS)
294 tar -zcvf $@ $<
296 $(RELS)/release/$(REL_VSN)/clean_release: ../../tools/utilities/clean_release
297 cp $< $@