Skip to content

Commit

Permalink
rewrite Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
inPhraZ committed Jul 1, 2022
1 parent 608fbff commit 88f32f8
Showing 1 changed file with 60 additions and 48 deletions.
108 changes: 60 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,50 +1,62 @@
OBJS = jpkt-main.o \
jpkt-packet.o \
jpkt-queue.o \
jpkt-eth.o \
jpkt-arp.o \
jpkt-ip.o \
jpkt-udp.o \
jpkt-tcp.o \
jpkt-icmp.o \
jpkt-data.o

LIBS = $(shell pkg-config --libs libpcap glib-2.0 json-glib-1.0)

INC = $(shell pkg-config --cflags glib-2.0 json-glib-1.0)

jpkt: $(OBJS)
gcc -o jpkt $(OBJS) $(LIBS)

jpkt-main.o: jpkt-main.c
gcc -c jpkt-main.c

jpkt-packet.o: jpkt-packet.c jpkt-packet.h
gcc -c jpkt-packet.c $(INC)

jpkt-queue.o: jpkt-queue.c jpkt-queue.h
gcc -c jpkt-queue.c $(INC)

jpkt-eth.o: jpkt-eth.c jpkt-eth.h
gcc -c jpkt-eth.c $(INC)

jpkt-arp.o: jpkt-arp.c jpkt-arp.h
gcc -c jpkt-arp.c $(INC)

jpkt-ip.o: jpkt-ip.c jpkt-ip.h
gcc -c jpkt-ip.c $(INC)

jpkt-icmp.o: jpkt-icmp.c jpkt-icmp.h
gcc -c jpkt-icmp.c $(INC)

jpkt-udp.o: jpkt-udp.c jpkt-udp.h
gcc -c jpkt-udp.c $(INC)

jpkt-tcp.o: jpkt-tcp.c jpkt-tcp.h
gcc -c jpkt-tcp.c $(INC)

jpkt-data.o: jpkt-data.c jpkt-data.h
gcc -c jpkt-data.c $(INC)
prefix := /usr/local
libdir := ${prefix}/lib
includedir := ${prefix}/include

rootdir := .
SRC := ${rootdir}/src
INC := ${rootdir}/include
BIN := ${rootdir}/bin
LIB := ${rootdir}/lib
EXM := ${rootdir}/example

MAJOR := 1
MINOR := 0
PROG := libjpkt
LIBJPKT := $(PROG).$(MAJOR).$(MINOR).a

CC := gcc
AR := ar

CFLAGS := -O2 -Wall -Werror -fPIC
ARFLAGS := -rcs

DEPS = \
$(shell pkg-config --libs libpcap glib-2.0 json-glib-1.0) \
$(shell pkg-config --cflags glib-2.0 json-glib-1.0)

OBJS := \
jpkt.o \
jpkt-packet.o \
jpkt-queue.o \
jpkt-eth.o \
jpkt-arp.o \
jpkt-ip.o \
jpkt-udp.o \
jpkt-tcp.o \
jpkt-icmp.o \
jpkt-data.o

.PHONY: lib

lib:
mkdir -p $(LIB) $(BIN)
$(CC) $(CFLAGS) -c $(SRC)/*.c -I $(INC) $(DEPS)
$(AR) $(ARFLAGS) $(LIB)/$(LIBJPKT) $(OBJS)
mv $(OBJS) $(BIN)

example: lib
$(CC) $(CFLAGS) -g $(EXM)/$@.c $(LIB)/$(LIBJPKT) -o $(EXM)/$@ -I $(INC) $(DEPS)

install: lib
@echo
@echo install

uninstall:
@echo Uninstall

clean:
rm -rf ./*.o
rm -rf $(BIN)

cleanall: clean
rm -rf $(LIB)
rm -rf $(EXM)/example

0 comments on commit 88f32f8

Please sign in to comment.