sockroot

Login to a secured (chrooted) shell via a UNIX-socket
Log | Files | Refs

Makefile (1996B)


      1 # Directories
      2 SRC_DIR     := src
      3 BUILD_DIR   := build
      4 INCLUDE_DIR := include
      5 BIN_DIR     := bin
      6 EXEC_DIR    := $(SRC_DIR)/exec
      7 MAN_DIR     := src/man
      8 ROFF_DIR    := man
      9 
     10 # Compiler Options
     11 CC       ?= clang
     12 CFLAGS   += -g -std=gnu99 -Wpedantic -Wunused-result -Wno-gnu-zero-variadic-macro-arguments
     13 LDFLAGS  += -fPIE
     14 
     15 # Executable-specific flags
     16 # finit_FLAGS := -static
     17 
     18 # File lists
     19 SOURCE_FILES  := $(wildcard $(SRC_DIR)/*.c)
     20 EXEC_FILES    := $(wildcard $(EXEC_DIR)/*)
     21 OBJ_FILES     := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SOURCE_FILES))
     22 BIN_FILES     := $(patsubst $(EXEC_DIR)/%.c,$(BIN_DIR)/%,$(EXEC_FILES)) \
     23 				 $(patsubst $(EXEC_DIR)/%.sh,$(BIN_DIR)/%,$(EXEC_FILES)) \
     24 				 $(patsubst $(EXEC_DIR)/%.lnk,$(BIN_DIR)/%,$(EXEC_FILES))
     25 INCLUDE_FILES := $(wildcard $(INCLUDE_DIR)/*.h)
     26 
     27 MAN_FILES     := $(wildcard $(MAN_DIR)/*)
     28 ROFF_FILES    := $(patsubst $(MAN_DIR)/%.md,$(ROFF_DIR)/%,$(MAN_FILES)) \
     29 				 $(patsubst $(MAN_DIR)/%.roff,$(ROFF_DIR)/%,$(MAN_FILES))
     30 
     31 # Intermediate directories
     32 INTERMED_DIRS := $(BIN_DIR) $(BUILD_DIR) $(ROFF_DIR)
     33 
     34 # Magic targets
     35 .PHONY: all clean manual binary
     36 
     37 .PRECIOUS: $(OBJ_FILES)
     38 
     39 
     40 # Default target
     41 all: compile_flags.txt binary manual
     42 
     43 # Clean target
     44 clean:
     45 	rm -rf $(INTERMED_DIRS)
     46 
     47 binary: $(BIN_FILES)
     48 
     49 manual: $(ROFF_FILES)
     50 
     51 # Directory rules
     52 $(INTERMED_DIRS):
     53 	mkdir -p $@
     54 
     55 # Object rules
     56 $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(INCLUDE_FILES) | $(BUILD_DIR)
     57 	$(CC) -o $@ -c -I$(INCLUDE_DIR) $(CFLAGS) $<
     58 
     59 # Executables
     60 $(BIN_DIR)/%: $(EXEC_DIR)/%.c $(INCLUDE_FILES) $(OBJ_FILES) | $(BIN_DIR)
     61 	$(CC) -o $@ -I$(INCLUDE_DIR) $(CFLAGS) $< $(OBJ_FILES) $($(notdir $@)_FLAGS) $(LDFLAGS)
     62 
     63 $(BIN_DIR)/%: $(EXEC_DIR)/%.sh | $(BIN_DIR)
     64 	cp $< $@
     65 	chmod +x $@
     66 
     67 $(BIN_DIR)/%: $(EXEC_DIR)/%.lnk | $(BIN_DIR)
     68 	ln -sf $(shell cat $<) $@
     69 
     70 
     71 # Manual targets
     72 
     73 $(ROFF_DIR)/%: $(MAN_DIR)/%.md | $(ROFF_DIR)
     74 	md2man-roff $< > $@
     75 
     76 $(ROFF_DIR)/%: $(MAN_DIR)/%.roff | $(ROFF_DIR)
     77 	cp $< $@
     78 
     79 # Debug
     80 compile_flags.txt: 
     81 	echo $(CFLAGS) | tr " " "\n" > compile_flags.txt