refactor: clean up Makefiles
							parent
							
								
									fb4a9a3b2e
								
							
						
					
					
						commit
						0229db027d
					
				| 
						 | 
				
			
			@ -1,6 +1,4 @@
 | 
			
		|||
*
 | 
			
		||||
 | 
			
		||||
!src/
 | 
			
		||||
!Makefile
 | 
			
		||||
!thirdparty/
 | 
			
		||||
!include/
 | 
			
		||||
data/
 | 
			
		||||
build/
 | 
			
		||||
trie/build/
 | 
			
		||||
.git/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,8 +18,9 @@ RUN curl -Lo - "https://github.com/Yelp/dumb-init/archive/refs/tags/v${DI_VER}.t
 | 
			
		|||
 | 
			
		||||
COPY . ./
 | 
			
		||||
 | 
			
		||||
RUN make CFLAGS='-O3 -static' LDFLAGS='-flto' && \
 | 
			
		||||
RUN make CFLAGS='-O3' LDFLAGS='-static -flto' && \
 | 
			
		||||
    strip build/lander && \
 | 
			
		||||
    readelf -d build/lander && \
 | 
			
		||||
    [ "$(readelf -d build/lander | grep NEEDED | wc -l)" = 0 ]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										34
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										34
									
								
								Makefile
								
								
								
								
							| 
						 | 
				
			
			@ -1,18 +1,10 @@
 | 
			
		|||
# https://spin.atomicobject.com/2016/08/26/makefile-c-projects/ was a great
 | 
			
		||||
# base for this Makefile
 | 
			
		||||
 | 
			
		||||
VERSION := 0.1.0
 | 
			
		||||
-include config.mk
 | 
			
		||||
 | 
			
		||||
BIN_FILENAME ?= lander
 | 
			
		||||
 | 
			
		||||
BUILD_DIR ?= build
 | 
			
		||||
SRC_DIR ?= src
 | 
			
		||||
TEST_DIR ?= test
 | 
			
		||||
THIRDPARTY_DIR ?= thirdparty
 | 
			
		||||
 | 
			
		||||
INC_DIRS ?= include $(THIRDPARTY_DIR)/include trie/include
 | 
			
		||||
LIBS ?= trie m
 | 
			
		||||
LIB_DIRS ?= ./trie/build
 | 
			
		||||
export CFLAGS
 | 
			
		||||
export LDFLAGS
 | 
			
		||||
 | 
			
		||||
BIN := $(BUILD_DIR)/$(BIN_FILENAME)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -31,23 +23,11 @@ BINS_TEST := $(OBJS_TEST:%.c.o=%)
 | 
			
		|||
TARGETS_TEST := $(BINS_TEST:%=test-%)
 | 
			
		||||
TARGETS_MEM_TEST := $(BINS_TEST:%=test-mem-%)
 | 
			
		||||
 | 
			
		||||
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
 | 
			
		||||
 | 
			
		||||
# -MMD: generate a .d file for every source file. This file can be imported by
 | 
			
		||||
#  make and makes make aware that a header file has been changed, ensuring an
 | 
			
		||||
#  object file is also recompiled if only a header is changed.
 | 
			
		||||
# -MP: generate a dummy target for every header file (according to the  docs it
 | 
			
		||||
#  prevents some errors when removing header files)
 | 
			
		||||
CFLAGS ?= -MMD -MP -g
 | 
			
		||||
_CFLAGS := $(INC_FLAGS) $(CFLAGS) -Wall -Wextra -DLANDER_VERSION=\"$(VERSION)\"
 | 
			
		||||
 | 
			
		||||
_CFLAGS := $(addprefix -I,$(INC_DIRS)) $(CFLAGS) -Wall -Wextra -DLANDER_VERSION=\"$(VERSION)\"
 | 
			
		||||
_LDFLAGS := $(addprefix -L,$(LIB_DIRS)) $(addprefix -l,$(LIBS)) $(LDFLAGS)
 | 
			
		||||
 | 
			
		||||
export CFLAGS
 | 
			
		||||
export LDFLAGS
 | 
			
		||||
 | 
			
		||||
.PHONY: all
 | 
			
		||||
all: bin
 | 
			
		||||
all: $(BIN)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# =====COMPILATION=====
 | 
			
		||||
| 
						 | 
				
			
			@ -60,8 +40,7 @@ libtrie:
 | 
			
		|||
	$(MAKE) -C trie
 | 
			
		||||
 | 
			
		||||
.PHONY: bin
 | 
			
		||||
bin: $(BIN)
 | 
			
		||||
$(BIN): $(OBJS) libtrie
 | 
			
		||||
$(BIN): libtrie $(OBJS)
 | 
			
		||||
	$(CC) -o $@ $(OBJS) $(_LDFLAGS)
 | 
			
		||||
 | 
			
		||||
