1 # ----------------------------------------------------
2 # Make file for creating an otp release.
3 # ----------------------------------------------------
6 # Basename of this release.
8 RELS
=$(shell basename `pwd`)
9 APP_NAME
=$(shell echo
$(RELS
) | sed s
/_rel
$$//)
11 include ..
/..
/build
/otp.mk
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
31 #LOCAL_DIR=$(shell cat $(RELS).rel.src |grep -m 1 '$(APP_NAME)' |awk -F '"' '{printf "%s-%s", $$2,$$4}')
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
= \
42 $(RELS
)/release
/$(REL_VSN
) \
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
= \
55 LOCAL_SCRIPT_AND_BOOT_FILES
= \
56 $(LOCAL_DIR
)/$(RELS
).script \
57 $(LOCAL_DIR
)/$(RELS
).boot
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
) \
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 \
79 $(RELS
)/release
/$(REL_VSN
)/clean_release
81 # ----------------------------------------------------
83 # ----------------------------------------------------
85 all debug opt instr script
: $(DIR_STRUCTURE
) $(LOCAL_TARGETS
) $(PRODUCTION_DIR_STRUCTURE
) $(PRODUCTION_TARGETS
)
90 tar: $(RELS
)-$(LOCATION
)-$(REL_VSN
).tgz
95 $(PRODUCTION_DIR_STRUCTURE
):
99 $(RM
) $(REL_SCRIPTS
) $(TARGET_FILES
)
100 $(RM
) -r
$(LOCAL_DIR
) $(PRODN_DIR
)
104 $(RM
) $(RELS
).rel.src.tmp
105 $(RM
) $(SCRIPT_AND_BOOT_FILES
)
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 \$$@" >> $@
120 @echo
"==== Start local node with \"sh $@\" ===="
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' \
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);' \
148 # Create the config file for local mode.
149 vsnit
: $(RELS
).rel.src
150 sed
-e
's;%REL_VSN%;$(REL_VSN);' \
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 \
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
\" \
162 cp
$(SCRIPT_AND_BOOT_FILES
) $(LOCAL_DIR
)/
164 $(LOCAL_DIR
)/var
/$(REL_VSN
)/www
/conf
/mime.types
: ..
/..
/build
/mime.types
167 # ----------------------------------------------------
168 # TARGETS FOR PRODUCTION MODE
169 # ----------------------------------------------------
171 # For some reason this will not happen if added to PRODUCTION_DIR_STRUCTURE
173 @ erl
-pz
$(RELS
)/build
/$(REL_VSN
) \
175 -s fs_lib commandline_apply fs_boot_smithe stage_from_relsrc
[\"$(USR_LIBPATH
)\"] \
176 \"$$(basename `pwd`).rel.src
\" \
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 \
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 \$$@" >> $@
194 $(RELS
)/build
/$(REL_VSN
): $(FSLIB_DIR
)/ebin
195 mkdir
-p
$(RELS
)/build
/$(REL_VSN
)
196 cp
$</fs_boot_smithe.beam
$@
198 cp
$</fs_lists.beam
$@
200 $(RELS
)/stage
/$(RELS
).rel.src
: $(RELS
).rel.src.tmp
203 $(RELS
)/stage
/$(RELS
).config.src
: $(RELS
).config.src
206 $(RELS
)/stage
/yaws.conf.src
: yaws.conf.src
210 @echo
'#!/bin/sh' > $@
212 @echo
"if [ \$$# -eq 1 ];then" >> $@
213 @echo
" INSTALL_DIR=\$$1;" >> $@
215 @echo
" INSTALL_DIR=$(INSTALL_DIR);" >> $@
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' >> $@
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;" >> $@
242 @echo
"find $(RELS) | cpio -o > \$$INSTALL_DIR/$(RELS).cpio;" >> $@
244 @echo
"cd \$$INSTALL_DIR; " >> $@
245 @echo
"echo -n \"Unpacked: \"" >> $@
246 @echo
"cpio -uid < $(RELS).cpio;" >> $@
247 @echo
"rm $(RELS).cpio;" >> $@
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;" >> $@
264 @echo
"mv $(RELS).rel $(RELS).script $(RELS).boot release/$(REL_VSN);" >> $@
266 @echo
"rm -r stage;" >> $@
267 @echo
"rm -r build;" >> $@
270 @echo
"chgrp -R erts $(RELS); " >> $@
271 @echo
"chmod -R 775 $(RELS); " >> $@
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'" >> $@
290 $(RELS
)/var
/$(REL_VSN
)/www
/conf
/mime.types
: ..
/..
/build
/mime.types
293 $(RELS
)-$(LOCATION
)-$(REL_VSN
).tgz
: $(RELS
)
296 $(RELS
)/release
/$(REL_VSN
)/clean_release
: ..
/..
/tools
/utilities
/clean_release