-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMakefile
157 lines (138 loc) · 6.96 KB
/
Makefile
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
# =============================================================
# This file is part of jsh.
#
# jsh: A basic UNIX shell implementation in C
# Copyright (C) 2014 Jo Van Bulck <[email protected]>
#
# jsh 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 3 of the License, or
# (at your option) any later version.
#
# jsh 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 jsh. If not, see <http://www.gnu.org/licenses/>.
# ============================================================
JSH_INSTALL_DIR = /usr/local/bin
MANPAGE_INSTALL_DIR = /usr/local/share/man/man1
JSH_RELEASE_DIR = ./JSH_$(RELEASE_NB)_RELEASE
DATE = $(shell date +%d\ %b\ %Y)
HOUR = $(shell date +%Hh%M)
MACHINE_BUILT = $(shell uname -srm)
MACHINE_RELEASE = $(shell uname -sm)
RELEASE_NB = 1.2.1
RELEASE_VERSION_STR = "jsh $(RELEASE_NB) on $(MACHINE_RELEASE) (official release $(DATE))"
DEV_BUILT_VERSION_STR = "jsh post $(RELEASE_NB) on $(MACHINE_BUILT) \n(developer built $(DATE) : $(HOUR))"
VERSION_STR = $(DEV_BUILT_VERSION_STR)
# 'make release' will override the above line to RELEASE_VERSION_STR
ifndef CC # allow the compiler to be changed with 'export CC=the_compiler'
CC = gcc
endif
CFLAGS = -g -DVERSION='$(VERSION_STR)' $(EXTRA_CFLAGS)
# EXTRA_CFLAGS is empty on default; 'make install' will add the INSTALL_CFLAGS
ifndef INSTALL_CFLAGS
INSTALL_CFLAGS = -DNODEBUG
endif
LIBS = -lreadline
LN = $(CC) $(CFLAGS) jsh-common.o jsh.o alias.o jsh-parse.o jsh-completion.o -o jsh $(LIBS)
ECHO_LIBS = echo "Linking jsh with the following libraries: $(LIBS) "
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
IS_BSD
else ifeq ($(UNAME_S), FreeBSD)
IS_BSD
endif
ifeq ($(UNAME_S), Darwin)
# link explicitely with readline library folder for Mac OS X (installed with homebrew)
LINK = $(LN) -L/usr/local/lib/
else
# try to link jsh with the readline library (and curses or termcap if needed)
LINK = @(($(ECHO_LIBS)); ($(LN)) || (($(ECHO_LIBS) "lncurses"); $(LN) -lncurses) || \
(($(ECHO_LIBS) "termcap"); $(LN) -termcap) || (echo "Failed linking jsh: all known fallback libraries were tried"))
endif
all: print_start_info jsh-common alias parse completion jsh link man
@echo "-------- Compiling all done --------"
jsh-common: jsh-common.c jsh-common.h
$(CC) $(CFLAGS) -c jsh-common.c -o jsh-common.o
alias: alias.c alias.h jsh-common.h
$(CC) $(CFLAGS) -c alias.c -o alias.o
parse: jsh-parse.c jsh-parse.h jsh-common.h
$(CC) $(CFLAGS) -c jsh-parse.c -o jsh-parse.o
completion: jsh-completion.h jsh-completion.c jsh-common.h
$(CC) $(CFLAGS) -c jsh-completion.c -o jsh-completion.o
jsh: jsh.c jsh-common.h
$(CC) $(CFLAGS) -c jsh.c -o jsh.o
link: jsh-common.o jsh.o alias.o jsh-parse.o jsh-completion.o
$(LINK)
man: jsh-man.1
ifndef NO_MAKE_MAN # don't make the man page when NO_MAKE_MAN has a non-empty value
@echo "making man page: adding version number and date to jsh.1"
ifdef IS_BSD # BSD sed version has another syntax
@sed -e 's/@VERSION/$(RELEASE_NB)/' -e 's/@DATE/$(DATE)/' \
-e '/@BEGIN_COMMENT/,/END_COMMENT/c\ '$$'\n''.\\" jsh manpage auto generated by jsh Makefile' \
< jsh-man.1 > jsh.1
else # GNU sed version syntax
@sed -e 's/@VERSION/$(RELEASE_NB)/' -e 's/@DATE/$(DATE)/' \
-e '/@BEGIN_COMMENT/,/END_COMMENT/c\.\\" jsh manpage auto generated by jsh Makefile' \
< jsh-man.1 > jsh.1
endif
endif
.PHONY: print_start_info
print_start_info:
@echo "-------- making jsh version" $(VERSION_STR) "-------- "
## this helper target is a hack for TravisCI; since it seems it can't use the clang
## compiler when making with 'sudo'
.PHONY: make_for_install
make_for_install:
ifndef INSTALL_ONLY
@echo "-------- installing jsh --------"
@echo "making jsh with additional $(INSTALL_CFLAGS) flags"
$(MAKE) --always-make EXTRA_CFLAGS='$(INSTALL_CFLAGS)' NO_MAKE_MAN='$(NO_MAKE_MAN)'
endif
.PHONY: install
install: make_for_install
@echo "installing jsh executable in directory $(JSH_INSTALL_DIR)..."
@test -d $(JSH_INSTALL_DIR) || (mkdir -p $(JSH_INSTALL_DIR) && echo "created directory $(JSH_INSTALL_DIR)")
@install -m 0755 jsh $(JSH_INSTALL_DIR);
ifndef NO_MAKE_MAN
@echo "installing the manpage in directory $(MANPAGE_INSTALL_DIR)..."
@test -d $(MANPAGE_INSTALL_DIR) || (mkdir -p $(MANPAGE_INSTALL_DIR) && echo "created directory $(MANPAGE_INSTALL_DIR)")
@install -m 0644 jsh.1 $(MANPAGE_INSTALL_DIR);
ifndef IS_BSD # Man-DB update is not necessary on BSD based systems
@echo "updating man-db..."
@mandb --quiet
endif
endif
@echo "-------- Installation all done --------"
.PHONY: uninstall
uninstall:
@echo "-------- Uninstalling jsh from directories $(JSH_INSTALL_DIR) and $(MANPAGE_INSTALL_DIR) --------"
rm -f $(JSH_INSTALL_DIR)/jsh $(MANPAGE_INSTALL_DIR)/jsh.1
@echo "-------- Uninstallation all done --------"
.PHONY: release
release:
@echo "-------- making jsh $(RELEASE_NB) release built --------"
$(MAKE) --always-make EXTRA_CFLAGS='$(INSTALL_CFLAGS)' VERSION_STR='$(RELEASE_VERSION_STR)'
@echo "copying jsh executable in directory $(JSH_RELEASE_DIR)/ ..."
@test -d $(JSH_RELEASE_DIR) || (mkdir -p $(JSH_RELEASE_DIR) && echo "created directory $(JSH_RELEASE_DIR)")
cp jsh $(JSH_RELEASE_DIR) && chmod a+rx $(JSH_RELEASE_DIR)/jsh;
@echo "copying the manpage in directory $(JSH_RELEASE_DIR)..."
cp jsh.1 $(JSH_RELEASE_DIR) && chmod a+r $(JSH_RELEASE_DIR)/jsh.1;
@echo "-------- Release built all done --------"
.PHONY: clean
clean:
rm -f jsh-common.o alias.o jsh.o jsh jsh.1
(test -d $(JSH_RELEASE_DIR) && rm -rfI $(JSH_RELEASE_DIR)) || true
.PHONY: help
help:
@echo "The following are valid targets for this Makefile:"
@echo "... all -- (the default if no target is provided); compiles the shell to the 'jsh' binary in the current directory"
@echo "... clean -- removes all object files generated by the build process; also removes the $(JSH_RELEASE_DIR)/ directory and its content, if any"
@echo "... install -- installs the jsh binary with $(INSTALL_CFLAGS) options to $(JSH_INSTALL_DIR)/ and the jsh man page to $(MANPAGE_INSTALL_DIR)/ Make sure you have the necessary rights, use 'sudo make install' if necessary."
@echo "... uninstall -- removes the jsh binary from $(JSH_INSTALL_DIR)/ and the jsh man page from $(MANPAGE_INSTALL_DIR)/ Make sure you have the necessary rights, use 'sudo make uninstall' if necessary."
@echo "... man -- makes a UNIX man page 'jsh.1' with filled in date and version number in the current directory"
@echo "... release -- makes a jsh release built in $(JSH_RELEASE_DIR)/ in the current directory"