$(BUILD_DIR)/$(SRC_DIR)/%.c.o: $(SRC_DIR)/%.c
 | 
			
		||||
| 
						 | 
				
			
			@ -111,6 +90,7 @@ $(BUILD_DIR)/$(TEST_DIR)/%.c.o: $(TEST_DIR)/%.c
 | 
			
		|||
		-I$(dir $(@:$(BUILD_DIR)/$(TEST_DIR)/%=$(SRC_DIR)/%)) \
 | 
			
		||||
		-c $< -o $@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# =====MAINTENANCE=====
 | 
			
		||||
.PHONY: lint
 | 
			
		||||
lint:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,23 @@
 | 
			
		|||
VERSION := 0.1.0
 | 
			
		||||
 | 
			
		||||
BIN_FILENAME = lander
 | 
			
		||||
 | 
			
		||||
BUILD_DIR      = build
 | 
			
		||||
SRC_DIR        = src
 | 
			
		||||
TEST_DIR       = test
 | 
			
		||||
THIRDPARTY_DIR = thirdparty
 | 
			
		||||
 | 
			
		||||
INC_DIRS  = include $(THIRDPARTY_DIR)/include trie/include
 | 
			
		||||
LIBS      = trie m
 | 
			
		||||
LIB_DIRS  = ./trie/build
 | 
			
		||||
 | 
			
		||||
# -MMD: generate a .d file for every source file. This file can be imported by
 | 
			
		||||
#  make and makes make aware that a header file has been changed, ensuring an
 | 
			
		||||
#  object file is also recompiled if only a header is changed.
 | 
			
		||||
# -MP: generate a dummy target for every header file (according to the  docs it
 | 
			
		||||
#  prevents some errors when removing header files)
 | 
			
		||||
CFLAGS = -MMD -MP -g
 | 
			
		||||
 | 
			
		||||
# When compiling release builds, these flags are better
 | 
			
		||||
# CLAGS = -O3
 | 
			
		||||
# LDFLAGS = -flto
 | 
			
		||||
| 
						 | 
				
			
			@ -1,12 +1,7 @@
 | 
			
		|||
# https://spin.atomicobject.com/2016/08/26/makefile-c-projects/ was a great
 | 
			
		||||
# base for this Makefile
 | 
			
		||||
 | 
			
		||||
LIB_FILENAME ?= libtrie.a
 | 
			
		||||
 | 
			
		||||
BUILD_DIR ?= build
 | 
			
		||||
SRC_DIR ?= src
 | 
			
		||||
TEST_DIR ?= test
 | 
			
		||||
INC_DIRS ?= include
 | 
			
		||||
-include config.mk
 | 
			
		||||
 | 
			
		||||
LIB := $(BUILD_DIR)/$(LIB_FILENAME)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -23,15 +18,7 @@ BINS_TEST := $(OBJS_TEST:%.c.o=%)
 | 
			
		|||
TARGETS_TEST := $(BINS_TEST:%=test-%)
 | 
			
		||||
TARGETS_MEM_TEST := $(BINS_TEST:%=test-mem-%)
 | 
			
		||||
 | 
			
		||||
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
 | 
			
		||||
 | 
			
		||||
# -MMD: generate a .d file for every source file. This file can be imported by
 | 
			
		||||
#  make and makes make aware that a header file has been changed, ensuring an
 | 
			
		||||
#  object file is also recompiled if only a header is changed.
 | 
			
		||||
# -MP: generate a dummy target for every header file (according to the  docs it
 | 
			
		||||
#  prevents some errors when removing header files)
 | 
			
		||||
CFLAGS ?= -MMD -MP -g
 | 
			
		||||
_CFLAGS := $(INC_FLAGS) $(CFLAGS) -Wall -Wextra
 | 
			
		||||
_CFLAGS := $(addprefix -I,$(INC_DIRS)) $(CFLAGS) -Wall -Wextra
 | 
			
		||||
 | 
			
		||||
.PHONY: all
 | 
			
		||||
all: lib
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,13 @@
 | 
			
		|||
LIB_FILENAME = libtrie.a
 | 
			
		||||
 | 
			
		||||
BUILD_DIR = build
 | 
			
		||||
SRC_DIR = src
 | 
			
		||||
TEST_DIR = test
 | 
			
		||||
INC_DIRS = include
 | 
			
		||||
 | 
			
		||||
# -MMD: generate a .d file for every source file. This file can be imported by
 | 
			
		||||
#  make and makes make aware that a header file has been changed, ensuring an
 | 
			
		||||
#  object file is also recompiled if only a header is changed.
 | 
			
		||||
# -MP: generate a dummy target for every header file (according to the  docs it
 | 
			
		||||
#  prevents some errors when removing header files)
 | 
			
		||||
CFLAGS = -MMD -MP -g
 | 
			
		||||
		Loading…
	
		Reference in New Issue