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