Skip to content

Commit

Permalink
Cleanup and simplify Makefile
Browse files Browse the repository at this point in the history
This gets rid of some unnecessary targets/code, and also makes it a bit
easier to support adding compiler/linker flags.

Signed-off-by: Saikrishna Arcot <[email protected]>
  • Loading branch information
saiarcot895 committed Jun 28, 2022
1 parent 04a23c7 commit 772625f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 36 deletions.
23 changes: 9 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@ CP := cp
MKDIR := mkdir
CC := g++
MV := mv
LIBS := -levent -lhiredis -lswsscommon -pthread -lboost_thread -lboost_system
CFLAGS += -Wall -std=c++17 -fPIE -I$(PWD)/../sonic-swss-common/common
override LDLIBS += -levent -lhiredis -lswsscommon -pthread -lboost_thread -lboost_system
override CPPFLAGS += -Wall -std=c++17 -fPIE -I/usr/include/swss
override CPPFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)"
PWD := $(shell pwd)

all: $(DHCP6RELAY_TARGET)

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS) $(OBJS)
endif
-include $(OBJS:%.o=%.d)
endif

-include src/subdir.mk

all: sonic-dhcp6relay

sonic-dhcp6relay: $(OBJS)
@echo 'Building target: $@'
@echo 'Invoking: G++ Linker'
$(CC) $(LDFLAGS) -o $(DHCP6RELAY_TARGET) $(OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
$(DHCP6RELAY_TARGET): $(OBJS)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@

install:
$(MKDIR) -p $(DESTDIR)/usr/sbin
Expand All @@ -34,7 +29,7 @@ deinstall:
$(RM) -rf $(DESTDIR)/usr/sbin

clean:
-$(RM) $(EXECUTABLES) $(C_DEPS) $(OBJS) $(DHCP6RELAY_TARGET)
-$(RM) $(EXECUTABLES) $(OBJS:%.o=%.d) $(OBJS) $(DHCP6RELAY_TARGET)
-@echo ' '

.PHONY: all clean dependents
Expand Down
25 changes: 3 additions & 22 deletions src/subdir.mk
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
CC := g++

C_SRCS += \
../src/relay.c \
../src/configInterface.c \
../src/main.c

OBJS += \
./src/relay.o \
./src/configInterface.o \
./src/main.o

C_DEPS += \
./src/relay.d \
./src/configInterface.d \
./src/main.d

src/%.o: src/%.cpp
@echo 'Building file: $<'
@echo 'Invoking: GCC C++ Compiler'
$(CC) -D__FILENAME__="$(subst src/,,$<)" $(CFLAGS) -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
$(PWD)/src/relay.o \
$(PWD)/src/configInterface.o \
$(PWD)/src/main.o

0 comments on commit 772625f

Please sign in to comment.