Clean up makefile.
diff --git a/Makefile b/Makefile
index 076aa76..e635432 100644
--- a/Makefile
+++ b/Makefile
@@ -1,30 +1,62 @@
-CXX ?= $(CROSS_COMPILE)gcc
+LIBS += libwritefrudata.so
+libwritefrudata.so_OBJS += frup.o writefrudata.o
+libwritefrudata.so_NEEDED += libsystemd
 
-FRU_WRITE_AND_PARSER_LIB = libwritefrudata.so
-FRU_WRITE_AND_PARSER_OBJS = frup.o writefrudata.o
+#### -----------------------------------------------------------------------####
+#                                                                              #
+##                       Compilare Regulas Sequi                              ##
+#                                                                              #
+#### -----------------------------------------------------------------------####
+OPTFLAGS ?= -O3 -g -pipe
+CFLAGS ?= $(OPTFLAGS)
+CXXFLAGS ?= $(OPTFLAGS)
+CFLAGS += -Wall -flto -fPIC
+CXXFLAGS += --std=gnu++14 -Wall -flto -fPIC -I.
 
-INC_FLAGS += $(shell pkg-config --cflags --libs libsystemd) -I. -O2 --std=gnu++14
-LIB_FLAGS += $(shell pkg-config  --libs libsystemd) -rdynamic
+__PKG_CONFIG = $(if $1,$(shell pkg-config $2 $1))
+
+define __BUILD_EXE
+$1 : $$($1_OBJS) $$(LIBS)
+		$$(LINK.cpp) -o $$@ $$^ $(call __PKG_CONFIG,$($1_NEEDED),--libs)
+
+$(eval CXXFLAGS += $(call __PKG_CONFIG,$($1_NEEDED),--cflags))
+
+#include $$($1_OBJS:.o=.d)
+endef
+
+$(foreach exe,$(EXES),$(eval $(call __BUILD_EXE,$(exe))))
+
+define __BUILD_LIB
+$1 : $$($1_OBJS)
+		$$(LINK.cpp) -shared -o $$@ $$^ $(call __PKG_CONFIG,$($1_NEEDED),--libs)
+
+$(eval CXXFLAGS += $(call __PKG_CONFIG,$($1_NEEDED),--cflags))
+
+#include $$($1_OBJS:.o=.d)
+endef
+
+$(foreach lib,$(LIBS),$(eval $(call __BUILD_LIB,$(lib))))
+
+.PHONY: clean
+clean:
+		$(RM) $(foreach exe,$(EXES),$(exe) $($(exe)_OBJS)) \
+			  $(foreach lib,$(LIBS),$(lib) $($(lib)_OBJS))
 
 DESTDIR ?= /
-SBINDIR ?= /usr/sbin
-INCLUDEDIR ?= /usr/include
+BINDIR ?= /usr/bin
 LIBDIR ?= /usr/lib
 
-all: $(FRU_WRITE_AND_PARSER_LIB)
-
-%.o: %.c
-	$(CXX) -fpic -c $< $(CXXFLAGS) $(INC_FLAGS) $(IPMID_PATH) -o $@
-
-%.o: %.C
-	$(CXX) -fpic -c $< $(CXXFLAGS) $(INC_FLAGS) $(IPMID_PATH) -o $@
-
-$(FRU_WRITE_AND_PARSER_LIB): $(FRU_WRITE_AND_PARSER_OBJS)
-	$(CXX) $^ -shared $(LDFLAGS) $(LIB_FLAGS) -o $@
-
-clean:
-	rm -f $(FRU_WRITE_AND_PARSER_OBJS) $(FRU_WRITE_AND_PARSER_LIB)
-
+.PHONY: install
 install:
-		install -m 0755 -d $(DESTDIR)$(LIBDIR)/host-ipmid
-		install -m 0755 $(FRU_WRITE_AND_PARSER_LIB) $(DESTDIR)$(LIBDIR)/host-ipmid
+		$(if $(EXES),\
+		install -m 0755 -d $(DESTDIR)$(BINDIR) && \
+		install -m 0755 $(EXES) $(DESTDIR)$(BINDIR) \
+		)
+		$(if $(LIBS),\
+		install -m 0755 -d $(DESTDIR)$(LIBDIR)/host-ipmid && \
+		install -m 0755 $(LIBS) $(DESTDIR)$(LIBDIR)/host-ipmid \
+		)
+
+.DEFAULT_GOAL: all
+.PHONY: all
+all: $(EXES) $(LIBS)