L4Re/departure

Annotated libe2access/host/Makefile

293:fc8ebfa6ba5d
2022-03-16 Paul Boddie Build library files in a separate directory when building the e2access tool.
paul@226 1
# Makefile - Build the filesystem access programs
paul@226 2
#
paul@249 3
# Copyright (C) 2019, 2021, 2022 Paul Boddie <paul@boddie.org.uk>
paul@226 4
#
paul@226 5
# This program is free software: you can redistribute it and/or modify
paul@226 6
# it under the terms of the GNU General Public License as published by
paul@226 7
# the Free Software Foundation, either version 3 of the License, or
paul@226 8
# (at your option) any later version.
paul@226 9
#
paul@226 10
# This program is distributed in the hope that it will be useful,
paul@226 11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@226 12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paul@226 13
# GNU General Public License for more details.
paul@226 14
#
paul@226 15
# You should have received a copy of the GNU General Public License
paul@226 16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
paul@226 17
paul@226 18
# Paths to library sources.
paul@226 19
paul@226 20
INC = ../include/e2access
paul@226 21
SRC = ../lib/src
paul@293 22
OBJECTS = objects
paul@226 23
paul@226 24
# Tool definitions.
paul@226 25
paul@226 26
RANLIB = ranlib
paul@226 27
paul@226 28
# Compilation and linking flags.
paul@226 29
paul@249 30
CFLAGS = -I$(INC) -fPIC # -g
paul@226 31
LDFLAGS = -lext2fs -L. -le2access # -lcom_err
paul@226 32
paul@226 33
# Output programs and libraries.
paul@226 34
paul@226 35
E2ACCESS = e2access
paul@226 36
LIBE2ACCESS = libe2access.a
paul@226 37
LIBE2ACCESS_SHARED = libe2access.so
paul@226 38
paul@226 39
TEST_LISTING = test_listing
paul@226 40
TEST_REMOVE = test_remove
paul@226 41
paul@226 42
TARGETS = $(E2ACCESS) $(LIBE2ACCESS) $(LIBE2ACCESS_SHARED) $(TEST_LISTING) $(TEST_REMOVE)
paul@226 43
paul@226 44
# Sources and objects.
paul@226 45
paul@279 46
E2ACCESS_SRC = e2access.c file.c input.c session.c ops.c $(wildcard op_*.c)
paul@226 47
E2ACCESS_OBJ = $(E2ACCESS_SRC:.c=.o)
paul@226 48
paul@226 49
TEST_LISTING_SRC = test_listing.c
paul@226 50
TEST_LISTING_OBJ = $(TEST_LISTING_SRC:.c=.o)
paul@226 51
paul@226 52
TEST_REMOVE_SRC = test_remove.c
paul@226 53
TEST_REMOVE_OBJ = $(TEST_REMOVE_SRC:.c=.o)
paul@226 54
paul@293 55
LIBE2ACCESS_SRC = format.c image.c path.c utils.c
paul@293 56
LIBE2ACCESS_SRC_MOVED = $(foreach FILE,$(LIBE2ACCESS_SRC),$(OBJECTS)/$(FILE))
paul@293 57
LIBE2ACCESS_OBJ = $(LIBE2ACCESS_SRC_MOVED:.c=.o)
paul@250 58
paul@293 59
ALL_OBJ = $(E2ACCESS_OBJ) $(LIBE2ACCESS_SRC_MOVED) $(LIBE2ACCESS_OBJ) $(TEST_LISTING_OBJ) $(TEST_REMOVE_OBJ)
paul@226 60
paul@226 61
# Rules.
paul@226 62
paul@226 63
.PHONY: all clean distclean
paul@226 64
paul@226 65
all:    $(TARGETS)
paul@226 66
paul@226 67
clean:
paul@293 68
	-rm -f $(ALL_OBJ) $(TARGETS)
paul@293 69
	-rmdir $(OBJECTS)
paul@226 70
paul@226 71
distclean: clean
paul@226 72
	echo "Nothing else to clean."
paul@226 73
paul@226 74
$(E2ACCESS): $(E2ACCESS_OBJ) $(LIBE2ACCESS_SHARED)
paul@226 75
	$(CC) $(LDFLAGS) $(E2ACCESS_OBJ) -o $@
paul@226 76
paul@226 77
$(LIBE2ACCESS): $(LIBE2ACCESS_OBJ)
paul@226 78
	$(AR) rc $@ $(LIBE2ACCESS_OBJ)
paul@226 79
	$(RANLIB) $@
paul@226 80
paul@226 81
$(LIBE2ACCESS_SHARED): $(LIBE2ACCESS) $(LIBE2ACCESS_OBJ)
paul@226 82
	$(LD) -shared $(LIBE2ACCESS_OBJ) -o $(LIBE2ACCESS_SHARED)
paul@226 83
paul@226 84
$(TEST_LISTING): $(TEST_LISTING_OBJ) $(LIBE2ACCESS_SHARED)
paul@226 85
	$(CC) $(LDFLAGS) $(TEST_LISTING_OBJ) -o $@
paul@226 86
paul@226 87
$(TEST_REMOVE): $(TEST_REMOVE_OBJ) $(LIBE2ACCESS_SHARED)
paul@226 88
	$(CC) $(LDFLAGS) $(TEST_REMOVE_OBJ) -o $@
paul@226 89
paul@293 90
$(LIBE2ACCESS_SRC_MOVED): | $(OBJECTS)
paul@293 91
	cp -f $(SRC)/$(notdir $@) $@
paul@293 92
paul@293 93
$(OBJECTS):
paul@293 94
	mkdir -p $(OBJECTS)
paul@293 95
paul@226 96
.c.o:
paul@226 97
	$(CC) -c $(CFLAGS) $< -o $@