Makefile基础模板

对文件结构如下的目录写makefile:

hostpc:/mnt/e/homework/WSL/medtls$ tree
.
├── iot_kal.h
├── iot_net_define.h
├── iot_type.h
├── demo_platform.c
├── demo_platform.h
├── include
│   ├── CMakeLists.txt
│   └── mbedtls
│       ├── aes.h
│       ├── aesni.h
│       ├── arc4.h
│       ├── asn1.h
│       ├── asn1write.h
│       ├── base64.h
│       ├── bignum.h
│       ├── blowfish.h
│       ├── bn_mul.h
│       ├── camellia.h
│       ├── ccm.h
│       ├── certs.h
│       ├── check_config.h
│       ├── cipher.h
│       ├── cipher_internal.h
│       ├── cmac.h
│       ├── compat-1.3.h
│       ├── config.h
│       ├── config.h.org
│       ├── ctr_drbg.h
│       ├── debug.h
│       ├── des.h
│       ├── dhm.h
│       ├── ecdh.h
│       ├── ecdsa.h
│       ├── ecjpake.h
│       ├── ecp.h
│       ├── ecp_internal.h
│       ├── entropy.h
│       ├── entropy_poll.h
│       ├── error.h
│       ├── gcm.h
│       ├── havege.h
│       ├── hmac_drbg.h
│       ├── md.h
│       ├── md2.h
│       ├── md4.h
│       ├── md5.h
│       ├── md_internal.h
│       ├── memory_buffer_alloc.h
│       ├── net.h
│       ├── net_sockets.h
│       ├── oid.h
│       ├── padlock.h
│       ├── pem.h
│       ├── pk.h
│       ├── pk_internal.h
│       ├── pkcs11.h
│       ├── pkcs12.h
│       ├── pkcs5.h
│       ├── platform.h
│       ├── platform_time.h
│       ├── ripemd160.h
│       ├── rsa.h
│       ├── sha1.h
│       ├── sha256.h
│       ├── sha512.h
│       ├── ssl.h
│       ├── ssl_cache.h
│       ├── ssl_ciphersuites.h
│       ├── ssl_cookie.h
│       ├── ssl_internal.h
│       ├── ssl_ticket.h
│       ├── threading.h
│       ├── timing.h
│       ├── version.h
│       ├── x509.h
│       ├── x509_crl.h
│       ├── x509_crt.h
│       ├── x509_csr.h
│       └── xtea.h
├── iot_err.h
├── iot_kal.c
├── library
│   ├── CMakeLists.txt
│   ├── Makefile
│   ├── aes.c
│   ├── aesni.c
│   ├── arc4.c
│   ├── asn1parse.c
│   ├── asn1write.c
│   ├── base64.c
│   ├── bignum.c
│   ├── blowfish.c
│   ├── camellia.c
│   ├── ccm.c
│   ├── certs.c
│   ├── cipher.c
│   ├── cipher_wrap.c
│   ├── cmac.c
│   ├── ctr_drbg.c
│   ├── debug.c
│   ├── des.c
│   ├── dhm.c
│   ├── ecdh.c
│   ├── ecdsa.c
│   ├── ecjpake.c
│   ├── ecp.c
│   ├── ecp_curves.c
│   ├── entropy.c
│   ├── entropy_poll.c
│   ├── error.c
│   ├── gcm.c
│   ├── havege.c
│   ├── hmac_drbg.c
│   ├── md.c
│   ├── md2.c
│   ├── md4.c
│   ├── md5.c
│   ├── md_wrap.c
│   ├── memory_buffer_alloc.c
│   ├── net_sockets.c
│   ├── oid.c
│   ├── padlock.c
│   ├── pem.c
│   ├── pk.c
│   ├── pk_wrap.c
│   ├── pkcs11.c
│   ├── pkcs12.c
│   ├── pkcs5.c
│   ├── pkparse.c
│   ├── pkwrite.c
│   ├── platform.c
│   ├── ripemd160.c
│   ├── rsa.c
│   ├── sha1.c
│   ├── sha256.c
│   ├── sha512.c
│   ├── ssl_cache.c
│   ├── ssl_ciphersuites.c
│   ├── ssl_cli.c
│   ├── ssl_cookie.c
│   ├── ssl_srv.c
│   ├── ssl_ticket.c
│   ├── ssl_tls.c
│   ├── threading.c
│   ├── timing.c
│   ├── version.c
│   ├── version_features.c
│   ├── x509.c
│   ├── x509_create.c
│   ├── x509_crl.c
│   ├── x509_crt.c
│   ├── x509_csr.c
│   ├── x509write_crt.c
│   ├── x509write_csr.c
│   └── xtea.c
├── log.txt
├── main_tls.c
├── mbedtls_test_demo.c
└── mbedtls_test_demo.h

3 directories, 157 files

Makefile文件如下:


TARGET=mbedtls

CFLAGS = -Wall -g

SRCDIR= ./*.c \
	./library/*.c \
	
INCLUDE = -I./ \
	-I./include \
	-I./include/mbedtls \

SRC = $(wildcard $(SRCDIR))

OBJS = $(patsubst %.c, %.o, $(SRC))

$(TARGET):$(OBJS)
	echo "target >>>>"
	gcc -m32 $^ -o $@
	@echo "==> compiler successful!!!! " 
	@echo "Image:" $(TARGET)

%.o: %.c
	echo "compiler >>>>"
	gcc -m32 $(CFLAGS) $(INCLUDE) -c $< -o $@
 
.PHONY:clean
clean:
	rm -f $(OBJS) $(TARGET)
	

 
# Compiler and flags
CC = gcc
TARGET = kws
CFLAGS = -Wall -g -O2 -m32 -ffunction-sections -fdata-sections
LDFLAGS = -m32 -Wl,--gc-sections

# Source files
SRC_DIRS = . \
       audio_test \
       audio_test/asr_alg_common/base_op \
       audio_test/model \
       audio_test/speexdsp/libspeexdsp

SRC_FILES = $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
OBJS = $(patsubst %.c,%.o,$(SRC_FILES))

# Header files
INC_DIRS = . \
       audio_test \
       audio_test/asr_alg_common \
       audio_test/asr_alg_common/base_op \
       audio_test/model \
       audio_test/speexdsp \
       audio_test/speexdsp/include \
       audio_test/speexdsp/include/speex \
       audio_test/speexdsp/libspeexdsp

INCLUDES = $(foreach dir,$(INC_DIRS),-I$(dir))

# Header dependencies
DEPS = $(wildcard $(foreach dir,$(INC_DIRS),$(dir)/*.h))

# Build rules
$(TARGET): $(OBJS)
	@echo ">>>>>Linking target..."
	$(CC) $(LDFLAGS) -o $@ $^
	@echo "Build successful! Target: $(TARGET)"

%.o: %.c $(DEPS)
	@echo "Compiling $<..."
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

.PHONY: clean
clean:
	rm -f $(OBJS) $(TARGET)
 
$(TARGET):$(OBJS)
	echo "target >>>>"
	gcc -m32 $^ -o $@
	@echo "==> compiler successful!!!! " 
	@echo "Image:" $(TARGET)
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值