begin working on process enumeration, add dummy target and adjust makefile for multiple targets
This commit is contained in:
parent
cd739c74e2
commit
d512bb4dd2
5 changed files with 71 additions and 16 deletions
38
Makefile
38
Makefile
|
|
@ -1,17 +1,22 @@
|
|||
INC_DIR = include
|
||||
SRC_DIR = src
|
||||
OBJ_DIR = obj
|
||||
BIN_DIR = bin
|
||||
INC_DIR = include
|
||||
SRC_DIR = src
|
||||
OBJ_DIR = obj
|
||||
BIN_DIR = bin
|
||||
|
||||
CC = g++
|
||||
LD = ld
|
||||
CXXFLAGS = -Wall -I$(INC_DIR)
|
||||
LDFLAGS =
|
||||
CC = g++
|
||||
LD = ld
|
||||
CXXFLAGS = -Wall -I$(INC_DIR)
|
||||
LDFLAGS =
|
||||
|
||||
BLACKJACK_SRC = main.cpp
|
||||
BLACKJACK_OBJ := $(addprefix $(OBJ_DIR)/,$(patsubst %.cpp,%.o,$(BLACKJACK_SRC)))
|
||||
BLACKJACK_SRC := $(addprefix $(SRC_DIR)/,$(BLACKJACK_SRC))
|
||||
BLACKJACK_DEPS =
|
||||
BLACKJACK_SRC = main.cpp process.cpp
|
||||
BLACKJACK_OBJ := $(addprefix $(OBJ_DIR)/,$(patsubst %.cpp,%.o,$(BLACKJACK_SRC)))
|
||||
BLACKJACK_SRC := $(addprefix $(SRC_DIR)/,$(BLACKJACK_SRC))
|
||||
BLACKJACK_DEPS = process.h
|
||||
BLACKJACK_DEPS := $(addprefix $(INC_DIR)/,$(BLACKJACK_DEPS))
|
||||
|
||||
DUMMY_TARGET_SRC = dummy_target.cpp
|
||||
DUMMY_TARGET_OBJ := $(addprefix $(OBJ_DIR)/,$(patsubst %.cpp,%.o,$(DUMMY_TARGET_SRC)))
|
||||
DUMMY_TARGET_SRC := $(addprefix $(SRC_DIR)/,$(DUMMY_TARGET_SRC))
|
||||
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
||||
$(CC) $(CXXFLAGS) -c -o $@ $<
|
||||
|
|
@ -19,13 +24,18 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
|||
blackjack: $(BLACKJACK_OBJ) $(BLACKJACK_DEPS)
|
||||
$(CC) $(LDFLAGS) -o $(BIN_DIR)/$@ $(BLACKJACK_OBJ)
|
||||
|
||||
dummy_target: $(DUMMY_TARGET_OBJ)
|
||||
$(CC) $(LDFLAGS) -o $(BIN_DIR)/$@ $(DUMMY_TARGET_OBJ)
|
||||
|
||||
.PHONY: all clean debug
|
||||
|
||||
all: blackjack
|
||||
TARGETS = blackjack dummy_target
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
debug: CXXFLAGS += -DDEBUG -g
|
||||
debug: LDFLAGS += -g
|
||||
debug: all
|
||||
debug: $(TARGETS)
|
||||
|
||||
clean:
|
||||
rm $(OBJ_DIR)/*.o
|
||||
|
|
|
|||
15
include/process.h
Normal file
15
include/process.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <sys/types.h>
|
||||
|
||||
class Process
|
||||
{
|
||||
public:
|
||||
Process(pid_t pid) : pid(pid) {}
|
||||
|
||||
static std::optional<Process> FindByName(std::string name);
|
||||
private:
|
||||
pid_t pid;
|
||||
};
|
||||
16
src/dummy_target.cpp
Normal file
16
src/dummy_target.cpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern char *program_invocation_name;
|
||||
extern char *program_invocation_short_name;
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("pid: %d\n", getpid());
|
||||
printf("program_invocation_name: %s\n", program_invocation_name);
|
||||
printf("program_invocation_short_name: %s\n", program_invocation_short_name);
|
||||
|
||||
puts("waiting for any key...");
|
||||
getc(stdin);
|
||||
return 0;
|
||||
}
|
||||
12
src/main.cpp
12
src/main.cpp
|
|
@ -1,7 +1,15 @@
|
|||
#include <iostream>
|
||||
#include "process.h"
|
||||
|
||||
int main()
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
std::cout << "Hello World" << std::endl;
|
||||
auto proc = Process::FindByName("dummy_target");
|
||||
if (proc) proc = proc.value();
|
||||
else
|
||||
{
|
||||
fputs("process not found\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
6
src/process.cpp
Normal file
6
src/process.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include "process.h"
|
||||
|
||||
std::optional<Process> Process::FindByName(std::string name)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue