日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux make教程,Linux下makefile的一个简单框架

發布時間:2025/3/15 linux 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux make教程,Linux下makefile的一个简单框架 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目錄結構

tree

.

|-- Makefile

`-- src

|-- Makefile

|-- bar

| |-- Makefile

| `-- bar.c

`-- foo

|-- Makefile

`-- foo.c

3 directories, 6 files

頂層Makefile

# Makefile for top directory

# phony target

.PHONY: all debug release clean

#

all: release

#

debug:

$(MAKE) -C src debug

#

release:

$(MAKE) -C src release

#

clean:

$(MAKE) -C src clean

#EOF

src目錄的Makefile

# Makefile for src directory

##############################

DIRS= foo \

bar

##############################

# phony target

.PHONY: all debug release clean

#

all:

set -e; for d in $(DIRS); do $(MAKE) -C $$d; done

#

debug:

set -e; for d in $(DIRS); do $(MAKE) DEBUG=1 -C $$d; done

#

release:

set -e; for d in $(DIRS); do $(MAKE) RELEASE=1 -C $$d; done

#

clean:

set -e; for d in $(DIRS); do $(MAKE) -C $$d clean; done

#EOF

bar目錄的Makefile和bar.c

# Makefile for bar directory

##############################

TARGET=bar

SRCS=$(wildcard *.c)

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

INCS=

ifeq ($(DEBUG),1)

CFLAGS=-Wall -DDEBUG

else

CFLAGS=-Wall -DRELEASE

endif

LDFLAGS=

LIBS=-lm

##############################

# phony target

.PHONY: all clean

#

all:$(TARGET)

# @echo "DEBUG="$(DEBUG)

# @echo "RELEASE="$(RELEASE)

# @echo "make " $(TARGET)

$(TARGET):$(OBJS)

# @echo $(OBJS)

$(CC) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

$(OBJS):$(SRCS)

$(CC) $(CFLAGS) -c $< -o $@

#

clean:

@echo "make " $(TARGET) "clean"

rm -f $(TARGET) $(OBJS)

#EOF

#include

#include

int main(int argc, char *argv[])

{

#ifdef DEBUG

printf("debug begin\n");

#endif

const double pi = 3.1415926;

printf("sin(30*pi/180) is %f\n", sin(30*pi/180));

#ifdef DEBUG

printf("debug end\n");

#endif

return 0;

}

foo目錄的Makefile和foo.c

# Makefile for foo directory

##############################

TARGET=foo

SRCS=$(wildcard *.c)

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

INCS=

ifeq ($(DEBUG),1)

CFLAGS=-Wall -DDEBUG

else

CFLAGS=-Wall -DRELEASE

endif

LDFLAGS=

LIBS=-lm -lpthread

##############################

# phony target

.PHONY: all clean

#

all:$(TARGET)

# @echo "DEBUG="$(DEBUG)

# @echo "RELEASE="$(RELEASE)

# @echo "make " $(TARGET)

$(TARGET):$(OBJS)

# @echo $(OBJS)

$(CC) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)

$(OBJS):$(SRCS)

$(CC) $(CFLAGS) -c $< -o $@

#

clean:

@echo "make " $(TARGET) "clean"

rm -f $(TARGET) $(OBJS)

#EOF

#include

#include

#include

#include

void *fun(void *arg)

{

pthread_detach(pthread_self());

#ifdef DEBUG

printf("pthread debug begin\n");

#endif

const double pi = 3.1415926;

printf("sin(30*pi/180) is %f\n", sin(30*pi/180));

#ifdef DEBUG

printf("pthread debug end\n");

#endif

return NULL;

}

int main(int argc, char *argv[])

{

int ret;

pthread_t tid;

ret = pthread_create(&tid, NULL, fun, NULL);

sleep(1);

return 0;

}

bar目錄make debug的結果

debug begin

sin(30*pi/180) is 0.500000

debug end

foo目錄make debug的結果

pthread debug begin

sin(30*pi/180) is 0.500000

pthread debug end

總結

以上是生活随笔為你收集整理的linux make教程,Linux下makefile的一个简单框架的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。