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 # Somehow, things like AR, CC and LD are removed when this Makefile is invoked 26 # by the L4Re build system. 27 28 AR = ar 29 CC = cc 30 LD = ld 31 RANLIB = ranlib 32 33 # Compilation and linking flags. 34 35 CFLAGS = -I$(INC) -fPIC # -g 36 LDFLAGS = -lext2fs -L. -le2access # -lcom_err 37 38 # Output programs and libraries. 39 40 E2ACCESS = e2access 41 LIBE2ACCESS = libe2access.a 42 LIBE2ACCESS_SHARED = libe2access.so 43 44 TEST_LISTING = test_listing 45 TEST_REMOVE = test_remove 46 47 TARGETS = $(E2ACCESS) $(LIBE2ACCESS) $(LIBE2ACCESS_SHARED) $(TEST_LISTING) $(TEST_REMOVE) 48 49 # Sources and objects. 50 51 E2ACCESS_SRC = e2access.c file.c input.c session.c ops.c $(wildcard op_*.c) 52 E2ACCESS_OBJ = $(E2ACCESS_SRC:.c=.o) 53 54 TEST_LISTING_SRC = test_listing.c 55 TEST_LISTING_OBJ = $(TEST_LISTING_SRC:.c=.o) 56 57 TEST_REMOVE_SRC = test_remove.c 58 TEST_REMOVE_OBJ = $(TEST_REMOVE_SRC:.c=.o) 59 60 LIBE2ACCESS_SRC = format.c image.c path.c utils.c 61 LIBE2ACCESS_SRC_MOVED = $(foreach FILE,$(LIBE2ACCESS_SRC),$(OBJECTS)/$(FILE)) 62 LIBE2ACCESS_OBJ = $(LIBE2ACCESS_SRC_MOVED:.c=.o) 63 64 ALL_OBJ = $(E2ACCESS_OBJ) $(LIBE2ACCESS_SRC_MOVED) $(LIBE2ACCESS_OBJ) $(TEST_LISTING_OBJ) $(TEST_REMOVE_OBJ) 65 66 # Rules. 67 68 .PHONY: all clean distclean 69 70 .SUFFIXES: .c .o 71 72 all: $(TARGETS) 73 74 clean: 75 -rm -f $(ALL_OBJ) $(TARGETS) 76 -rmdir $(OBJECTS) 77 78 distclean: clean 79 echo "Nothing else to clean." 80 81 $(E2ACCESS): $(E2ACCESS_OBJ) $(LIBE2ACCESS_SHARED) 82 $(CC) $(LDFLAGS) $(E2ACCESS_OBJ) -o $@ 83 84 $(LIBE2ACCESS): $(LIBE2ACCESS_OBJ) 85 $(AR) rc $@ $(LIBE2ACCESS_OBJ) 86 $(RANLIB) $@ 87 88 $(LIBE2ACCESS_SHARED): $(LIBE2ACCESS) $(LIBE2ACCESS_OBJ) 89 $(LD) -shared $(LIBE2ACCESS_OBJ) -o $(LIBE2ACCESS_SHARED) 90 91 $(TEST_LISTING): $(TEST_LISTING_OBJ) $(LIBE2ACCESS_SHARED) 92 $(CC) $(LDFLAGS) $(TEST_LISTING_OBJ) -o $@ 93 94 $(TEST_REMOVE): $(TEST_REMOVE_OBJ) $(LIBE2ACCESS_SHARED) 95 $(CC) $(LDFLAGS) $(TEST_REMOVE_OBJ) -o $@ 96 97 $(LIBE2ACCESS_SRC_MOVED): | $(OBJECTS) 98 cp -f $(SRC)/$(notdir $@) $@ 99 100 $(OBJECTS): 101 mkdir -p $(OBJECTS) 102 103 .c.o: 104 $(CC) -c $(CFLAGS) $< -o $@